From patchwork Fri Mar 11 04:48:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12777437 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 2EB33C433F5 for ; Fri, 11 Mar 2022 05:05:12 +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:References: Mime-Version:Message-Id: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=6fLTqFx2OS9gSfBK7fHZOl+w1i4i0XDieU9e6AfPXig=; b=MUX12B9PvV1n9SC+k+U1sj531K 2Yo7Xt25+gToaerU6PKrgJpoF9mQFu4JuTvukaCtCabP8bwFTBfcyg9bI5zcEc3IDMp0BorTrHqqP up3ptFSFBHkiHLHbFqUg/dfdnLl5VBU82F3hsGlhKgvES8e2Da3+SNtLEnOFtbKqBaHEVdtVmPH9v 46FdR5oxX/8FQUg6KUSFtY1MXmWEKQWUwpX8f3wKiFgYeqH5udxWg5n2CDOwTo0dQ2ebJaf39whL2 kp/ymRiwrE1fCjI8uou/As8zG/Jo8CjuqfjZKPZHC3b1WFgXwYg7tzVwMr+XzSDdEjGjdGg1jXH42 DVJ+didw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSXR4-00F5kF-4k; Fri, 11 Mar 2022 05:03:32 +0000 Received: from mail-pf1-x449.google.com ([2607:f8b0:4864:20::449]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSXDC-00EzsI-UN for linux-arm-kernel@lists.infradead.org; Fri, 11 Mar 2022 04:49:12 +0000 Received: by mail-pf1-x449.google.com with SMTP id w68-20020a62dd47000000b004f6aa5e4824so4533864pff.4 for ; Thu, 10 Mar 2022 20:49:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=7z5Uw2gRXSzvSWZCDvr7dARcE7XtDS3gb33aMNuIZp0=; b=LgvVZuqBFOS0jJKhiMC7n9409cSkdsgPrFen1ZDgAcy8XvbK5y7SuNyF2yj99Gs50X 8ctQndJnSgLFIAP995LFH9A9CyErl47PF5oJfFOu37jmWeQMiZlViWMsQEMouVLx2FId uw+L8ae+yJG3jRPydLz99/TREejGMtYarMr2/rXAq8Tn5lS+SPhVzfCJotveG3TIQZiQ DNxTGJan0vG2MDqBnZuRXt5+Wgx/DkcsUZfeBOe9WM466Bhc6ShUyRX9yyMHE0vpZlP+ hIit8D51RNTa1Bc+lf1P3YK4GXsm1D6MV0qYFKb+lJ2vdpvDXYmqaRka0xVr+4UriKpe d/7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=7z5Uw2gRXSzvSWZCDvr7dARcE7XtDS3gb33aMNuIZp0=; b=GBieFZLzGMVgzY247UNLuqGZlb2i22rOjab+BrzimNiVWJLEufEx3eKNFqFfex9hnE a/CgW4U9p/h+3re16PRDessvRr4I99zVnvz+ZnKwygD4nMbtf3xFWh7qDfKpF4qGAzR9 qJbdlWpYHFAoMG1shLPQXbuCihuHNCXYhkyXzwyGh8uyeewnxl/+BqOPkzQ28ir/sFIe WKVROjTgS4gJOGDXflsPJgTVHx3Sj+FTCyQ7OrX9ClVWW8AdNh9pM2JWPPO0oQfh+8/j D/E4TANL5LtukqFAkSZeBNQeaqrATgTuncBdx2T5Aq3HQCGfID2mzmXV9Rjv4XQqlOh8 zZwA== X-Gm-Message-State: AOAM5336EKzWyNxMr6w2QEtbSAcVlkeBUDaKyCUi8bz6KVs2DahedeZ5 BADdepvLSBmTmbLHxcKXedtB25JpUpM= X-Google-Smtp-Source: ABdhPJw61zM8eXq9A5LGOH7Lc1dcnB3i8F9/nsnO0WTPLudzhQ0Ew+bphYaAwCUfdiwvwCU4sgAbzOAPE+w= X-Received: from reiji-vws-sp.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3d59]) (user=reijiw job=sendgmr) by 2002:a05:6a00:228b:b0:4f7:9155:b685 with SMTP id f11-20020a056a00228b00b004f79155b685mr208604pfe.61.1646974149257; Thu, 10 Mar 2022 20:49:09 -0800 (PST) Date: Thu, 10 Mar 2022 20:48:09 -0800 In-Reply-To: <20220311044811.1980336-1-reijiw@google.com> Message-Id: <20220311044811.1980336-24-reijiw@google.com> Mime-Version: 1.0 References: <20220311044811.1980336-1-reijiw@google.com> X-Mailer: git-send-email 2.35.1.723.g4982287a31-goog Subject: [PATCH v6 23/25] KVM: arm64: Trap disabled features of ID_AA64ISAR1_EL1 From: Reiji Watanabe To: Marc Zyngier , kvmarm@lists.cs.columbia.edu Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, James Morse , Alexandru Elisei , Suzuki K Poulose , Paolo Bonzini , Will Deacon , Andrew Jones , Fuad Tabba , Peng Liang , Peter Shier , Ricardo Koller , Oliver Upton , Jing Zhang , Raghavendra Rao Anata , Reiji Watanabe X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220310_204911_044378_D780A08E X-CRM114-Status: GOOD ( 15.22 ) 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 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 --- arch/arm64/kvm/sys_regs.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index f3661881cbed..881e8879a48b 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -284,6 +284,30 @@ 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; + bool generic, address; + + if (!system_has_full_ptr_auth()) + /* The feature is not supported. */ + return false; + + val = read_id_reg_with_encoding(vcpu, SYS_ID_AA64ISAR1_EL1); + generic = aa64isar1_has_gpi(val) || aa64isar1_has_gpa(val); + address = aa64isar1_has_api(val) || aa64isar1_has_apa(val); + if (generic && address) + /* The feature is available. */ + return false; + + /* The feature is supported but hidden. */ + return true; +} + /* * Feature information to program configuration register to trap or disable * guest's using a feature when the feature is not exposed to the guest. @@ -379,6 +403,11 @@ static void feature_lor_trap_activate(struct kvm_vcpu *vcpu) feature_trap_activate(vcpu, VCPU_HCR_EL2, HCR_TLOR, 0); } +static void feature_ptrauth_trap_activate(struct kvm_vcpu *vcpu) +{ + feature_trap_activate(vcpu, VCPU_HCR_EL2, 0, HCR_API | HCR_APK); +} + /* For ID_AA64PFR0_EL1 */ static struct feature_config_ctrl ftr_ctrl_ras = { .ftr_reg = SYS_ID_AA64PFR0_EL1, @@ -447,6 +476,12 @@ static struct feature_config_ctrl ftr_ctrl_lor = { .trap_activate = feature_lor_trap_activate, }; +/* For SYS_ID_AA64ISAR1_EL1 */ +static struct feature_config_ctrl ftr_ctrl_ptrauth = { + .ftr_need_trap = vcpu_need_trap_ptrauth, + .trap_activate = feature_ptrauth_trap_activate, +}; + /* id_reg_desc flags field values */ #define ID_DESC_REG_UNALLOC (1UL << 0) #define ID_DESC_REG_HIDDEN (1UL << 1) @@ -3782,6 +3817,10 @@ static struct id_reg_desc id_aa64isar1_el1_desc = { .init = init_id_aa64isar1_el1_desc, .validate = validate_id_aa64isar1_el1, .vcpu_mask = vcpu_mask_id_aa64isar1_el1, + .trap_features = &(const struct feature_config_ctrl *[]) { + &ftr_ctrl_ptrauth, + NULL, + }, }; static struct id_reg_desc id_aa64mmfr0_el1_desc = {