From nobody Fri Oct 3 23:11:38 2025 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A1C62EA739 for ; Sat, 23 Aug 2025 16:00:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755964828; cv=none; b=nsLK8Jf5CxB4TOFtHTy8GBUdpZIpZgc65T6gUXdtJ19FKHMSKrLjUPXdqmnAfblVKVcz0fJlGd/lblTBLe1y/8iucB//s1o97irPHmnert2VlwroPg8guyIyMLSmpHXlyZVDqMu56DiD8A8rovaeLOA2GuHfNedqW95zn1P+jf8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755964828; c=relaxed/simple; bh=KVSzn4jAFjRZOnjj54GPJabMi5/vyN4OVJVrz5LsUW4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hICgizG200FE4tBsAmUJLWjJUN4+2bN3n9JvPTm+inSKLB4cUixBRz+vwoFAXXNJuF3zBbrDJcgDApuCxW5LWKQ0ETGU+deA6WFQrTqfJAzVYXuogd3NeLn06Vid1zw7Kofh0QF3qOOx20B/s1e7tFZC080TJE0mwouy1o5G7AA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=A6WkRlKw; arc=none smtp.client-ip=209.85.210.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="A6WkRlKw" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-76e2eb6d07bso2622509b3a.3 for ; Sat, 23 Aug 2025 09:00:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1755964826; x=1756569626; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+QNTGSl8W9jUKwX1Y5hiHFssIh4zzMlPaIQnsQ0pfko=; b=A6WkRlKwBgCMqncNCEJCWsNwGzcnkkWlBwHglbOchMyj4jH9ops8KgkRZFUa67ZF14 5cIe7k+wimeRnrrW59ZofqjCBpXfmzbsTivhn4ywVerfxlkQasWXCDbBHsDttfPgJrCv 6LeRUFrlQ7EKPXBIP6BFNOineqk2LvigJT5XteZbYYzVeErErNLY/W/HDmx+P1hVRoR6 XsNN0v1MdNoYf292JtsK1VUACxc3gMTliHXqK45PHH66Id5RvapW2+4Y7ELx2sJ4IFnA A4U4OoDgvihwtR1RIgagN3I/7n4c0pCAKkN+H/6nJvTLOmh0gjoE3NQOc28lVIvSk+Yw WJ3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755964826; x=1756569626; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+QNTGSl8W9jUKwX1Y5hiHFssIh4zzMlPaIQnsQ0pfko=; b=pyQCYAONBqIZm4mH5aSOH1k3ehxaWF0CLnWiL+oExFI2FBtr3l+AhK40uqqCng4h7g b3Q1ZCHUDv66puFj7u0X4QzWv0wCU81NbCs7g3odLnWTl/JwJwk0DnlIXnkqhoQR33Ru u4O8o8Bw6rxvKvDNyJVu8AdIphErZQWoN8E659Rg0cdNiHvURGKoMyZVcZJFACVjHyJ2 vTO7L5w9iI3s/s66HCC3DGNJ55jw8QHXfykyzUmpKFvzuLcGATUyBTxfhAZCFkI2+pL3 CgojUd/EMimDAIZJwzNOpha04wDOWEBr6hGy7+CFKtvU5cJ5xWWkEn0T0aibOzXg4sRg JKqg== X-Forwarded-Encrypted: i=1; AJvYcCWUs57l+JLC7ggtdnGidy1f3PrXGRIQ87jca22sf+HxtytMekaWFDuKqSdCxZ92X68/WSJgHdNNpXOITWo=@vger.kernel.org X-Gm-Message-State: AOJu0YyLHyKYSVYkKZnj/3Kor5+s69g+5NCjhv+EXibmU+ESqjqL3WsP 6Y1fqRAm23l3ewPW7kIKJG64i3qDH/iGNoJO3MEOVq0mHACk4dwzJrc/rbU/C30JZtRdLq7G3BK vMQrU X-Gm-Gg: ASbGncvdZtLAZYnXi7LF9rhRTz1Job9XhZgwv7J0TrCFSwhwn5eScxCx/fDu78LzH5A y2QVJt/kGgsifP8qD9GKbkVDEnAOPmL0BmxhAJQazVXT0oIqolDvRLgzXO0jz5W3GfnyTlOpOSO AwCqSYcIs5tqC6smTB6qdamBBp91VYLqMQQBcNdPjwEUTTRrC2KCPlkSkTwPcU03HFnmlmMoSLc CCPQJ43QwneTAZG+xgdKlPy9zNBrrRfsyATAtTDS+vxjnouatsUy+Rs6QRIoqjZzKYQlTNUMSna 31v/8f0xFWOin8ta/sc4PzKykZSIld7qcTMyMmRb0FEwQZHwCBvdBXTbe8ORZd9n9JTSfLADwDX bzieW9byZWqxSdRpWkUgnds1G2R7eb6UhCcJqx38UbVrMTLzvao8mjjqgYo7+5VA91xGGiIoC X-Google-Smtp-Source: AGHT+IEo9oLIFiXAIQrZJ7Jw/lL5+vEVJj3YiBwiqokGLrQldRoOB9aEEhSOfywm+FIR5r1fQzfjXg== X-Received: by 2002:a05:6a00:9288:b0:76b:d67b:2ee0 with SMTP id d2e1a72fcca58-7702f9d7f70mr10308982b3a.6.1755964825622; Sat, 23 Aug 2025 09:00:25 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-77040214b81sm2804464b3a.93.2025.08.23.09.00.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Aug 2025 09:00:25 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Palmer Dabbelt , Paul Walmsley , Alexandre Ghiti , Andrew Jones , Anup Patel , Paolo Bonzini , Shuah Khan , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Anup Patel Subject: [PATCH v3 4/6] RISC-V: KVM: Move copy_sbi_ext_reg_indices() to SBI implementation Date: Sat, 23 Aug 2025 21:29:45 +0530 Message-ID: <20250823155947.1354229-5-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250823155947.1354229-1-apatel@ventanamicro.com> References: <20250823155947.1354229-1-apatel@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The ONE_REG handling of SBI extension enable/disable registers and SBI extension state registers is already under SBI implementation. On similar lines, let's move copy_sbi_ext_reg_indices() under SBI implementation. Signed-off-by: Anup Patel Reviewed-by: Andrew Jones --- arch/riscv/include/asm/kvm_vcpu_sbi.h | 2 +- arch/riscv/kvm/vcpu_onereg.c | 29 ++------------------------- arch/riscv/kvm/vcpu_sbi.c | 27 ++++++++++++++++++++++++- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/arch/riscv/include/asm/kvm_vcpu_sbi.h b/arch/riscv/include/asm= /kvm_vcpu_sbi.h index 8970cc7530c4..d75ca45c0152 100644 --- a/arch/riscv/include/asm/kvm_vcpu_sbi.h +++ b/arch/riscv/include/asm/kvm_vcpu_sbi.h @@ -77,6 +77,7 @@ void kvm_riscv_vcpu_sbi_request_reset(struct kvm_vcpu *vc= pu, unsigned long pc, unsigned long a1); void kvm_riscv_vcpu_sbi_load_reset_state(struct kvm_vcpu *vcpu); int kvm_riscv_vcpu_sbi_return(struct kvm_vcpu *vcpu, struct kvm_run *run); +int kvm_riscv_vcpu_reg_indices_sbi_ext(struct kvm_vcpu *vcpu, u64 __user *= uindices); int kvm_riscv_vcpu_set_reg_sbi_ext(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg); int kvm_riscv_vcpu_get_reg_sbi_ext(struct kvm_vcpu *vcpu, @@ -86,7 +87,6 @@ int kvm_riscv_vcpu_set_reg_sbi(struct kvm_vcpu *vcpu, con= st struct kvm_one_reg * int kvm_riscv_vcpu_get_reg_sbi(struct kvm_vcpu *vcpu, const struct kvm_one= _reg *reg); const struct kvm_vcpu_sbi_extension *kvm_vcpu_sbi_find_ext( struct kvm_vcpu *vcpu, unsigned long extid); -bool riscv_vcpu_supports_sbi_ext(struct kvm_vcpu *vcpu, int idx); int kvm_riscv_vcpu_sbi_ecall(struct kvm_vcpu *vcpu, struct kvm_run *run); void kvm_riscv_vcpu_sbi_init(struct kvm_vcpu *vcpu); void kvm_riscv_vcpu_sbi_deinit(struct kvm_vcpu *vcpu); diff --git a/arch/riscv/kvm/vcpu_onereg.c b/arch/riscv/kvm/vcpu_onereg.c index 0f4e444e5e10..865dae903aa0 100644 --- a/arch/riscv/kvm/vcpu_onereg.c +++ b/arch/riscv/kvm/vcpu_onereg.c @@ -1082,34 +1082,9 @@ static inline unsigned long num_isa_ext_regs(const s= truct kvm_vcpu *vcpu) return copy_isa_ext_reg_indices(vcpu, NULL); } =20 -static int copy_sbi_ext_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uin= dices) -{ - unsigned int n =3D 0; - - for (int i =3D 0; i < KVM_RISCV_SBI_EXT_MAX; i++) { - u64 size =3D IS_ENABLED(CONFIG_32BIT) ? - KVM_REG_SIZE_U32 : KVM_REG_SIZE_U64; - u64 reg =3D KVM_REG_RISCV | size | KVM_REG_RISCV_SBI_EXT | - KVM_REG_RISCV_SBI_SINGLE | i; - - if (!riscv_vcpu_supports_sbi_ext(vcpu, i)) - continue; - - if (uindices) { - if (put_user(reg, uindices)) - return -EFAULT; - uindices++; - } - - n++; - } - - return n; -} - static unsigned long num_sbi_ext_regs(struct kvm_vcpu *vcpu) { - return copy_sbi_ext_reg_indices(vcpu, NULL); + return kvm_riscv_vcpu_reg_indices_sbi_ext(vcpu, NULL); } =20 static inline unsigned long num_sbi_regs(struct kvm_vcpu *vcpu) @@ -1237,7 +1212,7 @@ int kvm_riscv_vcpu_copy_reg_indices(struct kvm_vcpu *= vcpu, return ret; uindices +=3D ret; =20 - ret =3D copy_sbi_ext_reg_indices(vcpu, uindices); + ret =3D kvm_riscv_vcpu_reg_indices_sbi_ext(vcpu, uindices); if (ret < 0) return ret; uindices +=3D ret; diff --git a/arch/riscv/kvm/vcpu_sbi.c b/arch/riscv/kvm/vcpu_sbi.c index 04903e5012d6..1b13623380e1 100644 --- a/arch/riscv/kvm/vcpu_sbi.c +++ b/arch/riscv/kvm/vcpu_sbi.c @@ -110,7 +110,7 @@ riscv_vcpu_get_sbi_ext(struct kvm_vcpu *vcpu, unsigned = long idx) return sext; } =20 -bool riscv_vcpu_supports_sbi_ext(struct kvm_vcpu *vcpu, int idx) +static bool riscv_vcpu_supports_sbi_ext(struct kvm_vcpu *vcpu, int idx) { struct kvm_vcpu_sbi_context *scontext =3D &vcpu->arch.sbi_context; const struct kvm_riscv_sbi_extension_entry *sext; @@ -288,6 +288,31 @@ static int riscv_vcpu_get_sbi_ext_multi(struct kvm_vcp= u *vcpu, return 0; } =20 +int kvm_riscv_vcpu_reg_indices_sbi_ext(struct kvm_vcpu *vcpu, u64 __user *= uindices) +{ + unsigned int n =3D 0; + + for (int i =3D 0; i < KVM_RISCV_SBI_EXT_MAX; i++) { + u64 size =3D IS_ENABLED(CONFIG_32BIT) ? + KVM_REG_SIZE_U32 : KVM_REG_SIZE_U64; + u64 reg =3D KVM_REG_RISCV | size | KVM_REG_RISCV_SBI_EXT | + KVM_REG_RISCV_SBI_SINGLE | i; + + if (!riscv_vcpu_supports_sbi_ext(vcpu, i)) + continue; + + if (uindices) { + if (put_user(reg, uindices)) + return -EFAULT; + uindices++; + } + + n++; + } + + return n; +} + int kvm_riscv_vcpu_set_reg_sbi_ext(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) { --=20 2.43.0