Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp4066665pxb; Tue, 17 Nov 2020 10:20:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJyX9hl10/Uagwahvc+yE2v/27K2AyhPMgXhVrlnJPGopjvLOyyxxjMmc1kIQq3XQd7aP9F1 X-Received: by 2002:a50:d784:: with SMTP id w4mr22502326edi.201.1605637227877; Tue, 17 Nov 2020 10:20:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605637227; cv=none; d=google.com; s=arc-20160816; b=XWW99O4++ycmG9nRNOIVqYIxPcW9fYI2xobz0lMCUjw3sVW7SS+KiC1yo9mmz6kFNZ a6fD9lGhd89PM07PGoChshzbW0LDAvkXNC8IhAE4/PqF4r8qJijY5UGVTCCE3Nu39UR6 wuxBvXEsIovH3novqsUcFXCbBEpgkZgDsdQ96yulZftmQdC7m+f9S8sW4/Ez2vSINQ8b 8epcOhngW2FJSXFAPfpY4kvE1N8jkk5lgU+0luVzS4XH+2nUhvunMj+XYw5bPpF53a0z LiJlPh/zOxR4B32M5IOswIlA9Qpqwj+47ACDuY0PpIe46Lr++lEKkZX5qcwj1ryPuC5G NT/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=F6/Ku+z/rldXTKyTjaRYVBv4lFiTA1v23xAOFYW1znk=; b=eeS0006NVbGS8RKBLiU2IhU6AmJ6ObuEVDH3ikWckYEpwkahak4Nh+7xkzav3v+co0 YUSHIunvMB7eY2RgLsmwaYwEdm+W4TnP9YbdAdm/OYP9zKIb44XHnKkRUWSMzLpjoYzM vL0eEtwbwpoUEVKaSclcespeU3kgybFfy/1cobOB5It5ccABe3atLdto6EVxMrexAqEB hoKkm7g3ogHpddYqfeRgPX4X5ALk3RpDZCgUHIn0ZEC1ENUkI6Oc0U3uw+T1UshTyKxi W4FBZgQHsWLP2siZAsowvI6K6yeWyxsOQyClp3qz7pTCB9OqA7OijrVifbsRB4wvTsVy bIug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZN7TMzWc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z23si13989120ejn.209.2020.11.17.10.20.02; Tue, 17 Nov 2020 10:20:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZN7TMzWc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730941AbgKQSQy (ORCPT + 99 others); Tue, 17 Nov 2020 13:16:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730913AbgKQSQx (ORCPT ); Tue, 17 Nov 2020 13:16:53 -0500 Received: from mail-wr1-x449.google.com (mail-wr1-x449.google.com [IPv6:2a00:1450:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C19FC0613CF for ; Tue, 17 Nov 2020 10:16:53 -0800 (PST) Received: by mail-wr1-x449.google.com with SMTP id w6so13337943wrk.1 for ; Tue, 17 Nov 2020 10:16:53 -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=F6/Ku+z/rldXTKyTjaRYVBv4lFiTA1v23xAOFYW1znk=; b=ZN7TMzWcg2kpOSqffDoVhtCt8uuThETRtG/2q52T5qCUyS9wVVeqC8DLp9GHUxjPzl aRJom2yDGA29gjrTZrqqST+sCuyxUep0AcG3zyv30IblaP/4C9KEnPFKrtG+ZDCaIltz G1DBpjrBArDifkZHj2qKeMp5ucykr8vNPn9d5SaiPvot0qDGmYdqV7hchxuHrIYBK3Yt zQezM/vBty6xeYGG3xPKCMDP12KKhXP5Pcw3ErAA+STpsQVaYQ62FE6TFa2w6PAZc4YJ a7cIVY5OSaYEJLpdXMS0djxudcoIzYtYFsaSPvip1YOmJbhIujEddKb27SQvDMsnNhfF PBPQ== 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=F6/Ku+z/rldXTKyTjaRYVBv4lFiTA1v23xAOFYW1znk=; b=Grs7lLi4nqZVZzjwOhOgInEGrPBuVwyV9bKomMexsW2sHhzlZfl2bNO04n3LSDgCrN aXnJYkCDpcQW0V2IqJq1lkdruvqFd/nmMiAmn0wcc4qJ7/dBHKE8Il7J/pT7w78/sWBr FMXy1pCV/fojiu4xqimlMEZJvuitMEwgZc/jPjpRlSAramilrcO3UV9OovdF2mk0QaGF 3PoL24tvWMWm1Og4t/J7xiMM75TF00DtF47coWYc8cLJlKrKNvqROAkb9gqwx1DY+ya9 yOEC6SMCgtkwM48JnZqFYO2aLMz3lIFk4RVflPrVZSBHqYzGiL8SeScU3sWUfQYS6G/V 2wFg== X-Gm-Message-State: AOAM533C8MdEsTTOWBVofU/e/WpIIGaM/T/3ylMlzVoIIndjOECV/VI8 B8mr/HiM6zkGT0i9IazmAZELaWvEmtvy Sender: "qperret via sendgmr" X-Received: from luke.lon.corp.google.com ([2a00:79e0:d:210:f693:9fff:fef4:a7ef]) (user=qperret job=sendgmr) by 2002:adf:82f5:: with SMTP id 108mr804663wrc.269.1605637011993; Tue, 17 Nov 2020 10:16:51 -0800 (PST) Date: Tue, 17 Nov 2020 18:15:54 +0000 In-Reply-To: <20201117181607.1761516-1-qperret@google.com> Message-Id: <20201117181607.1761516-15-qperret@google.com> Mime-Version: 1.0 References: <20201117181607.1761516-1-qperret@google.com> X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog Subject: [RFC PATCH 14/27] KVM: arm64: Factor out vector address calculation From: Quentin Perret To: Catalin Marinas , Will Deacon , Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose , Rob Herring , Frank Rowand Cc: "moderated list:ARM64 PORT (AARCH64 ARCHITECTURE)" , open list , "open list:KERNEL VIRTUAL MACHINE FOR ARM64 (KVM/arm64)" , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE" , kernel-team@android.com, android-kvm@google.com, Quentin Perret Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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. 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 5168a0c516ae..cb104443d8e4 100644 --- a/arch/arm64/include/asm/kvm_mmu.h +++ b/arch/arm64/include/asm/kvm_mmu.h @@ -171,6 +171,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 c7f8fca97202..b1e1747e4bbf 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1318,16 +1318,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) -- 2.29.2.299.gdc1121823c-goog