Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1361484lqe; Mon, 8 Apr 2024 07:00:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVWvpQqU5jRbW5DoKlWjxBUoljYWizUDL5HEqHI2Ri3c67BFgy0CpiNDdDb4U0uiMTEP8JY7jKtH4yMgeotxi3DTaUidA6NQp4qZf5wGw== X-Google-Smtp-Source: AGHT+IF5JYIKZBbYYigqIkz6QuquiHAuS8AAALvG6jyPpjb0zJtvJmdHTkR50tLlR5+/65b5z1iz X-Received: by 2002:a05:6358:2248:b0:186:1c42:7240 with SMTP id i8-20020a056358224800b001861c427240mr4873144rwc.12.1712584837633; Mon, 08 Apr 2024 07:00:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712584837; cv=pass; d=google.com; s=arc-20160816; b=ru9VuwOVWQNHG2OiJ75mWWJKWGttosoNdgcdc9pzrJSU09RXbfTqGEQTe/iJOfRL0L +N8KGVtBQg8jkgg1KjnE2K1gSJWUx30uSF6UZp8VLTZzahLiuf0j7+vp19/UZeDRsWR0 VeBu8ax9kIR4sdxS9SETzfnLQCe8MToi6yl0fIawX2KVebK54bCi1owKNjTyFe+KxcIe f+JkxiXwRis8f/vZaQ5MI0O6+s5KQ0I/hMtLr/NBxSB3gRTGtwfFSxWsvRH8dhmP8k7z +W58n5ce6Yoeb2mYbv3bmPspviDstqs770ikbbUtyTYov/SrIlJv3j4noczTzeZ2qTbW Jo4w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=2coaQxB0F90mD/VO/63txYCW7fbnXdz4Og49R0bnS0Q=; fh=4o/Iy9xYUPbRjYBrjtnc1pSIeeIKMP/iI9hHiCEBw/k=; b=RwXL+zj9K/ixf2tdhckX8D78/zEEZpgMKXvd51L8uaH09LC7EbcaUxTnZNZTSMvqZ/ +lbsIHI5FsQfY6s0YFrcT3GSkkLaGjpX7w3BblUiHyKlr+Lco5TpD1XOrX0T3Hklbdo3 gX+a8Txp9yYS9VVbM2U4OtSNW8mqN1yfzboDCEGUUIW6kAsQWQOWuk/fLrO9Wz+lWZVZ LGgLpyYnTocLNc7KwYX6YEqSaUbEfUYROK7SROmDmD/HK7zReAvPrcg/T5x992B02Nub xqGJU+UmxVZHgpumjT+go/7nMmpz+5I0jXu7vb779F18Og+lUOBAynKmU9QWNWZTZ0wQ mMaw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bitbyteword.org header.s=google header.b=IpyLp1h3; arc=pass (i=1 spf=pass spfdomain=bitbyteword.org dkim=pass dkdomain=bitbyteword.org); spf=pass (google.com: domain of linux-kernel+bounces-135476-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135476-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id c1-20020a63d141000000b005dca783a8basi6331208pgj.841.2024.04.08.07.00.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 07:00:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-135476-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bitbyteword.org header.s=google header.b=IpyLp1h3; arc=pass (i=1 spf=pass spfdomain=bitbyteword.org dkim=pass dkdomain=bitbyteword.org); spf=pass (google.com: domain of linux-kernel+bounces-135476-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135476-linux.lists.archive=gmail.com@vger.kernel.org" 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 44FCF2819E3 for ; Mon, 8 Apr 2024 14:00:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5D6EF7E10B; Mon, 8 Apr 2024 13:59:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bitbyteword.org header.i=@bitbyteword.org header.b="IpyLp1h3" Received: from mail-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) (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 928957D3E8 for ; Mon, 8 Apr 2024 13:59:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712584784; cv=none; b=GWXBZ4cnklUgBjQU4xKUVgB5TLVrOBi27LO6xqo/ik05pVXfk2uDS6oG4aWq9ANRapH9Ksc1QqIguQJpuFHsDYQRXmTtdaD2zv2VLndHpZ7Ys2aUxLjAufzj9IsqCZxRRkeSlqzEc9OKYsIOwqx2tvJ/ACtb45pUbhg8P3g/dlo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712584784; c=relaxed/simple; bh=lbVTY91IwFFIb6sbUTf2Z6WUddRDSgvFYfQik2bdU5s=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=EeKKzlrksqqfFVaXNHbaag4rQAFvPfgEa+7HyW0UJOeISGHiysrRuREBOgdcV/c0La7qdERzdWhbgBShYVRBtK9uqP58zPVf7TuhpnKigDNcMynD6zlpMVMsI73fDuWVLSpXoy2ESuAjrkT6tubVKDfat1cJP/c8WPufeUcyleI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bitbyteword.org; spf=pass smtp.mailfrom=bitbyteword.org; dkim=pass (2048-bit key) header.d=bitbyteword.org header.i=@bitbyteword.org header.b=IpyLp1h3; arc=none smtp.client-ip=209.85.219.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bitbyteword.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bitbyteword.org Received: by mail-yb1-f177.google.com with SMTP id 3f1490d57ef6-dccb1421bdeso4340833276.1 for ; Mon, 08 Apr 2024 06:59:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bitbyteword.org; s=google; t=1712584781; x=1713189581; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=2coaQxB0F90mD/VO/63txYCW7fbnXdz4Og49R0bnS0Q=; b=IpyLp1h3XLmltMszTAcxVWHS6ZFLH/1mNbEnJhbxRzfgDqnuBZix6GaXxkPbZRn++j GwSzUc0K42qlfV9ozuQ2trE3fpz6b4LFuXTDSaNdIsbZgJGQEpZjZin8pCdRFaHOem7n xcrOU/UFn4zxyjB3RodCT5zMwLFQ4ii06grSDEf7iJUtOq5JDnDq0DPeWAvKrrtDZKg9 nfvmDX8R3vNBjIFBgCZYHb2dmWPA5F9Ag46LO03n5wACybE+mebMDc7g7rseMNC79Gxc B7/picFwhBGPBUsUmWXe2q4hKHMuvPLfJpIbnnj3fA5BpqAiQttD7Bw9rLwo10EepvvK uleA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712584781; x=1713189581; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2coaQxB0F90mD/VO/63txYCW7fbnXdz4Og49R0bnS0Q=; b=E5oRpMYX7/Gbn98r0Syw05UUtTPwaIXXwf55CgY2PDATrxvouu7ZMTq4DRubJywR9E Pqkv2eLILwivGO90moG7K1NmrB3hHHXTuzXSeGkeGPOj6i+aAwWXr63Zz6AA9NUlSqFH WZC9ecM0Jc8N1DfJJS9R9IFna8qjJTyjXFn7o32XkKOMJkUSxumBGYX/wr1OgGNiYTeP BBdoIFDrUjDnc1UE1hy9Aem3q0r1UJgDSjDgmUuApyt8ZUQ3dOkqhVfkYiQIsHnd8ri7 lvjynlUazy+w2QIOHtqzlhhLtdtefHz7yyHewXte7/QEAuAnfdQtqqsoHw+h/iS5HSP1 HqxQ== X-Forwarded-Encrypted: i=1; AJvYcCVQP40k4Myqxu3RUTuVfIreGafuOf2AE6DGJYd0oYxYxC5AnspSn+wgUiQUxy4psmV02Xh4V9l7T7u48x4SZfABzHuNJLSWyNnR3gwC X-Gm-Message-State: AOJu0YwwNkQhCXH7sAq9RBYAkID/4qIQzx0P7IQfRpK1smkwvENnfn6d Ej0eh9LoDhwab3NT/65NNK7TdA32TD4MtPMyJpGus5FQ2JlM1eAlFOJepflNmpxbVC5NM0ZF27y ZZWI6s72o/EhFQFDGimTzD3Wpg/zo4cwVlLY63rT8lXhE22YGK80= X-Received: by 2002:a5b:843:0:b0:dcd:af3f:c7fc with SMTP id v3-20020a5b0843000000b00dcdaf3fc7fcmr6978574ybq.9.1712584781543; Mon, 08 Apr 2024 06:59:41 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240403140116.3002809-1-vineeth@bitbyteword.org> <20240403140116.3002809-4-vineeth@bitbyteword.org> In-Reply-To: <20240403140116.3002809-4-vineeth@bitbyteword.org> From: Vineeth Remanan Pillai Date: Mon, 8 Apr 2024 09:59:31 -0400 Message-ID: Subject: Re: [RFC PATCH v2 3/5] kvm: interface for managing pvsched driver for guest VMs To: Ben Segall , Borislav Petkov , Daniel Bristot de Oliveira , Dave Hansen , Dietmar Eggemann , "H . Peter Anvin" , Ingo Molnar , Juri Lelli , Mel Gorman , Paolo Bonzini , Andy Lutomirski , Peter Zijlstra , Sean Christopherson , Thomas Gleixner , Valentin Schneider , Vincent Guittot , Vitaly Kuznetsov , Wanpeng Li Cc: Steven Rostedt , Joel Fernandes , Suleiman Souhlal , Masami Hiramatsu , himadrics@inria.fr, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, Tejun Heo , Barret Rhoden , David Vernet , Josh Don Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Adding sched_ext folks On Wed, Apr 3, 2024 at 10:01=E2=80=AFAM Vineeth Pillai (Google) wrote: > > Implement ioctl for assigning and unassigning pvsched driver for a > guest. VMMs would need to adopt this ioctls for supporting the feature. > Also add a temporary debugfs interface for managing this. > > Ideally, the hypervisor would be able to determine the pvsched driver > based on the information received from the guest. Guest VMs with the > feature enabled would request hypervisor to select a pvsched driver. > ioctl api is an override mechanism to give more control to the admin. > > Signed-off-by: Vineeth Pillai (Google) > Signed-off-by: Joel Fernandes (Google) > --- > include/uapi/linux/kvm.h | 6 ++ > virt/kvm/kvm_main.c | 117 +++++++++++++++++++++++++++++++++++++++ > 2 files changed, 123 insertions(+) > > diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h > index c3308536482b..4b29bdad4188 100644 > --- a/include/uapi/linux/kvm.h > +++ b/include/uapi/linux/kvm.h > @@ -2227,4 +2227,10 @@ struct kvm_create_guest_memfd { > __u64 reserved[6]; > }; > > +struct kvm_pvsched_ops { > + __u8 ops_name[32]; /* PVSCHED_NAME_MAX */ > +}; > + > +#define KVM_GET_PVSCHED_OPS _IOR(KVMIO, 0xe4, struct kvm_pvsc= hed_ops) > +#define KVM_REPLACE_PVSCHED_OPS _IOWR(KVMIO, 0xe5, struct= kvm_pvsched_ops) > #endif /* __LINUX_KVM_H */ > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index 0546814e4db7..b3d9c362d2e3 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -1223,6 +1223,79 @@ static void kvm_destroy_vm_debugfs(struct kvm *kvm= ) > } > } > > +#ifdef CONFIG_PARAVIRT_SCHED_KVM > +static int pvsched_vcpu_ops_show(struct seq_file *m, void *data) > +{ > + char ops_name[PVSCHED_NAME_MAX]; > + struct pvsched_vcpu_ops *ops; > + struct kvm *kvm =3D (struct kvm *) m->private; > + > + rcu_read_lock(); > + ops =3D rcu_dereference(kvm->pvsched_ops); > + if (ops) > + strncpy(ops_name, ops->name, PVSCHED_NAME_MAX); > + rcu_read_unlock(); > + > + seq_printf(m, "%s\n", ops_name); > + > + return 0; > +} > + > +static ssize_t > +pvsched_vcpu_ops_write(struct file *filp, const char __user *ubuf, > + size_t cnt, loff_t *ppos) > +{ > + int ret; > + char *cmp; > + char buf[PVSCHED_NAME_MAX]; > + struct inode *inode; > + struct kvm *kvm; > + > + if (cnt > PVSCHED_NAME_MAX) > + return -EINVAL; > + > + if (copy_from_user(&buf, ubuf, cnt)) > + return -EFAULT; > + > + cmp =3D strstrip(buf); > + > + inode =3D file_inode(filp); > + inode_lock(inode); > + kvm =3D (struct kvm *)inode->i_private; > + ret =3D kvm_replace_pvsched_ops(kvm, cmp); > + inode_unlock(inode); > + > + if (ret) > + return ret; > + > + *ppos +=3D cnt; > + return cnt; > +} > + > +static int pvsched_vcpu_ops_open(struct inode *inode, struct file *filp) > +{ > + return single_open(filp, pvsched_vcpu_ops_show, inode->i_private)= ; > +} > + > +static const struct file_operations pvsched_vcpu_ops_fops =3D { > + .open =3D pvsched_vcpu_ops_open, > + .write =3D pvsched_vcpu_ops_write, > + .read =3D seq_read, > + .llseek =3D seq_lseek, > + .release =3D single_release, > +}; > + > +static void kvm_create_vm_pvsched_debugfs(struct kvm *kvm) > +{ > + debugfs_create_file("pvsched_vcpu_ops", 0644, kvm->debugfs_dentry= , kvm, > + &pvsched_vcpu_ops_fops); > +} > +#else > +static void kvm_create_vm_pvsched_debugfs(struct kvm *kvm) > +{ > +} > +#endif > + > static int kvm_create_vm_debugfs(struct kvm *kvm, const char *fdname) > { > static DEFINE_MUTEX(kvm_debugfs_lock); > @@ -1288,6 +1361,8 @@ static int kvm_create_vm_debugfs(struct kvm *kvm, c= onst char *fdname) > &stat_fops_per_vm); > } > > + kvm_create_vm_pvsched_debugfs(kvm); > + > ret =3D kvm_arch_create_vm_debugfs(kvm); > if (ret) > goto out_err; > @@ -5474,6 +5549,48 @@ static long kvm_vm_ioctl(struct file *filp, > r =3D kvm_gmem_create(kvm, &guest_memfd); > break; > } > +#endif > +#ifdef CONFIG_PARAVIRT_SCHED_KVM > + case KVM_REPLACE_PVSCHED_OPS: > + struct pvsched_vcpu_ops *ops; > + struct kvm_pvsched_ops in_ops, out_ops; > + > + r =3D -EFAULT; > + if (copy_from_user(&in_ops, argp, sizeof(in_ops))) > + goto out; > + > + out_ops.ops_name[0] =3D 0; > + > + rcu_read_lock(); > + ops =3D rcu_dereference(kvm->pvsched_ops); > + if (ops) > + strncpy(out_ops.ops_name, ops->name, PVSCHED_NAME= _MAX); > + rcu_read_unlock(); > + > + r =3D kvm_replace_pvsched_ops(kvm, (char *)in_ops.ops_nam= e); > + if (r) > + goto out; > + > + r =3D -EFAULT; > + if (copy_to_user(argp, &out_ops, sizeof(out_ops))) > + goto out; > + > + r =3D 0; > + break; > + case KVM_GET_PVSCHED_OPS: > + out_ops.ops_name[0] =3D 0; > + rcu_read_lock(); > + ops =3D rcu_dereference(kvm->pvsched_ops); > + if (ops) > + strncpy(out_ops.ops_name, ops->name, PVSCHED_NAME= _MAX); > + rcu_read_unlock(); > + > + r =3D -EFAULT; > + if (copy_to_user(argp, &out_ops, sizeof(out_ops))) > + goto out; > + > + r =3D 0; > + break; > #endif > default: > r =3D kvm_arch_vm_ioctl(filp, ioctl, arg); > -- > 2.40.1 >