From patchwork Thu Dec 14 10:01:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13492821 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 718E1C4167B for ; Thu, 14 Dec 2023 11:17:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version: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=Recbsr6tnh++Mv/OoSsoLts1WmSHU+haFdDps7/2ks4=; b=lducNzUXxaTGn2eCgjD44PU9r1 SzqJKrsRx8lozRQmANtPBduaBc4FdqymSyDLZeoJacbc+JiLuMaT5GksLg/A110/iGSXLndTiBypo b6FDHN6Mm+HCgnF3VTEuFk9pG3HWBronqQKKSSpoSOl71QfnjDZba7u9nZGtItZbCnTnvYv4D4p9T kiOljrKFCfDjKICApE0EyYck+7EBZqLit2XL6gHKB6uvMB5UDGhyb9XuVFHOO2Pa4cokwhxYjuK7S dNKenwV2cKuVNtKVqO3Xteb9qpyQaEo+SiI2ORs1x3cOa2Gxgb+2qjxY4XiKMAmJ6yvwPuzpX12KI NkJvt8UQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rDjhl-0000PY-20; Thu, 14 Dec 2023 11:16:37 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rDiY5-00HP1W-0t for linux-arm-kernel@lists.infradead.org; Thu, 14 Dec 2023 10:02:34 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-dbcda1ff95bso1291352276.3 for ; Thu, 14 Dec 2023 02:02:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702548152; x=1703152952; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=BZpm5g8sXqlgN71zqSoD3PYKLpgzzVAPPBQdv9SzS9U=; b=CPDvaLS8OmFBEYW5Yg6ZQnWOHqTYDViBZL3zXkMN/b4dem3IdMLGAkKnw35emwl9WU 8t3t15jPeaOfliXP5v9bzzJb/sZUQ4GiUJ72iCriq9xRocMpPUbeK4AblgIBaMlHevhy KfU95opCkcBNDE8fmQtXZtI67rzducGqGbgU+es1gdxXOKALZIa5djjXGo8t1Rcz0Bz8 d6yrPeLvyF6jb3UdtCLiWQl0/yxRCwdDCPjUR4CIrXimyX1XsgZiJk0QtcM3EY6nUORE g9ZAun8YEEkw2njcTkyjX9OP6AQJ6a1ZxYySAK/GjPD4no8mvvwi2StDiOqpMhrcNbPs lmgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702548152; x=1703152952; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BZpm5g8sXqlgN71zqSoD3PYKLpgzzVAPPBQdv9SzS9U=; b=PkSQlBn1otS/TgYdEu9SfDs5yiCjpAc90xVIJkAl2d98/0SoSg2y9YPp5lc0bI33iS RrIgcBF/PVrWCLwUzhzKKDbI2I23r1e5QFOW9zcho9H7Toik+G8wW7Cy7ZonDgvlKYFX RVJJ/hIVQsUK2dOTs9lc5nLBUex094Xpgts6+7ef0A+vlfXBhpgfMjPSfhvqS0IsMqFr CI8422G7QxFJOtBob2Cuo7s4eTreLy49eXN5ALkqi+Z0RE6445i6Om33v8hbCyalMjsO ccvT/70FsqNBGiOrmchVwz0P0D9EV18rNjalBXJFMHMFa/zffz/79pVcNN4s/6jE0sga oTnQ== X-Gm-Message-State: AOJu0YzZwuMLv88ZOuESD3gg/6HAa/aO6RseSGRimUPYfoiUDW1+9PRR dMY0qBu6z7t1c2EsCRetJ3lp+fMbhA== X-Google-Smtp-Source: AGHT+IF6Akn1Pi5DCUhyiJjAZLduSqaHqIoZSn6di1DIm8HQc07sCgOSlwvtGjmu28U/J1q4cm0p0M6luQ== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a05:6902:150:b0:da0:3da9:ce08 with SMTP id p16-20020a056902015000b00da03da9ce08mr109580ybh.10.1702548151743; Thu, 14 Dec 2023 02:02:31 -0800 (PST) Date: Thu, 14 Dec 2023 10:01:54 +0000 In-Reply-To: <20231214100158.2305400-1-tabba@google.com> Mime-Version: 1.0 References: <20231214100158.2305400-1-tabba@google.com> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Message-ID: <20231214100158.2305400-15-tabba@google.com> Subject: [PATCH v3 14/17] KVM: arm64: Macros for setting/clearing FGT bits From: Fuad Tabba To: kvmarm@lists.linux.dev Cc: maz@kernel.org, oliver.upton@linux.dev, broonie@kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, eric.auger@redhat.com, jingzhangos@google.com, joey.gouly@arm.com, tabba@google.com, linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231214_020233_324994_EE467EBD X-CRM114-Status: GOOD ( 11.78 ) 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 There's a lot of boilerplate code for setting and clearing FGT bits when activating guest traps. Refactor it into macros. These macros will also be used in future patch series. No functional change intended. Signed-off-by: Fuad Tabba --- arch/arm64/kvm/hyp/include/hyp/switch.h | 60 +++++++++---------------- 1 file changed, 21 insertions(+), 39 deletions(-) diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h index 17ce40f5b006..e223fc0d5193 100644 --- a/arch/arm64/kvm/hyp/include/hyp/switch.h +++ b/arch/arm64/kvm/hyp/include/hyp/switch.h @@ -79,6 +79,23 @@ static inline void __activate_traps_fpsimd32(struct kvm_vcpu *vcpu) clr |= ~hfg & __ ## reg ## _nMASK; \ } while(0) +#define update_fgt_traps_cs(reg, clr, set) \ + do { \ + struct kvm_cpu_context *hctxt = \ + &this_cpu_ptr(&kvm_host_data)->host_ctxt; \ + u64 val, c = 0, s = 0; \ + \ + ctxt_sys_reg(hctxt, reg) = read_sysreg_s(SYS_ ## reg); \ + compute_clr_set(vcpu, reg, c, s); \ + val = __ ## reg ## _nMASK; \ + val |= (s | set); \ + val &= ~(c | clr); \ + write_sysreg_s(val, SYS_ ## reg); \ + } while(0) + +#define update_fgt_traps(reg) \ + update_fgt_traps_cs(reg, 0, 0) + /* * Validate the fine grain trap masks. * Check that the masks do not overlap and that all bits are accounted for. @@ -146,45 +163,10 @@ static inline void __activate_traps_hfgxtr(struct kvm_vcpu *vcpu) if (!vcpu_has_nv(vcpu) || is_hyp_ctxt(vcpu)) return; - ctxt_sys_reg(hctxt, HFGITR_EL2) = read_sysreg_s(SYS_HFGITR_EL2); - - r_set = r_clr = 0; - compute_clr_set(vcpu, HFGITR_EL2, r_clr, r_set); - r_val = __HFGITR_EL2_nMASK; - r_val |= r_set; - r_val &= ~r_clr; - - write_sysreg_s(r_val, SYS_HFGITR_EL2); - - ctxt_sys_reg(hctxt, HDFGRTR_EL2) = read_sysreg_s(SYS_HDFGRTR_EL2); - ctxt_sys_reg(hctxt, HDFGWTR_EL2) = read_sysreg_s(SYS_HDFGWTR_EL2); - - r_clr = r_set = w_clr = w_set = 0; - - compute_clr_set(vcpu, HDFGRTR_EL2, r_clr, r_set); - compute_clr_set(vcpu, HDFGWTR_EL2, w_clr, w_set); - - r_val = __HDFGRTR_EL2_nMASK; - r_val |= r_set; - r_val &= ~r_clr; - - w_val = __HDFGWTR_EL2_nMASK; - w_val |= w_set; - w_val &= ~w_clr; - - write_sysreg_s(r_val, SYS_HDFGRTR_EL2); - write_sysreg_s(w_val, SYS_HDFGWTR_EL2); - - ctxt_sys_reg(hctxt, HAFGRTR_EL2) = read_sysreg_s(SYS_HAFGRTR_EL2); - - r_clr = r_set = 0; - compute_clr_set(vcpu, HAFGRTR_EL2, r_clr, r_set); - - r_val = __HAFGRTR_EL2_nMASK; - r_val |= r_set; - r_val &= ~r_clr; - - write_sysreg_s(r_val, SYS_HAFGRTR_EL2); + update_fgt_traps(HFGITR_EL2); + update_fgt_traps(HDFGRTR_EL2); + update_fgt_traps(HDFGWTR_EL2); + update_fgt_traps(HAFGRTR_EL2); } static inline void __deactivate_traps_hfgxtr(struct kvm_vcpu *vcpu)