Received: by 10.223.176.5 with SMTP id f5csp4038821wra; Tue, 30 Jan 2018 00:55:26 -0800 (PST) X-Google-Smtp-Source: AH8x226Ax/wpRKthDUnlF16ssXL6R7gWsNbRV/IbbeZln7HqCyW6AliFn5nyFagWoMtN3rThw3/B X-Received: by 2002:a17:902:8545:: with SMTP id d5-v6mr4716509plo.306.1517302525998; Tue, 30 Jan 2018 00:55:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517302525; cv=none; d=google.com; s=arc-20160816; b=dWi6fD/G2kcaH371qPtEvdLkZ7xVf277b+2GUbcu5VwEFfNvfLMp4HEbIm5VJmvsWt kfFamEA3JYA6qcZ+Q9Nn9BTKROcWrbkcggqIYKsvlzD7OVrR7SaEMC541L8Gi1KL5Www a2AArsOpvvU96Ny3zD7lEWWBcQW38MlReHGSPMUjjoOs/OVwj4IwIb0sdeqGSLp2Xezj d5EdRbQso6oJK0LqWKhFnEkMkSNmhXa/mvUrQiYxAoeJfr+I68qwcPCXngkE0t9UJeKS P+OsiTT72PUr9ZCzmym5/mufQ3ThB+LBmqiRbCyuawGIGh7Cx+/Bjonn2LyYksw4OQUa Cejw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject :arc-authentication-results; bh=v89D8nF60G6LJORdus+2eJS45wRrWFwQwwRZ+7Qydhs=; b=QTFznkl/F49SieqNUEYjvAIbm+SKnf1Urr/m9yTnBNF/7NsSCqKBymnSxza6lPvS0m 9I//9w21Nlch28FIO3xHPJtPIEJCWax93k6dz0EguzRmizfZpOjuvyRb5yJEQ3Gd0/dS RAa6zWgfHqSdGTfQ39GpXKpB+YTGtJ+Op+74Bav6OBwdSxTCcT/1xFJ4L+oRz26hxwfT vYmXKFANofiwBnzMNPG+dEgrLMd+/NFCySLY7wCC81qbLOAbmqBANLtzjWeLSN5zUhJZ jf0I1GAzT7RlmOtnWZPJ+6D0rRt0PpYQPM+JxcdSEyv0P8qGUNXDNKx9ugrTT6gL0PzB cWIA== ARC-Authentication-Results: i=1; mx.google.com; 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 x8-v6si10872153plv.61.2018.01.30.00.55.11; Tue, 30 Jan 2018 00:55:25 -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; 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 S1751979AbeA3IyY (ORCPT + 99 others); Tue, 30 Jan 2018 03:54:24 -0500 Received: from foss.arm.com ([217.140.101.70]:50908 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751563AbeA3IyW (ORCPT ); Tue, 30 Jan 2018 03:54:22 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2E48080D; Tue, 30 Jan 2018 00:54:22 -0800 (PST) Received: from [10.1.207.62] (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5E1D53F487; Tue, 30 Jan 2018 00:54:19 -0800 (PST) Subject: Re: [PATCH v2 15/16] arm/arm64: smccc: Implement SMCCC v1.1 inline primitive To: Robin Murphy , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu Cc: Catalin Marinas , Will Deacon , Peter Maydell , Christoffer Dall , Lorenzo Pieralisi , Mark Rutland , Ard Biesheuvel , Jon Masters References: <20180129174559.1866-1-marc.zyngier@arm.com> <20180129174559.1866-16-marc.zyngier@arm.com> <04d16ecd-044c-fe56-f9be-78d0cb591e71@arm.com> From: Marc Zyngier Organization: ARM Ltd Message-ID: <84eaa3ee-6838-466a-9974-98b6092b9e6c@arm.com> Date: Tue, 30 Jan 2018 08:54:17 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <04d16ecd-044c-fe56-f9be-78d0cb591e71@arm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 29/01/18 19:07, Robin Murphy wrote: > On 29/01/18 17:45, Marc Zyngier wrote: >> One of the major improvement of SMCCC v1.1 is that it only clobbers >> the first 4 registers, both on 32 and 64bit. This means that it >> becomes very easy to provide an inline version of the SMC call >> primitive, and avoid performing a function call to stash the >> registers that would otherwise be clobbered by SMCCC v1.0. > > This is disgusting... I love it :D I expected nothing less from you! ;-) > >> Signed-off-by: Marc Zyngier >> --- >> include/linux/arm-smccc.h | 157 ++++++++++++++++++++++++++++++++++++++++++++++ >> 1 file changed, 157 insertions(+) >> >> diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h >> index dd44d8458c04..bc5843728909 100644 >> --- a/include/linux/arm-smccc.h >> +++ b/include/linux/arm-smccc.h >> @@ -150,5 +150,162 @@ asmlinkage void __arm_smccc_hvc(unsigned long a0, unsigned long a1, >> >> #define arm_smccc_hvc_quirk(...) __arm_smccc_hvc(__VA_ARGS__) >> >> +/* SMCCC v1.1 implementation madness follows */ >> +#ifdef CONFIG_ARM64 >> + >> +#define SMCCC_SMC_INST "smc #0" >> +#define SMCCC_HVC_INST "hvc #0" >> + >> +#define __arm_smccc_1_1_prologue(inst) \ >> + inst "\n" \ >> + "cbz %[ptr], 1f\n" \ >> + "stp %x[r0], %x[r1], %[ra0]\n" \ >> + "stp %x[r2], %x[r3], %[ra2]\n" \ >> + "1:\n" \ >> + : [ra0] "=Ump" (*(&___res->a0)), \ >> + [ra2] "=Ump" (*(&___res->a2)), > > Rather than embedding a guaranteed spill to memory, I wonder if there's > money in just always declaring r0-r3 as in-out operands, and propagating > them by value afterwards, i.e.: > > asm(...); > if (___res) > *___res = (struct arm_smccc_res){ r0, r1, r2, r3 }; > > In theory, for sufficiently simple callers that might allow res to stay > in registers for its entire lifetime and give nicer codegen. It *might* > also simplify some of this macro machinery too, although at this point > in the evening I can't really tell... I just implemented it, and this is indeed much better. In most cases, the store gets optimized away, mostly because we either pass NULL (and the condition is dropped) or the store doesn't need to take place as we evaluate a condition and discard the structure, like in check_smccc_arch_workaround_1. In all cases, this allows for slightly reduced levels of cpp madness, and better codegen. I also suspect it will solve Ard's register allocation issue. Thanks, M. -- Jazz is not dead. It just smells funny...