Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp7526896ybl; Tue, 24 Dec 2019 04:16:03 -0800 (PST) X-Google-Smtp-Source: APXvYqxebyK1wwQQVFxkUrhhqrDa2ChwRNbz+4FfjbaXG6OB6W7XeIK+ihk4AW6xVA+X3402ORKw X-Received: by 2002:a05:6830:160c:: with SMTP id g12mr37318781otr.82.1577189763252; Tue, 24 Dec 2019 04:16:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577189763; cv=none; d=google.com; s=arc-20160816; b=IP5Jzsjk5o1+OmnTYRNQeXKRye+q2gX67S2TNzfvdGvGwCnAI9fOeBwLZx5VpLoiKZ BBHxE3RQsqLGzR+3TmCkCZ1gaeEQwiw5al6SwzDiTGp4GpzCTu8bIuGB9ApWF22RlWwn 62MmcHTs/bjk84GfKs4iALoNrWRYfpxAOyDxSie0VrzuyVEIpxDozTkHhpKUQanEiSCc YQl+JnvkWpKQPyGR/ygUGxgSvLf6scRzUL82XF8hhoG/DcKVIAF8QmtR332Im4WJ2fV2 tkuv3QUQRBwisDto0nIo0yfH8g72uJNtETFWauhp79wS36B55kMbO0El+9wX4qlCTZrh klPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:in-reply-to:cc:references:message-id :date:subject:mime-version:from:content-transfer-encoding :dkim-signature; bh=cUl5gZioHf+9+6AN9dmbhGHLhNt8/shlwV1E7YstAts=; b=ujaQV3xUnTE+Tx8LHPIlye4ikXJa5XdmiOWjjjCmUGqmT9stkztHzSuF5RUIF8vf7c FDnH7ptT/9wJlgeXCGwE4gWyt4iZ2ZMvMDbIXp2twF5p2GmT/5SvkKf5d7CwqPwPHqme ifDuB+8x/t97F8/7LYfUuFeZzQpv+qcemOdxryv5mjP5pY9sUZ+3uK2A8JNTxSomQ/XO PFOXFN8WPLTZtXjodtg8/6aGQk968nqg3NezCiiiZJvJQXDgyB/8IxQIeS9jGvVI8wa3 ArV+ySTUQJ2q7uMIRlRRR3WwmPaNV+9bbUaeb7LWcu0RgaCK2LHKM98NdHl6KGyQOoVN eKOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=zDWD8XCA; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g6si11037406otk.171.2019.12.24.04.15.51; Tue, 24 Dec 2019 04:16:03 -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=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=zDWD8XCA; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726216AbfLXMPP (ORCPT + 99 others); Tue, 24 Dec 2019 07:15:15 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:38239 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726157AbfLXMPO (ORCPT ); Tue, 24 Dec 2019 07:15:14 -0500 Received: by mail-pf1-f194.google.com with SMTP id x185so10690372pfc.5 for ; Tue, 24 Dec 2019 04:15:14 -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=cUl5gZioHf+9+6AN9dmbhGHLhNt8/shlwV1E7YstAts=; b=zDWD8XCA/EeC40f+rqUuDAnCbmAAgAgN8grpTLGD/hu+c6oJ0ekyx9F6083vGsPNpB IGrhdkZdQkxUJLQB7IC7MUBKdiAhvr42yCtnEmbLuDVhaVlWU50A+XXkfqUzCfKxLwYd NcWZApcamRuoTETR8c7gHOWeAVehTsmseTXj6LnGvlE98ZW3YWEywJh2onhr62RKIN/O QbWUv3VfPQ9hUaNXtaLLQYhY2txQ0sPDCgcRwZIrZh36FXuwhdnUh56nRBpE8VWMrHr3 eko3/wFRsyPKl+dK9FEf1/R7qWEszOxJvMCuzKzRvNgASrlCBXtD9TcieHqLYVVfd8P7 LnPg== 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=cUl5gZioHf+9+6AN9dmbhGHLhNt8/shlwV1E7YstAts=; b=CtsR2NPcrPNJe+OsdvuVZ0xJDILc8Mr4n05LqtGESX9a4FXbFcUv07Mw6bSuw+1agp eF7guD4edd9kxLRxtzyXNHT9NJkHQn6MxyeblVnZWnyz9lQT9KXPXcYL3GLwBhD6z06q 0/rT4bO0gFebWR7VXRk4DdIb46ih0AlzL0bDHuhT1uaDiFeTr14/HyWwMdAGxmJbBzfj 2YXeIqvNQSgCysupQmG8suBWwECFuK2udbH7ZWv28rnvu9V/1Ab3o8wpfBcgbHBV+whN 5vnwogRsOeCfwC9+gOrCUcqkD25W0RURqOMpB34W+WIHt3RkoPAKRZFqYTi7aQHPYeei LDuQ== X-Gm-Message-State: APjAAAWSG3FvOhy1WUBvf1Zuxj9u6dpUAxP6U823E+D3giHEkzFBBwxc JTNXPnHjaLZxXKFOfhN4E7tmvw== X-Received: by 2002:a62:868f:: with SMTP id x137mr34816521pfd.228.1577189713974; Tue, 24 Dec 2019 04:15:13 -0800 (PST) Received: from [192.168.0.9] (111-255-104-19.dynamic-ip.hinet.net. [111.255.104.19]) by smtp.gmail.com with ESMTPSA id j5sm11842535pfn.180.2019.12.24.04.15.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 24 Dec 2019 04:15:13 -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: [RFC PATCH v2 04/10] lib: vdso: get pointer to vdso data from the arch Date: Tue, 24 Dec 2019 20:15:11 +0800 Message-Id: References: 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 In-Reply-To: To: christophe leroy X-Mailer: iPhone Mail (17C54) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Dec 24, 2019, at 7:53 PM, christophe leroy wr= ote: >=20 > =EF=BB=BF >=20 >> 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: >>>=20 >>> On powerpc, __arch_get_vdso_data() clobbers the link register, >>> requiring the caller to set a stack frame in order to save it. >>>=20 >>> 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? >=20 > Yes it can be inlined (I did it in V1 https://patchwork.ozlabs.org/patch/1= 180571/), but you can't do it without clobbering the link register, because t= he only way to get the program counter is to do to as if you were calling an= other function but you call to the address which just follows where you are,= so that it sets LR which the simulated return address which corresponds to t= he address following the branch. >=20 > static __always_inline > const struct vdso_data *__arch_get_vdso_data(void) > { > void *ptr; >=20 > asm volatile( > " bcl 20, 31, .+4;\n" > " mflr %0;\n" > " addi %0, %0, __kernel_datapage_offset - (.-4);\n" > : "=3Db"(ptr) : : "lr"); >=20 > return ptr + *(unsigned long *)ptr; > } >=20 >> 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). >=20 > Why ? Powerpc is also using PC-relative addressing for all calls but indir= ect calls. I mean PC-relative access for data. The data page is at a constant, known o= ffset from the vDSO text. I haven=E2=80=99t checked how much x86_64 benefits from this, but at least t= he 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 stil= l 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 on x86_6= 4 in particular, since x86_64 can convert a PC-relative address to an absolu= te 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 computing an= absolute address at any point.