From patchwork Tue Dec 5 10:22:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13479887 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 BE7F4C4167B for ; Tue, 5 Dec 2023 10:23:35 +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=Ul39JhgXxizsu7B/yE3XbvpdB5sIVVqwsXHt16PNcNs=; b=ETZOG0HsDad2SkPjFMLyQUJG5o nx5B3XRScYJStOcemEjqRvEzgcQyFRQk0T5YgQDjTwADyz9vBuSXkCqxZmJ5bZoYqykZqueiUzp9k /SjFB9r5jza1bg/+R/NufVVrbCuMJz1yw7oro/D38yJEn0+KEQHF3ADO6Oe2Do6jY+EqW5+XaSZdY diYlur2/N/2Zfmf4H2rDk1NxtbfkEg3OlOMqwtbA1Slg3rkQnYueng+TEis2dPaN+VAikWbJciREV WhI220WNDhaT5NOPXu96PAXmoJM8C+cRjxkPF6tqNHe9jI2fwKGqRLv6nimOEjuz5ilN9rbr2k3lO 1xxl+A7Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rASa1-006xTp-0X; Tue, 05 Dec 2023 10:23:05 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rASZw-006xPa-2c for linux-arm-kernel@lists.infradead.org; Tue, 05 Dec 2023 10:23:02 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5d12853cb89so81221177b3.3 for ; Tue, 05 Dec 2023 02:22:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701771778; x=1702376578; 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=6/1/nR/wPZ7NA+ogBhISAqTkBseTGBaMyb03BUPjq4U=; b=cYqN2eA1miqYuCqSMKW1sdTr4WlZEk0w9Tie0aozVhkASe8BX1Y5EkrxcLswO5cMT8 ZKTYBp7+IVIz+QuzfyMYsvX/kFDI7CiY7n+Q0j4WxS8qIEwsarCFxRH1rlewHffKjwr3 5L5rfZq9oVwH5nD82gr/82YzJzlbCPZNB75QUaYQgsjsLapHER1onDhSCIaVKm1fP3Fr zUV7Bct05d6XgAY49QoGSERw9+khsWZgEd1ttSnaEdYtUzaE3Pass44dyoe6ce2W67z5 pxsOdLp5l8uf4mXjy5KIInJADy5nNsZhxuEzDa4CDOpju1hYYR5Q2Z30g13LiVDO+sH/ vV5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701771778; x=1702376578; 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=6/1/nR/wPZ7NA+ogBhISAqTkBseTGBaMyb03BUPjq4U=; b=rpE5CV1Io033pHGB5x7y/rCWbKLoN2QWXOYcArKuF6OTIDETl9Cspf/Pf2RA1luve3 72M3GF9MXEr4w/Utkohs4xupwIjN0BDgXPugWJ0wQ0LOP4TW/8owpzR3ju1udzObv2v6 4W4SBfx4gVCrr/An5JVjvZM5SyB6TiWxMns/GbZuDwfhL/zCh25GG/yu3eU0UFO6py5k FDfiHVSjLPBFcZ3AJUgw9ip1udSzz9xHcQrm5QXzkIMvGht3iIi7pHrsKHRb9whWDa7G qcGDG2CIq182PogM7+aUHbcjW1ubd3Xscj7EFcYjL56tVJzNzAsH+GssgdO2DoHzw53l GgRg== X-Gm-Message-State: AOJu0Yxc5jyZddQgqKBCpGq1KTJO2MB26naeoQo+dluAoi1tolljgzWQ K+h5vAwQPLZS6O8gwOS1ThJd8HlkEw== X-Google-Smtp-Source: AGHT+IFx6QtlZCISWo5zQurlwbwfl/q4BA+QdlQsjnDHwvFwpmn/4q0wJ5or16gDPeh6bB5cpSUmEIAy6A== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a81:d444:0:b0:5d2:913a:6421 with SMTP id g4-20020a81d444000000b005d2913a6421mr552135ywl.8.1701771777402; Tue, 05 Dec 2023 02:22:57 -0800 (PST) Date: Tue, 5 Dec 2023 10:22:45 +0000 In-Reply-To: <20231205102248.1915895-1-tabba@google.com> Mime-Version: 1.0 References: <20231205102248.1915895-1-tabba@google.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog Message-ID: <20231205102248.1915895-4-tabba@google.com> Subject: [PATCH v1 3/6] KVM: arm64: Add build validation for trap mask values From: Fuad Tabba To: kvmarm@lists.linux.dev Cc: maz@kernel.org, oliver.upton@linux.dev, 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-20231205_022300_846672_1D8020DD X-CRM114-Status: GOOD ( 10.09 ) 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 These checks help ensure that all the bits are accounted for, and that there hasn't been a transcribing error from the spec. Signed-off-by: Fuad Tabba --- arch/arm64/kvm/hyp/include/hyp/switch.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h index f99d8af0b9af..2c6e8cbbd081 100644 --- a/arch/arm64/kvm/hyp/include/hyp/switch.h +++ b/arch/arm64/kvm/hyp/include/hyp/switch.h @@ -79,6 +79,16 @@ static inline void __activate_traps_fpsimd32(struct kvm_vcpu *vcpu) clr |= ~hfg & __ ## reg ## _nMASK; \ } while(0) +/* + * Validate the fine grain trap masks. + * Check that the masks do not overlap and that all bits are accounted for. + */ +#define CHECK_FGT_MASKS(reg) \ + do { \ + BUILD_BUG_ON((__ ## reg ## _MASK) & (__ ## reg ## _nMASK)); \ + BUILD_BUG_ON(~((__ ## reg ## _RES0) ^ (__ ## reg ## _MASK) ^ \ + (__ ## reg ## _nMASK))); \ + } while(0) static inline void __activate_traps_hfgxtr(struct kvm_vcpu *vcpu) { @@ -86,6 +96,14 @@ static inline void __activate_traps_hfgxtr(struct kvm_vcpu *vcpu) u64 r_clr = 0, w_clr = 0, r_set = 0, w_set = 0, tmp; u64 r_val, w_val; + CHECK_FGT_MASKS(HFGRTR_EL2); + CHECK_FGT_MASKS(HFGWTR_EL2); + CHECK_FGT_MASKS(HFGITR_EL2); + CHECK_FGT_MASKS(HDFGRTR_EL2); + CHECK_FGT_MASKS(HDFGWTR_EL2); + CHECK_FGT_MASKS(HAFGRTR_EL2); + CHECK_FGT_MASKS(HCRX_EL2); + if (!cpus_have_final_cap(ARM64_HAS_FGT)) return;