@@ -281,6 +281,35 @@ static bool trap_raz_wi(struct kvm_vcpu *vcpu,
(cpuid_feature_extract_unsigned_field(val, ID_AA64ISAR1_GPI_SHIFT) >= \
ID_AA64ISAR1_GPI_IMP_DEF)
+/*
+ * Return true if ptrauth needs to be trapped.
+ * (i.e. if ptrauth is supported on the host but not exposed to the guest)
+ */
+static bool vcpu_need_trap_ptrauth(struct kvm_vcpu *vcpu)
+{
+ u64 val;
+ unsigned int gpi, gpa, api, apa;
+ unsigned int generic, address;
+
+ if (!system_has_full_ptr_auth())
+ /* The feature is not supported. */
+ return false;
+
+ val = __vcpu_sys_reg(vcpu, IDREG_SYS_IDX(SYS_ID_AA64ISAR1_EL1));
+ gpi = aa64isar1_has_gpi(val);
+ gpa = aa64isar1_has_gpa(val);
+ api = aa64isar1_has_api(val);
+ apa = aa64isar1_has_apa(val);
+ generic = gpi || gpa;
+ address = api || apa;
+ if (generic && address)
+ /* The feature is available. */
+ return false;
+
+ /* The feature is supported but hidden. */
+ return true;
+}
+
enum vcpu_config_reg {
VCPU_HCR_EL2 = 1,
VCPU_MDCR_EL2,
@@ -385,6 +414,14 @@ static struct feature_config_ctrl ftr_ctrl_lor = {
.cfg_val = HCR_TLOR,
};
+/* For SYS_ID_AA64ISAR1_EL1 */
+static struct feature_config_ctrl ftr_ctrl_ptrauth = {
+ .ftr_need_trap = vcpu_need_trap_ptrauth,
+ .cfg_reg = VCPU_HCR_EL2,
+ .cfg_mask = (HCR_API | HCR_APK),
+ .cfg_val = 0,
+};
+
struct id_reg_info {
u32 sys_reg; /* Register ID */
u64 sys_val; /* Sanitized system value */
@@ -763,6 +800,10 @@ static struct id_reg_info id_aa64isar1_el1_info = {
.init = init_id_aa64isar1_el1_info,
.validate = validate_id_aa64isar1_el1,
.get_reset_val = get_reset_id_aa64isar1_el1,
+ .trap_features = &(const struct feature_config_ctrl *[]) {
+ &ftr_ctrl_ptrauth,
+ NULL,
+ },
};
static struct id_reg_info id_aa64dfr0_el1_info = {
Add feature_config_ctrl for PTRAUTH, which is indicated in ID_AA64ISAR1_EL1, to program configuration register to trap guest's using the feature when it is not exposed to the guest. Signed-off-by: Reiji Watanabe <reijiw@google.com> --- arch/arm64/kvm/sys_regs.c | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)