Received: by 2002:ab2:7041:0:b0:1f4:bcc8:f211 with SMTP id x1csp14995lql; Fri, 12 Apr 2024 02:01:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU9gP6ONI7VQlfK6W/qxKD/NJP11+Z06L5ckorETrfpf3N29l48rQ2tKqWSoaNw7k6IssWpn4RAa9wZkDpBUWvaos+d5ozf2XnO8KPEQQ== X-Google-Smtp-Source: AGHT+IHEqkTEAbD2Q9fWqDT/5u/PAkLgCSo/ZJZLvEaa6A0esz3w1xzS/eaoTLAcLfpbD9h29V6V X-Received: by 2002:a05:6122:a22:b0:4d8:7ae2:107 with SMTP id 34-20020a0561220a2200b004d87ae20107mr2167945vkn.10.1712912461917; Fri, 12 Apr 2024 02:01:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712912461; cv=pass; d=google.com; s=arc-20160816; b=Muxmh/Rr9jQFNUJyuhEnCICyWxWjkHMsb8+2FjC50zWY6PjJl3oNSrsBpCh8iMouDL 1rDBDzQmWvM8exHiUB0FOSJlUFLpUaxsEj+vcXd5zDkHblasZ+FX2p5Y46vl4JL9IADb NEFpQxpvSxpI8FOZqOFXiaiNzwgFN35ACI2Qomuxc2IHCOv39rQcJF30x5zLTA5nvjd0 VBqaQG/hhKwsQBBK4AMPPVkx6TvcOrPr7IsJuGk1W5HGJnHNeFPe3eWHDcGva1fIcl1d 0HZnOtD1DX1kcYOMCgl1+ElO1uTkZBzjcY2TUgnTAJGxA5vHNPdZAOxZGsbUPpV79Cj5 Di+A== 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=Y3BR8aYOXUHoMmkW/9ASr03R4bE9ahDnJ/5HnKz60dM=; fh=9LvSfW0WHt2iGJzVq6ancEjPK6P/LWkxdE9eAG2qWdE=; b=r9recgC2pnnVgKz7NzfrFDa8z8TRiH7v5Ovw3QCx7qh446gpleLxJNnGSVfS0UCY4I /8QEV574UJoVtFzpOpX9pdwRW51bRM/FDTDkiyOqOeQhSWYS4e/sVY/NGTpHwErm0Cyr ZSCewqwVi0YW10ppoxmLKZvLXP5Ppwv1G2aZYQ6L9EhKC4YM5cCVdpPFDzYO0uVmwviS ldf8yBOvU/wdDqGzlBsxLoZDxdXTKTa0j2ytLJqY5cxNwYOyWAGl34++rT1/RhwCu6PF 2OqTShY/6oseVhzM3Llzn6pmJXtRB7wHltiKKArpFj8eldgU/cj6qwamZMAEY5M9R1KN zTPQ==; 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-142313-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142313-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. [147.75.199.223]) by mx.google.com with ESMTPS id v21-20020a056102227500b004786f9ebd31si463701vsd.200.2024.04.12.02.01.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 02:01:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142313-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; 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-142313-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142313-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 C07401C22672 for ; Fri, 12 Apr 2024 09:00:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4CAD7134CF7; Fri, 12 Apr 2024 08:44:55 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 990BA13443C; Fri, 12 Apr 2024 08:44:53 +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=1712911494; cv=none; b=cA1VgErghps4CZxoa6foxVEV5xkiI7oMgdrFLz4bPEJ/BKXsshg3unyM10ORC7PruL2lwAUkNx+ptE692xFmpOHT2948ZhUMm6/gecieF50SRvP0d7Jotl6b4SuDZpK6l4uYHMllWrU24+Sm5VsFVzkuOtn43PRlvWtpzdyUbTU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712911494; c=relaxed/simple; bh=7rI3Cv8jIpbvflmCs0EL317NA4f18q7OkdVv2AgbcTQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nFvPSR8ZXywqNYkexl3hSXN2WXKiUpHoR4Xq5A2AJstp5eUmi8OIfQtKhpMg9ENoo/qtqDt726at4FxK8GlhTE+4ZXon/Dh1vN0qSdHzwu/xl2NPCLVxyC0mwAAELkGXItYZlb/UgLnePMThlA9qO4oGLw1aUp7yjNDYL7gk+Go= 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 848A3113E; Fri, 12 Apr 2024 01:45:22 -0700 (PDT) Received: from e112269-lin.cambridge.arm.com (e112269-lin.cambridge.arm.com [10.1.194.51]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0EC043F6C4; Fri, 12 Apr 2024 01:44:50 -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 v2 40/43] arm64: RME: Provide register list for unfinalized RME RECs Date: Fri, 12 Apr 2024 09:43:06 +0100 Message-Id: <20240412084309.1733783-41-steven.price@arm.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240412084309.1733783-1-steven.price@arm.com> References: <20240412084056.1733704-1-steven.price@arm.com> <20240412084309.1733783-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 69d29797c2ed..2dd014d3c366 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1696,10 +1696,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 d72e59e79185..f1fe51775649 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