Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp4479108imm; Mon, 15 Oct 2018 15:53:24 -0700 (PDT) X-Google-Smtp-Source: ACcGV63WhoCbTOMY0IgMOxHpQaWMtQFtGJ3SbvuBPs3iGuvq/phgF5OKNi2mmfK1n91BTGaJg/xd X-Received: by 2002:a63:86c8:: with SMTP id x191-v6mr18011775pgd.39.1539644004621; Mon, 15 Oct 2018 15:53:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539644004; cv=none; d=google.com; s=arc-20160816; b=SmZ3J+GRCCLg4nsBMSnMX4vMcS/RGXB6nMtug1LwSmqgphDdm3flMPGovxum2h5/FZ 95yIDz7JiC7GmtYmaXXaRsogdHE1hHeioMdsCuWpGcBiCcG6NIoicMoIFz0qRxPiITZO 6bBRT5J8YMPI3GIrD6CohtGD/ELLqyYXP58M/H1WOQ7dh21TfLlsrczs4duYe1ATczYS Fp1r+ZU8MyvhcC3/sYvWXa1myH0tXUppVHbtX/ibzUpko+aTpUUUyvV95eMlVgsepeKW o5M03m6E6EBwIPKNDsWSdWGSTdLREkmmphKyO+0ypeS+nyaez8FublPLF4Z6ljtoaIyr yClg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:references :in-reply-to:subject:cc:to:from:date:content-transfer-encoding :mime-version:dkim-signature; bh=v8yBp11xBReu7sym4zCNE2ASOh1Kk5DCKO1gESKDhTY=; b=JL/VCGvcBSAqz1r+f+s8RQTh0ln9aPIrr8amfS4spEFVaS+V2FOAeoM0LFCQ61y1aO 6NOKPdE0JQrtXFdUNa0vjYwVkTzoVwHJ+9mOcsap0fvltlcJupSyBSZfIcDGnRoWlMbB ugVVPBEukINpAlMe0ED8t6Ct5gyi81+wdRCgcfg3VRZzDgwe0dhhK6X2L09xRgI/ttS+ YADFYFswBtWkwzW7eiftG9dGE6JLUUO/TGBgJCEpQ63J+SqU6ZQPhr6ll7N7L6MYFZwP 4haymENj55mat5AsALtXeaFBnQuy2RH9LIEGyfXO1bWnuVnk9vNTybhnjo1odTLizEKJ 04Hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@agner.ch header.s=dkim header.b=sVKEnjhd; 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 f7-v6si13485398pln.125.2018.10.15.15.53.08; Mon, 15 Oct 2018 15:53:24 -0700 (PDT) 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=@agner.ch header.s=dkim header.b=sVKEnjhd; 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 S1727045AbeJPGir (ORCPT + 99 others); Tue, 16 Oct 2018 02:38:47 -0400 Received: from mail.kmu-office.ch ([178.209.48.109]:38794 "EHLO mail.kmu-office.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726877AbeJPGir (ORCPT ); Tue, 16 Oct 2018 02:38:47 -0400 Received: from webmail.kmu-office.ch (unknown [IPv6:2a02:418:6a02::a3]) by mail.kmu-office.ch (Postfix) with ESMTPSA id 292795C0106; Tue, 16 Oct 2018 00:51:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=agner.ch; s=dkim; t=1539643886; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=v8yBp11xBReu7sym4zCNE2ASOh1Kk5DCKO1gESKDhTY=; b=sVKEnjhdMfZdTP8hOadFs/uc0xT9mh+5SjHPn6QRJaXB0CSwFpFdwd3GjjiWxOxvHXH+pA L5L2MHm7IkQ9L5IuQhcKG2IV8T49g9+1GNd6JSI2AJ1iSdUE2W3CnT1TEz09CifouvGQtD sdPDGXRB0vOJ1DnTqSH5ZZe6GELr/AA= MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Date: Tue, 16 Oct 2018 00:51:26 +0200 From: Stefan Agner To: Russell King - ARM Linux Cc: Nicolas Pitre , ulli.kroll@googlemail.com, joel@jms.id.au, arnd@arndb.de, linus.walleij@linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] ARM: copypage: do not use naked functions In-Reply-To: <20181015224152.GA30658@n2100.armlinux.org.uk> References: <20181015222621.14673-1-stefan@agner.ch> <20181015224152.GA30658@n2100.armlinux.org.uk> Message-ID: <4e598f27e3dc7ae9fd96a6cf097d1154@agner.ch> X-Sender: stefan@agner.ch User-Agent: Roundcube Webmail/1.3.7 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 16.10.2018 00:41, Russell King - ARM Linux wrote: > On Mon, Oct 15, 2018 at 06:35:33PM -0400, Nicolas Pitre wrote: >> On Tue, 16 Oct 2018, Stefan Agner wrote: >> >> > GCC documentation says naked functions should only use basic ASM >> > syntax. The extended ASM or mixture of basic ASM and "C" code is >> > not guaranteed. Currently it seems to work though. >> > >> > Furthermore with Clang using parameters in extended asm in a >> > naked function is not supported: >> > arch/arm/mm/copypage-v4wb.c:47:9: error: parameter references not >> > allowed in naked functions >> > : "r" (kto), "r" (kfrom), "I" (PAGE_SIZE / 64)); >> > ^ >> > >> > Use a regular function to be more portable. Also use volatile asm >> > to avoid unsolicited optimizations. >> > >> > Tested with qemu versatileab machine and versatile_defconfig and >> > qemu mainstone machine using pxa_defconfig compiled with GCC 7.2.1 >> > and Clang 7.0. >> > >> > Link: https://github.com/ClangBuiltLinux/linux/issues/90 >> > Reported-by: Joel Stanley >> > Signed-off-by: Stefan Agner >> > --- >> > arch/arm/mm/copypage-fa.c | 17 +++++++++++------ >> > arch/arm/mm/copypage-feroceon.c | 17 +++++++++++------ >> > arch/arm/mm/copypage-v4mc.c | 14 +++++++++----- >> > arch/arm/mm/copypage-v4wb.c | 17 +++++++++++------ >> > arch/arm/mm/copypage-v4wt.c | 17 +++++++++++------ >> > arch/arm/mm/copypage-xsc3.c | 17 +++++++++++------ >> > arch/arm/mm/copypage-xscale.c | 13 ++++++++----- >> > 7 files changed, 72 insertions(+), 40 deletions(-) >> > >> > diff --git a/arch/arm/mm/copypage-fa.c b/arch/arm/mm/copypage-fa.c >> > index ec6501308c60..33ccd396bf99 100644 >> > --- a/arch/arm/mm/copypage-fa.c >> > +++ b/arch/arm/mm/copypage-fa.c >> > @@ -17,11 +17,16 @@ >> > /* >> > * Faraday optimised copy_user_page >> > */ >> > -static void __naked >> > -fa_copy_user_page(void *kto, const void *kfrom) >> > +static void fa_copy_user_page(void *kto, const void *kfrom) >> > { >> > - asm("\ >> > - stmfd sp!, {r4, lr} @ 2\n\ >> > + register void *r0 asm("r0") = kto; >> > + register const void *r1 asm("r1") = kfrom; >> > + >> > + asm( >> > + __asmeq("%0", "r0") >> > + __asmeq("%1", "r1") >> > + "\ >> > + stmfd sp!, {r4} @ 2\n\ >> > mov r2, %2 @ 1\n\ >> > 1: ldmia r1!, {r3, r4, ip, lr} @ 4\n\ >> > stmia r0, {r3, r4, ip, lr} @ 4\n\ >> > @@ -34,9 +39,9 @@ fa_copy_user_page(void *kto, const void *kfrom) >> > subs r2, r2, #1 @ 1\n\ >> > bne 1b @ 1\n\ >> > mcr p15, 0, r2, c7, c10, 4 @ 1 drain WB\n\ >> > - ldmfd sp!, {r4, pc} @ 3" >> > + ldmfd sp!, {r4} @ 3" >> > : >> > - : "r" (kto), "r" (kfrom), "I" (PAGE_SIZE / 32)); >> > + : "r" (r0), "r" (r1), "I" (PAGE_SIZE / 32)); >> >> This is still wrong as you list r0 and r1 in the input operand list >> where they must remain constant but the code does modify them. You >> should list them in the output operand list with the "&" attribute. Also >> r2 should be listed in the clobbered list. > > Either we keep these as naked functions (and, if Clang wants to > try to inline naked functions which makes no sense, also mark them > as noinline) or we make them proper functions and also add (eg) r4 > to the clobber list and get rid of the stacking of that register > along with LR/PC. Clang does not inline naked functions, at least that is what a quick look at the disassembled code shows when compiling with 9a40ac86152c reverted. > > Having this half-way house which will generate worse code is not > acceptable. For Clang reverting 9a40ac86152c ("ARM: 6164/1: Add kto and kfrom to input operands list.") is a solution... I guess the question is why that commit was necessary back then... Do we break something by reverting it? -- Stefan