Received: by 10.223.176.5 with SMTP id f5csp1730313wra; Sun, 4 Feb 2018 10:41:24 -0800 (PST) X-Google-Smtp-Source: AH8x2265x4mWG4C5VYgfYIXwtRu+HW3C+yCLp/81vi663jGSLjLTcgGHooa6BdnOrmk/rTxO9poo X-Received: by 2002:a17:902:a589:: with SMTP id az9-v6mr20428877plb.298.1517769684267; Sun, 04 Feb 2018 10:41:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517769684; cv=none; d=google.com; s=arc-20160816; b=SSk9RMZ+SUFrOcevwEKrF7HMNZN7tEyhHVA0/0VToRCWP7MKqSnSWI12evRsLfBAy3 uwBLErzWon/a0p2bM+MBiewPdOh3m66bKoSSwNvV3NH2Phspg+rptSIBPtEg9OtPOraR XKsOoGNY1m9bFP9eSc+3HOEUqQvsOR3U00w8/t1yx/rrnMKCd7hVpCkPuR82QSR7+tav jXDpToWkzZb/4CnuqvoZUqL24kB9EZ1+EuiY2S4/AB/XMheFOyNHnnN6L397Jpxyiagg I++5APPxcLXJvKhRWToWyBWTLy6THv4cRSmrXaLKCsvzAwY1CkpOgZeM10YocPG3HJds n4/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=4uq4o4ZCesXtx67UmN3hOLTiiZdTFWmlUTXHZOmcRfc=; b=YpHKch1vwWQB0OKhnJtNOJJ1WVqLwQVYni9aCLHrILRv+Pnhgn4zZfCOxodAtOAT07 dfol3hFC4NrxEQegZethklBwTbQ1yBd/w0/GIJXGTrsEJiK/gbaOmXZFFznZ/ZiNgzoR AckOB52jk5/ATUFT0iwJAi7TwvHF1Nib3QYyK3xbt+s7C+XWWqUt2mUd44QAslHmHaQr PPwdmrG0QfycRhrwNV38WDXqB10r4bw31/nC/2cUHhlc/tJeAwL4OfrBtGfJWMoZxACl 6BGin0ka+YyVNszW2ftzsZTrSEUaSBoeVwiQNzzC5ZeYXMWY9w4sQniaBnyKx/xn8GtA Pe6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZxPvQ2jy; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s9-v6si5769795plq.187.2018.02.04.10.41.09; Sun, 04 Feb 2018 10:41:24 -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=@linaro.org header.s=google header.b=ZxPvQ2jy; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752255AbeBDSjf (ORCPT + 99 others); Sun, 4 Feb 2018 13:39:35 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:52059 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752182AbeBDSjK (ORCPT ); Sun, 4 Feb 2018 13:39:10 -0500 Received: by mail-wm0-f68.google.com with SMTP id r71so22185298wmd.1 for ; Sun, 04 Feb 2018 10:39:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=4uq4o4ZCesXtx67UmN3hOLTiiZdTFWmlUTXHZOmcRfc=; b=ZxPvQ2jytuFxXUWOlbPb28R1g8Cmpnip6C0yWuJQcohvrD9gGWDOCXSBex8+50hf7/ r3+jhy1oXq2ws1LZFrsJgHVg72EvCokMfPAHawq7XB5K6C+rSPEsEuzpXj3AJOOvXRyB kpB13Zbt8aCqyeaFY9Fx1pEPZX9+yZHOfTXQ4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=4uq4o4ZCesXtx67UmN3hOLTiiZdTFWmlUTXHZOmcRfc=; b=ca4t9GCA42BhVnZNs7QXSx4Yv1wimZ9lj/xBqg9q76YhgAIFcKFiwjpTo6buga0cKd IbdBIuT3rtL1Cy5OWS6JA/d1B19M1bx2Qb3ngw7jfMm1ERGBCLm0rq7DJ5f6Sv42cJ08 VxRnVoQ/tKY+WS1ie4BLCCQ2Zijtho+imSLnCtumiEMfkL1IJW4x7QOWfByFkJJxbPKW fA48ExLlvjzxH2vVkqgTUWz9qA3gnZRQlMwSlNBhFO4Ql23B0JbJ4WsI8lyMUapQZZQe MrPho0E6ylTp1SLArVUYLJkMta26aUsBe6Ve9iOo/cKD0oP9Pmqf4aWNo18Cl5ubhdVo EK5g== X-Gm-Message-State: AKwxytc/VDJlXLk+lekeWWzc4nJmrUCLyWJByFXp7ycK5y+ePJoEZ/xz M4Bk1mL4a9o4+KzBviwMC1wilA== X-Received: by 10.80.226.203 with SMTP id q11mr78095049edl.248.1517769549280; Sun, 04 Feb 2018 10:39:09 -0800 (PST) Received: from localhost (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id f55sm6629132ede.77.2018.02.04.10.39.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 04 Feb 2018 10:39:08 -0800 (PST) Date: Sun, 4 Feb 2018 19:39:07 +0100 From: Christoffer Dall To: Marc Zyngier Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, Catalin Marinas , Will Deacon , Peter Maydell , Lorenzo Pieralisi , Mark Rutland , Robin Murphy , Ard Biesheuvel , Andrew Jones , Hanjun Guo , Jayachandran C , Jon Masters , Russell King - ARM Linux Subject: Re: [PATCH v3 12/18] arm64: KVM: Add SMCCC_ARCH_WORKAROUND_1 fast handling Message-ID: <20180204183907.GP21802@cbox> References: <20180201114657.7323-1-marc.zyngier@arm.com> <20180201114657.7323-13-marc.zyngier@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180201114657.7323-13-marc.zyngier@arm.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 01, 2018 at 11:46:51AM +0000, Marc Zyngier wrote: > We want SMCCC_ARCH_WORKAROUND_1 to be fast. As fast as possible. > So let's intercept it as early as we can by testing for the > function call number as soon as we've identified a HVC call > coming from the guest. Hmmm. How often is this expected to happen and what is the expected extra cost of doing the early-exit handling in the C code vs. here? I think we'd be better off if we only had a single early-exit path (and we should move the FP/SIMD trap to that path as well), but if there's a measurable benefit of having this logic in assembly as opposed to in the C code, then I'm ok with this as well. The code in this patch looks fine otherwise. Thanks, -Christoffer > > Signed-off-by: Marc Zyngier > --- > arch/arm64/kvm/hyp/hyp-entry.S | 20 ++++++++++++++++++-- > 1 file changed, 18 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/kvm/hyp/hyp-entry.S b/arch/arm64/kvm/hyp/hyp-entry.S > index e4f37b9dd47c..f36464bd57c5 100644 > --- a/arch/arm64/kvm/hyp/hyp-entry.S > +++ b/arch/arm64/kvm/hyp/hyp-entry.S > @@ -15,6 +15,7 @@ > * along with this program. If not, see . > */ > > +#include > #include > > #include > @@ -64,10 +65,11 @@ alternative_endif > lsr x0, x1, #ESR_ELx_EC_SHIFT > > cmp x0, #ESR_ELx_EC_HVC64 > + ccmp x0, #ESR_ELx_EC_HVC32, #4, ne > b.ne el1_trap > > - mrs x1, vttbr_el2 // If vttbr is valid, the 64bit guest > - cbnz x1, el1_trap // called HVC > + mrs x1, vttbr_el2 // If vttbr is valid, the guest > + cbnz x1, el1_hvc_guest // called HVC > > /* Here, we're pretty sure the host called HVC. */ > ldp x0, x1, [sp], #16 > @@ -100,6 +102,20 @@ alternative_endif > > eret > > +el1_hvc_guest: > + /* > + * Fastest possible path for ARM_SMCCC_ARCH_WORKAROUND_1. > + * The workaround has already been applied on the host, > + * so let's quickly get back to the guest. We don't bother > + * restoring x1, as it can be clobbered anyway. > + */ > + ldr x1, [sp] // Guest's x0 > + eor w1, w1, #ARM_SMCCC_ARCH_WORKAROUND_1 > + cbnz w1, el1_trap > + mov x0, x1 > + add sp, sp, #16 > + eret > + > el1_trap: > /* > * x0: ESR_EC > -- > 2.14.2 >