All of lore.kernel.org
 help / color / mirror / Atom feed
From: Janis Schoetterl-Glausch <scgl@linux.ibm.com>
To: Christian Borntraeger <borntraeger@linux.ibm.com>,
	Janosch Frank <frankja@linux.ibm.com>,
	Claudio Imbrenda <imbrenda@linux.ibm.com>,
	Heiko Carstens <hca@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Janis Schoetterl-Glausch <scgl@linux.ibm.com>,
	David Hildenbrand <david@redhat.com>,
	Jonathan Corbet <corbet@lwn.net>,
	kvm@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-s390@vger.kernel.org, Paolo Bonzini <pbonzini@redhat.com>,
	Shuah Khan <shuah@kernel.org>,
	Sven Schnelle <svens@linux.ibm.com>
Subject: [PATCH v6 09/14] KVM: s390: Dispatch to implementing function at top level of vm mem_op
Date: Wed, 25 Jan 2023 22:26:03 +0100	[thread overview]
Message-ID: <20230125212608.1860251-10-scgl@linux.ibm.com> (raw)
In-Reply-To: <20230125212608.1860251-1-scgl@linux.ibm.com>

Instead of having one function covering all mem_op operations,
have a function implementing absolute access and dispatch to that
function in its caller, based on the operation code.
This way additional future operations can be implemented by adding an
implementing function without changing existing operations.

Suggested-by: Janosch Frank <frankja@linux.ibm.com>
Signed-off-by: Janis Schoetterl-Glausch <scgl@linux.ibm.com>
---
 arch/s390/kvm/kvm-s390.c | 38 ++++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index e0dfaa195949..588cf70dc81e 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -2791,7 +2791,7 @@ static void *mem_op_alloc_buf(struct kvm_s390_mem_op *mop)
 	return buf;
 }
 
-static int kvm_s390_vm_mem_op(struct kvm *kvm, struct kvm_s390_mem_op *mop)
+static int kvm_s390_vm_mem_op_abs(struct kvm *kvm, struct kvm_s390_mem_op *mop)
 {
 	void __user *uaddr = (void __user *)mop->buf;
 	void *tmpbuf = NULL;
@@ -2802,17 +2802,6 @@ static int kvm_s390_vm_mem_op(struct kvm *kvm, struct kvm_s390_mem_op *mop)
 	if (r)
 		return r;
 
-	/*
-	 * This is technically a heuristic only, if the kvm->lock is not
-	 * taken, it is not guaranteed that the vm is/remains non-protected.
-	 * This is ok from a kernel perspective, wrongdoing is detected
-	 * on the access, -EFAULT is returned and the vm may crash the
-	 * next time it accesses the memory in question.
-	 * There is no sane usecase to do switching and a memop on two
-	 * different CPUs at the same time.
-	 */
-	if (kvm_s390_pv_get_handle(kvm))
-		return -EINVAL;
 	tmpbuf = mem_op_alloc_buf(mop);
 	if (IS_ERR(tmpbuf))
 		return PTR_ERR(tmpbuf);
@@ -2851,8 +2840,6 @@ static int kvm_s390_vm_mem_op(struct kvm *kvm, struct kvm_s390_mem_op *mop)
 		}
 		break;
 	}
-	default:
-		r = -EINVAL;
 	}
 
 out_unlock:
@@ -2862,6 +2849,29 @@ static int kvm_s390_vm_mem_op(struct kvm *kvm, struct kvm_s390_mem_op *mop)
 	return r;
 }
 
+static int kvm_s390_vm_mem_op(struct kvm *kvm, struct kvm_s390_mem_op *mop)
+{
+	/*
+	 * This is technically a heuristic only, if the kvm->lock is not
+	 * taken, it is not guaranteed that the vm is/remains non-protected.
+	 * This is ok from a kernel perspective, wrongdoing is detected
+	 * on the access, -EFAULT is returned and the vm may crash the
+	 * next time it accesses the memory in question.
+	 * There is no sane usecase to do switching and a memop on two
+	 * different CPUs at the same time.
+	 */
+	if (kvm_s390_pv_get_handle(kvm))
+		return -EINVAL;
+
+	switch (mop->op) {
+	case KVM_S390_MEMOP_ABSOLUTE_READ:
+	case KVM_S390_MEMOP_ABSOLUTE_WRITE:
+		return kvm_s390_vm_mem_op_abs(kvm, mop);
+	default:
+		return -EINVAL;
+	}
+}
+
 long kvm_arch_vm_ioctl(struct file *filp,
 		       unsigned int ioctl, unsigned long arg)
 {
-- 
2.34.1


  parent reply	other threads:[~2023-01-25 21:26 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-25 21:25 [PATCH v6 00/14] KVM: s390: Extend MEM_OP ioctl by storage key checked cmpxchg Janis Schoetterl-Glausch
2023-01-25 21:25 ` [PATCH v6 01/14] KVM: s390: selftest: memop: Pass mop_desc via pointer Janis Schoetterl-Glausch
2023-01-26 11:51   ` Janosch Frank
2023-01-25 21:25 ` [PATCH v6 02/14] KVM: s390: selftest: memop: Replace macros by functions Janis Schoetterl-Glausch
2023-01-26 12:00   ` Janosch Frank
2023-01-25 21:25 ` [PATCH v6 03/14] KVM: s390: selftest: memop: Move testlist into main Janis Schoetterl-Glausch
2023-01-26 12:03   ` Janosch Frank
2023-01-25 21:25 ` [PATCH v6 04/14] KVM: s390: selftest: memop: Add bad address test Janis Schoetterl-Glausch
2023-01-26 15:23   ` Janosch Frank
2023-01-25 21:25 ` [PATCH v6 05/14] KVM: s390: selftest: memop: Fix typo Janis Schoetterl-Glausch
2023-01-25 21:26 ` [PATCH v6 06/14] KVM: s390: selftest: memop: Fix wrong address being used in test Janis Schoetterl-Glausch
2023-01-25 21:26 ` [PATCH v6 07/14] KVM: s390: selftest: memop: Fix integer literal Janis Schoetterl-Glausch
2023-01-26  6:38   ` Thomas Huth
2023-01-25 21:26 ` [PATCH v6 08/14] KVM: s390: Move common code of mem_op functions into functions Janis Schoetterl-Glausch
2023-01-26  6:48   ` Thomas Huth
2023-01-26 13:02     ` Janosch Frank
2023-01-26 16:47       ` Janis Schoetterl-Glausch
2023-01-26 17:01     ` Janis Schoetterl-Glausch
2023-01-25 21:26 ` Janis Schoetterl-Glausch [this message]
2023-01-26 12:13   ` [PATCH v6 09/14] KVM: s390: Dispatch to implementing function at top level of vm mem_op Thomas Huth
2023-01-25 21:26 ` [PATCH v6 10/14] KVM: s390: Refactor absolute vm mem_op function Janis Schoetterl-Glausch
2023-01-26 12:18   ` Thomas Huth
2023-01-26 13:02     ` Janosch Frank
2023-02-03 14:48   ` Janosch Frank
2023-02-03 15:32     ` Janis Schoetterl-Glausch
2023-01-25 21:26 ` [PATCH v6 11/14] KVM: s390: Refactor absolute vcpu " Janis Schoetterl-Glausch
2023-01-25 21:26 ` [PATCH v6 12/14] KVM: s390: Extend MEM_OP ioctl by storage key checked cmpxchg Janis Schoetterl-Glausch
2023-01-26  8:19   ` Heiko Carstens
2023-01-26 16:10   ` Janosch Frank
2023-01-27 18:15     ` Janis Schoetterl-Glausch
2023-01-28  9:29   ` kernel test robot
2023-01-28 14:38   ` kernel test robot
2023-01-28 14:38   ` kernel test robot
2023-01-25 21:26 ` [PATCH v6 13/14] Documentation: KVM: s390: Describe KVM_S390_MEMOP_F_CMPXCHG Janis Schoetterl-Glausch
2023-01-25 21:26 ` [PATCH v6 14/14] KVM: s390: selftest: memop: Add cmpxchg tests Janis Schoetterl-Glausch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230125212608.1860251-10-scgl@linux.ibm.com \
    --to=scgl@linux.ibm.com \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=corbet@lwn.net \
    --cc=david@redhat.com \
    --cc=frankja@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=shuah@kernel.org \
    --cc=svens@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.