From patchwork Tue Mar 22 18:35:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 12788936 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 984B4C433F5 for ; Tue, 22 Mar 2022 18:37:28 +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=73SJBr6hA2tdPmh0gHjsCrZoEJIkebV1Ucdgmv/BW88=; b=VdM5cZvho5mkenerI7OT4/r3R8 Hs5I2Bp6MzUtlUVpeni73Zv53s5X6LSqdG2F5MPsiqliaQ1vw1f6kUBaO7AH0Sk3KU8hGpiugVSZ/ mwQ4IrKWxo12++uocjDn/4MwMVVJlUfPwL/8fM3I9Kc5k7uuJWlhvYmo3lafy3TI4fQeh4iwF/F3f DO1Tk9NQG+ElVVisOGeLBl7Xi6LI26VZjxpxOzcPlhiasOYEi2a5jixW+WgNj36PFcwUPvoaRo3ue W705CMsW28mGKmiwzz1MYcz9+oJhco+S/Vd611IB7gzJ+SJ3XdAf+ldLyRmkSqaW9/udjx6TwlhTz UIRMbb5g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nWjMY-00Bsvf-VG; Tue, 22 Mar 2022 18:36:11 +0000 Received: from mail-il1-x14a.google.com ([2607:f8b0:4864:20::14a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nWjMC-00BsoU-0W for linux-arm-kernel@lists.infradead.org; Tue, 22 Mar 2022 18:35:49 +0000 Received: by mail-il1-x14a.google.com with SMTP id j12-20020a056e02154c00b002c81c9084b9so3834192ilu.22 for ; Tue, 22 Mar 2022 11:35:46 -0700 (PDT) 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=tnmr6FcY2JLhce32y9oAbKJR7f3jp9JaOpVAL3BoK3A=; b=GxSnt/O3uM4E7Ryuar3lRQb3ZogNtuTF21itlU478JfimK/CQKTWdC9abGJl5jGsFh vsCpeMIIxraZrqRAwjKKOTB0V//WU8dg4cRVKC5Q0oAggoKE61LbaN2rbGZvkGP8/uOI j74qp5vzLIA/wwHG8BgfrxsjGVbP6uB+Zf/aYbxfEVInJprXmyWl37BtVnmB2T3XX6u1 1rCCQ1bgNVvEq9m2lW4tSlCy3pGPNhFI7/hNOXDvATOYcr4EOtfhnIbMlmth4ZA3l6pq 8WyopLOxPV6FWc3VIk5u2CKXW37WMVKpQ+2nVJy6NA9Y65KSYa++PFSfzbm7x68qpJ47 G89g== 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=tnmr6FcY2JLhce32y9oAbKJR7f3jp9JaOpVAL3BoK3A=; b=3o/4ehdy0uEE1JpI/X0IkJbPykMAMhGBazrgM5XocKUhi+3FiohOwQ24c+XLHf+yhh 8Q+uJkaNpe5nC96l8Q7LcWkpWVq6QhhxKtgKMKueXfsgw6h5e8/qvo9xeIhjn7pRKpd7 cv/jWmVsF5nUat9aXWe1m8c86gKVRPyGkwbvkVpTCwOInAMaVbHK0HE3II4TqS4WbdfB tBsBhoLMn/vA5gDhv+1Ldu5VW1Tv3FvgjqV53gIYLqs1iGC00KqwZdmuQPzBZbU7V8Tg 5sIGg53+/N8TAkSJPMo9G16ZRJA1rP1LMQdbk3O2BYjSIv6Gai5mvNCbksrki861nx9G SrQA== X-Gm-Message-State: AOAM531FtmrAOjRwtwCCL1cWk7LTWGww/nJbflz5mSAoOhsJXaAFNwbD Fh0Lrehlcpl0JKKQIwXz4IDheVmmpvA= X-Google-Smtp-Source: ABdhPJyqOQMpygQKbMQI+YxY6NGJvNzmxA9fxDwQQ/eBULRiqPtajRMzQcxcfqJ1BaMG0pno7t9pgoH7orM= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a05:6638:3e13:b0:321:446d:2977 with SMTP id co19-20020a0566383e1300b00321446d2977mr5465994jab.178.1647974146089; Tue, 22 Mar 2022 11:35:46 -0700 (PDT) Date: Tue, 22 Mar 2022 18:35:37 +0000 In-Reply-To: <20220322183538.2757758-1-oupton@google.com> Message-Id: <20220322183538.2757758-3-oupton@google.com> Mime-Version: 1.0 References: <20220322183538.2757758-1-oupton@google.com> X-Mailer: git-send-email 2.35.1.894.gb6a874cedc-goog Subject: [PATCH v2 2/3] KVM: arm64: Actually prevent SMC64 SYSTEM_RESET2 from AArch32 From: Oliver Upton To: kvmarm@lists.cs.columbia.edu Cc: kvm@vger.kernel.org, Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , linux-arm-kernel@lists.infradead.org, Peter Shier , Ricardo Koller , Reiji Watanabe , Paolo Bonzini , Will Deacon , Oliver Upton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220322_113548_078406_80929597 X-CRM114-Status: GOOD ( 14.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 The SMCCC does not allow the SMC64 calling convention to be used from AArch32. While KVM checks to see if the calling convention is allowed in PSCI_1_0_FN_PSCI_FEATURES, it does not actually prevent calls to unadvertised PSCI v1.0+ functions. Hoist the check to see if the requested function is allowed into kvm_psci_call(), thereby preventing SMC64 calls from AArch32 for all PSCI versions. Fixes: d43583b890e7 ("KVM: arm64: Expose PSCI SYSTEM_RESET2 call to the guest") Acked-by: Will Deacon Reviewed-by: Reiji Watanabe Signed-off-by: Oliver Upton --- arch/arm64/kvm/psci.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kvm/psci.c b/arch/arm64/kvm/psci.c index cd3ee947485f..d24ccc77500b 100644 --- a/arch/arm64/kvm/psci.c +++ b/arch/arm64/kvm/psci.c @@ -232,10 +232,6 @@ static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu) unsigned long val; int ret = 1; - val = kvm_psci_check_allowed_function(vcpu, psci_fn); - if (val) - goto out; - switch (psci_fn) { case PSCI_0_2_FN_PSCI_VERSION: /* @@ -303,7 +299,6 @@ static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu) break; } -out: smccc_set_retval(vcpu, val, 0, 0, 0); return ret; } @@ -423,6 +418,15 @@ static int kvm_psci_0_1_call(struct kvm_vcpu *vcpu) */ int kvm_psci_call(struct kvm_vcpu *vcpu) { + u32 psci_fn = smccc_get_function(vcpu); + unsigned long val; + + val = kvm_psci_check_allowed_function(vcpu, psci_fn); + if (val) { + smccc_set_retval(vcpu, val, 0, 0, 0); + return 1; + } + switch (kvm_psci_version(vcpu)) { case KVM_ARM_PSCI_1_1: return kvm_psci_1_x_call(vcpu, 1);