Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp375672lqp; Mon, 10 Jun 2024 06:55:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV996crLHiNEtXHjaswKwn/rWgs0TYRsTZaFR/NuPKTHY2OvLRHzXwCkrHQ3q/qTn040Nus7xXBYMRioPIh2S5BlyVIkvjwi7otP7hehQ== X-Google-Smtp-Source: AGHT+IEGpxtvPkOwI0f5F22yFtYFYMYe8ve4Zg93wt6p7agQs60kF9vMBLxrqIBF1D7uSzo9W4MS X-Received: by 2002:a05:6214:5884:b0:6ab:7067:6f6d with SMTP id 6a1803df08f44-6b059f948d2mr88833446d6.56.1718027751076; Mon, 10 Jun 2024 06:55:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718027751; cv=pass; d=google.com; s=arc-20160816; b=QUoWYwvduHXv7pjyq2/z3QB9i2Gg2gh8Pxvutaxn8t1IyKyuipkVxZivSInZriZvXX oSxq6XkvBcQIVhBR00VE4KaVe/MluV7aT9cmSXE6HdF3Hek/O5nFx4ocVuIFb+7DS2FN 5oRpgmH8+R5siOTbYlfk4LDiHkAu6rCJn16Uynftf8yM5BNsuiQzoLx2fvy5GDDVUvSi 90yfDrpRHvLbCHxEsS2ypOcmev9aMWEtcX3dOyoteSbL1o2C1Ev/xvMemOGOgRUCXx/0 7weYiVImjsjCEbjZBxaNwFxgtUZ2FNbF0XrV1mtJNTQ32xaHDCJ9h73AR8YUBXtDnHWO +1BA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=D6tMACXI0z0uJRgeYTeCW8hEHYTIw4coe6RCL1xa8js=; fh=9LvSfW0WHt2iGJzVq6ancEjPK6P/LWkxdE9eAG2qWdE=; b=YvEk3N8tKUjPLovHlMWYMCQ4E1bS3KmJXkj1OjJaAzf4kkw0wZsEVu/MAvE46sNT/Z bW6UMob6tHRAsfrMQersQMI7SOGqlhOuy06AhbjlBSiDJV/6rXo/YviUo8Q2ZLLIfFyj ySO2JL5CSeXkv48Zseb3cNBoispuCKfekgmsR5avkaverCpYHNdb6j5sQz2xTe1vExKc jfn8SEIeSUlX4bJ/pl0qnjg9t3QPRvVZmtv4i7giEQMBadAebkAoJmI0lsSvWKOMDlIm EtIbAA9OoeehWbwnskUMylPC2Cjq38KBQR+Q2I2RQzT7mnX571WKIIsr4jdJBeKT2JAt uqvg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-208289-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208289-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 6a1803df08f44-6b06c7ed67esi56822966d6.309.2024.06.10.06.55.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 06:55:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208289-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-208289-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208289-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id CA3631C2218C for ; Mon, 10 Jun 2024 13:55:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DE4D9158D61; Mon, 10 Jun 2024 13:44:28 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3087386255; Mon, 10 Jun 2024 13:44:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718027068; cv=none; b=KxnUkmYCntWVEHus3hPiPuAajnbbZ0KsHgM5Jkt/ZK0dfLWXi7cLXpw581n6xrbkPwzdBhz3CeS0pWJts58WyL0Wqoa4Fq4Tz5LZ5HIo9MTI1kdvxWG/oRgV/9g6wIUiayT1/13VIsEHOVVG9S7RSSnCwyn3sHjZ5BR9G1IW9BI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718027068; c=relaxed/simple; bh=PXzB2CfFVPOkpm1ENsA7+9DLxxEPtB8SHxv47VUK+j0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NFpTLgkuJHyjmfmCK9VDzdttnsetv9q+YuTTO6n0GCpNfwnY1nZVWCJ9D0OmrnOo4yTZbcukza5vhIaVSl8KG4GumTe4uZpyrW8DNqYtRNod4t5z3U+wcDwyXIHmVrvAcf564wVfxA2OuuaFREK099OO1zb8Bu/M/q+cvdp65W4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 32AD812FC; Mon, 10 Jun 2024 06:44:50 -0700 (PDT) Received: from e122027.cambridge.arm.com (e122027.cambridge.arm.com [10.1.35.41]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BE77E3F58B; Mon, 10 Jun 2024 06:44:22 -0700 (PDT) From: Steven Price To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: Jean-Philippe Brucker , Catalin Marinas , Marc Zyngier , Will Deacon , James Morse , Oliver Upton , Suzuki K Poulose , Zenghui Yu , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Joey Gouly , Alexandru Elisei , Christoffer Dall , Fuad Tabba , linux-coco@lists.linux.dev, Ganapatrao Kulkarni , Steven Price Subject: [PATCH v3 40/43] arm64: RME: Provide register list for unfinalized RME RECs Date: Mon, 10 Jun 2024 14:41:59 +0100 Message-Id: <20240610134202.54893-41-steven.price@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240610134202.54893-1-steven.price@arm.com> References: <20240610134202.54893-1-steven.price@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Jean-Philippe Brucker KVM_GET_REG_LIST should not be called before SVE is finalized. The ioctl handler currently returns -EPERM in this case. But because it uses kvm_arm_vcpu_is_finalized(), it now also rejects the call for unfinalized REC even though finalizing the REC can only be done late, after Realm descriptor creation. Move the check to copy_sve_reg_indices(). One adverse side effect of this change is that a KVM_GET_REG_LIST call that only probes for the array size will now succeed even if SVE is not finalized, but that seems harmless since the following KVM_GET_REG_LIST with the full array will fail. Signed-off-by: Jean-Philippe Brucker Signed-off-by: Steven Price --- arch/arm64/kvm/arm.c | 4 ---- arch/arm64/kvm/guest.c | 9 +++------ 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index b04f08e242a6..19b04299d1b2 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1805,10 +1805,6 @@ long kvm_arch_vcpu_ioctl(struct file *filp, if (unlikely(!kvm_vcpu_initialized(vcpu))) break; - r = -EPERM; - if (!kvm_arm_vcpu_is_finalized(vcpu)) - break; - r = -EFAULT; if (copy_from_user(®_list, user_list, sizeof(reg_list))) break; diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c index e3366c9bdd9d..6299561da46d 100644 --- a/arch/arm64/kvm/guest.c +++ b/arch/arm64/kvm/guest.c @@ -652,12 +652,9 @@ static unsigned long num_sve_regs(const struct kvm_vcpu *vcpu) { const unsigned int slices = vcpu_sve_slices(vcpu); - if (!vcpu_has_sve(vcpu)) + if (!vcpu_has_sve(vcpu) || !kvm_arm_vcpu_sve_finalized(vcpu)) return 0; - /* Policed by KVM_GET_REG_LIST: */ - WARN_ON(!kvm_arm_vcpu_sve_finalized(vcpu)); - return slices * (SVE_NUM_PREGS + SVE_NUM_ZREGS + 1 /* FFR */) + 1; /* KVM_REG_ARM64_SVE_VLS */ } @@ -673,8 +670,8 @@ static int copy_sve_reg_indices(const struct kvm_vcpu *vcpu, if (!vcpu_has_sve(vcpu)) return 0; - /* Policed by KVM_GET_REG_LIST: */ - WARN_ON(!kvm_arm_vcpu_sve_finalized(vcpu)); + if (!kvm_arm_vcpu_sve_finalized(vcpu)) + return -EPERM; /* * Enumerate this first, so that userspace can save/restore in -- 2.34.1