From patchwork Thu Dec 14 10:01: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: 13492687 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 7B43BC4332F for ; Thu, 14 Dec 2023 10:02:54 +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=TC0qAE2I3kPFH6CJfhTzlheqnSICUssSNLzmpFxbR70=; b=Knk7EIUNoBRGtnvQgfhDeW0twn 8M0psn3njfNC2Yf6wg8EJyBBn9Ib4134I3TiXrbCVTJXpVhuPTN7WwQL40J0XmOZ/UOcuJs1D0GzJ /TrvW38d9eD78xE/JexrlgkX0STIg+WsF7Ll/mEe18RBy63Uh1xmwjhe1ajA+JzAgJiszdqZNlrrM RGy8E12yqprBnx8tdv/BKFkRFfftkIcfpOzdqXTZ6leIujMCjHsQDke4ZbSSVLab/4QELX0uRARJO uELUEUvQVdF/o6MBsDooouLUb0uevXoGMlAh3LCB/m1DtlJJFuQXI+pWiFEqaXL4dHKD+6jrwlA5U xy2VFAOQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rDiXy-00HOwx-1I; Thu, 14 Dec 2023 10:02:26 +0000 Received: from mail-wr1-x449.google.com ([2a00:1450:4864:20::449]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rDiXl-00HOro-2r for linux-arm-kernel@lists.infradead.org; Thu, 14 Dec 2023 10:02:15 +0000 Received: by mail-wr1-x449.google.com with SMTP id ffacd0b85a97d-3334e56554bso7128550f8f.0 for ; Thu, 14 Dec 2023 02:02:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702548131; x=1703152931; 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=iO5cgv8s1+7lRn9EEBAbuMss8Z8UN6A/g0VvwzwiLdY=; b=N5CaZRdoklfRqZboC3TyWpylDEp9YoUVFF5RVymg1sHbtUMrsthfu4NfAIZ/PY8aqd YsTELmpO3j4NDN4ugJMzsHX1raichrLFVXs5aI3VyY9riFeb/2UOCpqfEFUREnvjl45D Iwb1w7IWsXz0kozVEiTl0l99qZB9Qmvga4tYytJkDovRyP2tNA6YA7gveZ+Cz4d8zvYa Tnm2Oz1fspPLJf8xoMmhJtximm1yxK17ckwTGoPgCfRKg2fktCWmxSkwi3KmBKG8WF66 zphlOhmwLsCKizJTnbSMXV0kSfqCfr9V7ES2PmSqxVjmoT3ugpR2MHglNXXPipEPfUek AkQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702548131; x=1703152931; 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=iO5cgv8s1+7lRn9EEBAbuMss8Z8UN6A/g0VvwzwiLdY=; b=VWWuvYYb/sDeGQYqq2KowQPJ/5TEqE9S1+MEZWhJoBCqV/WRDgOWIvkjGnhNcut1Jr SPlQZcvIaPoRW0Rdx0C4k2OaBr2ThAEPEo2eaqRlWLirUJJvu7hAEYGAENzgwh144O7M ZvejjywporHcGScXOI8jQ+9IaTgerz6eraAlVlPVsX2bzozLbsQmOhW7BcXNFhmQRvGX cDtBcwf0gthJYi6W2tgVp//uCPlmwnZRMMglEur48vX9NWz2ceyhPQRLgzwZlP1AgL1b 3VujIHKX2Pv74p2J3D+RqxJC/gIKPJFTqtzXiiEw/jVENanoKe3BdOzcEouW89o6GIif wOlQ== X-Gm-Message-State: AOJu0YwFcE008Z9XeCNk/7j3NzdQW3dpareQ7j0YI6t7ATGc1dJzjgA6 buhHCiFcLM6Lumxs78v6OzHSyah26Q== X-Google-Smtp-Source: AGHT+IEKuhuE+8t070Z74NIEk6C7Bliycci+lz+5qRu4aMv9bjpk2q4FwL5YoB+4kB4l2qUOVyCBpGx6TQ== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a5d:4b06:0:b0:336:4a97:9f70 with SMTP id v6-20020a5d4b06000000b003364a979f70mr1368wrq.5.1702548131670; Thu, 14 Dec 2023 02:02:11 -0800 (PST) Date: Thu, 14 Dec 2023 10:01:45 +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-6-tabba@google.com> Subject: [PATCH v3 05/17] KVM: arm64: Explicitly trap unsupported HFGxTR_EL2 features 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_020213_922675_A33EE7CB X-CRM114-Status: GOOD ( 11.21 ) 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 Do not rely on the value of __HFGRTR_EL2_nMASK to trap unsupported features, since the nMASK can (and will) change as new traps are added and as its value is updated. Instead, explicitly specify the trap bits. Suggested-by: Joey Gouly Signed-off-by: Fuad Tabba --- arch/arm64/kvm/hyp/include/hyp/switch.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h index f99d8af0b9af..7b4909dfd1f5 100644 --- a/arch/arm64/kvm/hyp/include/hyp/switch.h +++ b/arch/arm64/kvm/hyp/include/hyp/switch.h @@ -110,12 +110,15 @@ static inline void __activate_traps_hfgxtr(struct kvm_vcpu *vcpu) compute_clr_set(vcpu, HFGWTR_EL2, w_clr, w_set); } - /* The default is not to trap anything but ACCDATA_EL1 */ - r_val = __HFGRTR_EL2_nMASK & ~HFGxTR_EL2_nACCDATA_EL1; + /* The default to trap everything not handled or supported in KVM. */ + tmp = HFGxTR_EL2_nAMAIR2_EL1 | HFGxTR_EL2_nMAIR2_EL1 | HFGxTR_EL2_nS2POR_EL1 | + HFGxTR_EL2_nPOR_EL1 | HFGxTR_EL2_nPOR_EL0 | HFGxTR_EL2_nACCDATA_EL1; + + r_val = __HFGRTR_EL2_nMASK & ~tmp; r_val |= r_set; r_val &= ~r_clr; - w_val = __HFGWTR_EL2_nMASK & ~HFGxTR_EL2_nACCDATA_EL1; + w_val = __HFGWTR_EL2_nMASK & ~tmp; w_val |= w_set; w_val &= ~w_clr;