From patchwork Tue Mar 2 14:59:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12113655 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2519C433E0 for ; Wed, 3 Mar 2021 15:00:34 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9E7ED60240 for ; Wed, 3 Mar 2021 15:00:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9E7ED60240 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Cc:To:From:Subject:References:Mime-Version: Message-Id:In-Reply-To:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=0a4WhGor+qH54PVEY+iMLI75WyS/nzsxK6cOcs4RVJM=; b=NKhlzhBvQqZKr+ ZPPvA7jw5aRdni464CSeAterVGrdc/kvm4WNjl/J509O+BT4rkVZwPJkrElLaepK0QkfcNMfg2YRS JDAAer3SLHbKRH772QHpnF2f8xap1ksIL3QpWoXQF3yduUq2Sz1MqenfyyN4RMw8pv6YVJ3Bk2LZG QkbCi2TWpFUIH1mEODyyrZIqz5eCXDJlD8klafXHsAnGohjwDDlnfFoKOawoQYAN7AWYyYERqP4sY Avk9ZHJ5P877gIlHCEi5vk1BOM/AYoCcFZILLkyyf0jDdgjhhH4VXWTErbIi++S9HBlcwF8gyxEMh Njh4MoAgQ0ye9WB8jGGQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lHSwM-005Fmw-9c; Wed, 03 Mar 2021 14:57:32 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lHSBT-0054NU-PT for linux-arm-kernel@desiato.infradead.org; Wed, 03 Mar 2021 14:09:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=84bkslXA7Qi7zlX0xHNbjR4XGFTrfSQqHB0l+SkjRTk=; b=WCfbmWYNNqr9gexqlv5bbMOBn0 E+1j+1YGmLAFMTC8ENhn87vDv/JfN902cbtq0wwPFh7nQLfXNCUErPB17Yv0UHjVQO7soZWkjeLBt J40ZufL/qu/2qvh0p9x+Aaq3PXwe2/TuMcR7Y3yVPCr4sQWSXKpcP/zirKskDwySHU1WvcPGNcm9g +VtUqXSTT720T/XDCCuRgWO+q9nyYLxXYtWTE04a99jjZrpnJV5brah8TPtbR/ibpzybGy5vytW5p pwTdYr9QcBch4DIJdYUcJl9u90/3gqABRTjsy9SDh9IUc84iZzfWHMpCDUsrvwta2llVnjfiWt4FJ ljZ8Ps1w==; Received: from mail-wr1-x44a.google.com ([2a00:1450:4864:20::44a]) by casper.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lH6XE-00HJJG-OL for linux-arm-kernel@lists.infradead.org; Tue, 02 Mar 2021 15:02:07 +0000 Received: by mail-wr1-x44a.google.com with SMTP id m9so5489908wrx.6 for ; Tue, 02 Mar 2021 07:01:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=84bkslXA7Qi7zlX0xHNbjR4XGFTrfSQqHB0l+SkjRTk=; b=aEyIjsz9Q39OmQlGKhPsdWMeCxwA+8gfzAIcUr3vtuH7vJkQ/TC8zCkBwOeeBT65tq UvSouJ8Birgm8kdd91FSgiyZCYROychF8+9Sg1dSYXCER9zOEopyAV4P/kgm4Ysxeidy 7ft7SR+/KlrHCJgsZMEZ51u1Cmk9vBYllJNwbmgZ1ompvmxQEqTIg6O0Ypw4YW+TiLNY Bdfy60xclmeqbqcp8GDWtDDVvsqYWew2CdzBsipN3fqfz7oI3broHa+hdFZwgg01rnPc IAtkChQhjHl8hf9R0x8GkU6smUb+gwabjgaL22vSTdg2PoB4sWRTIVOgQBrjdOfDE6Mh olZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=84bkslXA7Qi7zlX0xHNbjR4XGFTrfSQqHB0l+SkjRTk=; b=gA7NkhodVdWimsMrGCSCWhdVWQB5IJ5VeULgUkayIYRjaE4JuJVHWf7zzgDLwjvqid /ktn3nto6EjO5zQx/vAU5TMkguPuBTICFuOsTBQGTJqIBTxN1N3It+s5c/2O6Q9CpBk1 Ko+2rg39WJIB8lsY6YyfNRDQKd8cjkON4f1eUfZnheaKquQiCZbpHbEByp/8kzlAIpUE 4ymJXmIa+tmEQRVhioEmGVDI9MJaRcPC4MzHlTU3n/k/Gs4Tqfl8gDnXuRxL5BgWdnsI iplwxSr9qMnr9CfTE8yrZ6jqrob8I7yDS451lseJA1UA0pe7mEyeNwH9V0C++0m5QXJe 4AjA== X-Gm-Message-State: AOAM531qtf6CGEfwAMCkUnL4vWd56J9oZrbHj7ZKsCqVXG4bBIceLhIx mMJVp/aniV33DurbJIRUUhE6HfpzM/x9 X-Google-Smtp-Source: ABdhPJwFUzBVYVUNUz65kgYHvUCXtvq4NXrt8gCrlNsOFSMTng7gs+AjbNDT7VknGe5P7PaLfd9Y7549RF9U X-Received: from r2d2-qp.c.googlers.com ([fda3:e722:ac3:10:28:9cb1:c0a8:1652]) (user=qperret job=sendgmr) by 2002:a1c:2e90:: with SMTP id u138mr496527wmu.0.1614697237854; Tue, 02 Mar 2021 07:00:37 -0800 (PST) Date: Tue, 2 Mar 2021 14:59:44 +0000 In-Reply-To: <20210302150002.3685113-1-qperret@google.com> Message-Id: <20210302150002.3685113-15-qperret@google.com> Mime-Version: 1.0 References: <20210302150002.3685113-1-qperret@google.com> X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog Subject: [PATCH v3 14/32] KVM: arm64: Factor out vector address calculation From: Quentin Perret To: catalin.marinas@arm.com, will@kernel.org, maz@kernel.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com Cc: android-kvm@google.com, linux-kernel@vger.kernel.org, kernel-team@android.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, tabba@google.com, mark.rutland@arm.com, dbrazdil@google.com, mate.toth-pal@arm.com, seanjc@google.com, qperret@google.com, robh+dt@kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210302_150207_913707_F283F2B2 X-CRM114-Status: GOOD ( 11.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In order to re-map the guest vectors at EL2 when pKVM is enabled, refactor __kvm_vector_slot2idx() and kvm_init_vector_slot() to move all the address calculation logic in a static inline function. Acked-by: Will Deacon Signed-off-by: Quentin Perret --- arch/arm64/include/asm/kvm_mmu.h | 8 ++++++++ arch/arm64/kvm/arm.c | 9 +-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h index 90873851f677..5c42ec023cc7 100644 --- a/arch/arm64/include/asm/kvm_mmu.h +++ b/arch/arm64/include/asm/kvm_mmu.h @@ -168,6 +168,14 @@ phys_addr_t kvm_mmu_get_httbr(void); phys_addr_t kvm_get_idmap_vector(void); int kvm_mmu_init(void); +static inline void *__kvm_vector_slot2addr(void *base, + enum arm64_hyp_spectre_vector slot) +{ + int idx = slot - (slot != HYP_VECTOR_DIRECT); + + return base + (idx * SZ_2K); +} + struct kvm; #define kvm_flush_dcache_to_poc(a,l) __flush_dcache_area((a), (l)) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 3f8bcf8db036..26e573cdede3 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1345,16 +1345,9 @@ static unsigned long nvhe_percpu_order(void) /* A lookup table holding the hypervisor VA for each vector slot */ static void *hyp_spectre_vector_selector[BP_HARDEN_EL2_SLOTS]; -static int __kvm_vector_slot2idx(enum arm64_hyp_spectre_vector slot) -{ - return slot - (slot != HYP_VECTOR_DIRECT); -} - static void kvm_init_vector_slot(void *base, enum arm64_hyp_spectre_vector slot) { - int idx = __kvm_vector_slot2idx(slot); - - hyp_spectre_vector_selector[slot] = base + (idx * SZ_2K); + hyp_spectre_vector_selector[slot] = __kvm_vector_slot2addr(base, slot); } static int kvm_init_vector_slots(void)