Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp7551502ybl; Tue, 24 Dec 2019 04:42:53 -0800 (PST) X-Google-Smtp-Source: APXvYqy3NRkxQL0mPy5H63PqZD3Z3DZ+DJ/irf2C30SEAw9jOHDZtNzPeNSM9D68qCBVzH44jqZf X-Received: by 2002:a9d:5786:: with SMTP id q6mr20596734oth.164.1577191373435; Tue, 24 Dec 2019 04:42:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577191373; cv=none; d=google.com; s=arc-20160816; b=ftOBlYxTez4oVwvHoc3YwMy71uJtRX+UIpcab3aQnQD79yjEHtbOtoZLFjMyqbC/Dn oaFvzjF0yRpFXbR7wH/fpqv4UqEtX1iRFrIDo1L3V5ZBoWyiAyTFTcA9ZUwp0cJRfcJX SkB790kiFIPIuy/x66ITHDuKobZ+DwHLf7SyHmfcmiSXBKwQNuFvWmFL7h7gK9epg53p gOaB2uJzMVYp3gi+ZQQl7UZMVwC/1qXqPKc4SIJN1IWF/xWpDYUz09TJ0ymiFw7Eamke B9182Xcu16EM8aJTYfFVe27iZCOTBy4j2dFvoCS3ttki35f9ZlPjoAkrSJ6Lnnv9lW5k 97dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=kaVKc6m5jeGI6NoEhgNAEGz0dNuDn3Mmt1T0lAPshIQ=; b=mmP/3b9dYQLX1vVHCfdLnz1cWnv0dLT17qfwlFsTVCMQc7EmmEcXgDU1S7aV/3dl2l kmWQ9pVnh9/ZjK4x3APrhL5aN1AByZHUR3RmOSQfuGcG6eWWLVI8BUW2Ow9MVFyUZnsL y8+GivatmJm9OdCbino38pD7tWGhkI5qqGycjeivy1683tpSi860o5Jl8tsqKcm3/pfk DuRtZuGhVEvQiV3ONe1Bt0rHQ+g70fROFgQInunpyxT0PIpNm0mtinbHBtHJTNfkra+d b55KPPRp8VV1nkbbOFAA7XYdRh9K3GEqgwy6EAtb108ST7ucEoR7oc2gHey4TabkqiBl qv4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mbhzlqrF; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o6si12436675otk.201.2019.12.24.04.42.41; Tue, 24 Dec 2019 04:42:53 -0800 (PST) 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=@kernel.org header.s=default header.b=mbhzlqrF; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726246AbfLXMmD (ORCPT + 99 others); Tue, 24 Dec 2019 07:42:03 -0500 Received: from mail.kernel.org ([198.145.29.99]:42460 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726224AbfLXMmD (ORCPT ); Tue, 24 Dec 2019 07:42:03 -0500 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EFF2F20722 for ; Tue, 24 Dec 2019 12:42:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577191322; bh=xWNWJ8I9fxHntwfPGgiUpJJyIhLQ1SeEPpEpuaGohNs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=mbhzlqrFOTd5D0VnwK8uZ6zmm6un9WEQBuC+SsW/vNr4zmirMRl3Ie03Hti+oSKnq jWL+FYDrP86b5jRs0x0aSDRUVDijhRUPxNal17nD3tvwFIHL1sEqrGQp833aEf8LTp 5Sfx49XQkhGKpNMeG65TqgqaLju0XthGjvsfdWd0= Received: by mail-wr1-f43.google.com with SMTP id y17so19759787wrh.5 for ; Tue, 24 Dec 2019 04:42:01 -0800 (PST) X-Gm-Message-State: APjAAAW1V7tRz8jIE/B7ZpiDe492bn0xDujAhMNMu/aEeAIM/n/vidcI mdfZDx+KrVErso2pyPsDKSxcmZ0dROs6dD6VR5k/FA== X-Received: by 2002:adf:eb09:: with SMTP id s9mr36777598wrn.61.1577191320403; Tue, 24 Dec 2019 04:42:00 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Andy Lutomirski Date: Tue, 24 Dec 2019 04:41:48 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH v2 04/10] lib: vdso: get pointer to vdso data from the arch To: christophe leroy Cc: Andy Lutomirski , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Arnd Bergmann , Thomas Gleixner , Vincenzo Frascino , LKML , linuxppc-dev , linux-arm-kernel , "open list:MIPS" , X86 ML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 24, 2019 at 4:15 AM Andy Lutomirski wrote= : > > > > > On Dec 24, 2019, at 7:53 PM, christophe leroy = wrote: > > > > =EF=BB=BF > > > >> Le 24/12/2019 =C3=A0 03:27, Andy Lutomirski a =C3=A9crit : > >>> On Mon, Dec 23, 2019 at 6:31 AM Christophe Leroy > >>> wrote: > >>> > >>> On powerpc, __arch_get_vdso_data() clobbers the link register, > >>> requiring the caller to set a stack frame in order to save it. > >>> > >>> As the parent function already has to set a stack frame and save > >>> the link register to call the C vdso function, retriving the > >>> vdso data pointer there is lighter. > >> I'm confused. Can't you inline __arch_get_vdso_data()? Or is the > >> issue that you can't retrieve the program counter on power without > >> clobbering the link register? > > > > Yes it can be inlined (I did it in V1 https://patchwork.ozlabs.org/patc= h/1180571/), but you can't do it without clobbering the link register, beca= use the only way to get the program counter is to do to as if you were call= ing another function but you call to the address which just follows where y= ou are, so that it sets LR which the simulated return address which corresp= onds to the address following the branch. > > > > static __always_inline > > const struct vdso_data *__arch_get_vdso_data(void) > > { > > void *ptr; > > > > asm volatile( > > " bcl 20, 31, .+4;\n" > > " mflr %0;\n" > > " addi %0, %0, __kernel_datapage_offset - (.-4);\n" > > : "=3Db"(ptr) : : "lr"); > > > > return ptr + *(unsigned long *)ptr; > > } > > > >> I would imagine that this patch generates worse code on any > >> architecture with PC-relative addressing modes (which includes at > >> least x86_64, and I would guess includes most modern architectures). > > > > Why ? Powerpc is also using PC-relative addressing for all calls but in= direct calls. > > I mean PC-relative access for data. The data page is at a constant, know= n offset from the vDSO text. > > I haven=E2=80=99t checked how much x86_64 benefits from this, but at leas= t the non-array fields ought to be accessible with a PC-relative access. > > It should be possible to refactor a little bit so that the compiler can s= till see what=E2=80=99s going on. Maybe your patch actually does this. I= =E2=80=99d want to look at the assembly. This also might not matter much o= n x86_64 in particular, since x86_64 can convert a PC-relative address to a= n absolute address with a single instruction with no clobbers. > > Does power have PC-relative data access? If so, I wonder if the code can= be arranged so that even the array accesses don=E2=80=99t require computin= g an absolute address at any point. Indeed the x86 code is also suboptimal, but at least the unnecessary absolute address calculation is cheap on x86_64. Ideally we'd pass around offsets into the vdso data instead of passing pointers, and maybe the compiler will figure it out. I can try to play with this in the morning.