From nobody Mon Feb 9 19:25:43 2026 Received: from mail-qv1-f49.google.com (mail-qv1-f49.google.com [209.85.219.49]) (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 D8527148FEA for ; Wed, 3 Apr 2024 14:01:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712152887; cv=none; b=BXE6f/JP1m740XBYuoG4jD6GdqGrhTScjrykZjRH0EVoCDP4poSEKvBCvp8ILXfFwpgswrhqd5cEEZUl3iXgVLVW2kbDpYaNtC2QjqRlXys6bCWJl2QtCaMjCmvWa/Z0Jcq0amY/x9bYU6ePBvKzgnKkHPYcBjd/9zqQIausxj8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712152887; c=relaxed/simple; bh=lpEab+19m9Mx7BY7SwMTKJYnA5tlJh+0D6EDugugn/0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WvP/dfdEsPc6WME/WPJQljCDHuMS84G3SlzrRELAZ+5VNLXgYlu1N1M4exJYLoDZTAbxprP7RdwxMQK0WHCoNWPIhOYSZX+SXJoS91bvYsaDF7SqXeIV/U5EWrYGTkQoqLG9s3N1NEapha27BPu9vISmXh3bd7UaH392f1LkRjI= 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=TZOnuuqC; arc=none smtp.client-ip=209.85.219.49 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bitbyteword.org header.i=@bitbyteword.org header.b="TZOnuuqC" Received: by mail-qv1-f49.google.com with SMTP id 6a1803df08f44-6964b1c529cso50150506d6.0 for ; Wed, 03 Apr 2024 07:01:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bitbyteword.org; s=google; t=1712152884; x=1712757684; 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=UONGPslpRt306kqZsCmGTE/b37ydkUsAJesjvT1tJpY=; b=TZOnuuqCWQeykS4xx0VCry+S8i7MXpSO9vMoFgCzqKiZyCp/I8S2Um7vg0thOCZgJf 7UaNcUxP3yUXZZT6TQ8O5f8N/jalmIxY1FnTf1Uhkw0FUeP2Y13+EBpKchrPPJWorJdW I3HrlKMeGHvl7cziEfxEMhY+RMAEYlSuCFwUP3iUzd/05ziPD/hWiwjohlkAnzWJfDGx Jbkg1na5dkHQLAHjVqBbTtG8fibHn2zZTQicobvWq2GG/DrCUT8lSZGf31GjTJ5m6RkQ O6Cofmxlwr/ey490UI32Vb7SRyJBjHS4FzaQ72EGEFKltjhfFbAKar07t4Cyspz5Plsh UAQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712152884; x=1712757684; 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=UONGPslpRt306kqZsCmGTE/b37ydkUsAJesjvT1tJpY=; b=fr+QVVKWEdUdPJJ6F5VIZM6hFOr19UoKAfyJgOUQp6NKiamnTU/XmqHAaEXdNN/X2C BMUEtnOe8rwNE1lScqd2IczERnQMG1TGpG+7tM/qgT/uDD6nI2DJOeLZjFkkzwmPSPlC CYcjQ2ANphRsX4vzU/2UzYtDJGKjelf6PoqBiFfgmLXrHEIFexsahFy4vt1JQlyNmzdr ztMpEQXLrXjNmF/WnKPQso0+/10dYZSYdcFZg1La4f68m1Yt2Rljul66Wsrml7ykHge4 PLqN5SwgwfPIgl4alwSPJ+HpMzeMiH9fLSUcN1FlrPv8g5xCWTnVtqXhc5u3MugJmYnv nPGw== X-Forwarded-Encrypted: i=1; AJvYcCWuEESjsOGDLk15TN7rM+Ssyqz9Fce42HiQcITL4jhXKVplsqLWP75Bt0eCmYCEhpUtRNh7eJ/n+xv0kIKfMKUAnHdZKePebnDo/N2d X-Gm-Message-State: AOJu0YzmEbpDflrprFG8LJETAyLXAs2ufyfAk8SSS7gcxWrbm3TZBnTC QMq0cIBFhCTxI3gQIlO26JwvWa58v3STY2VLYcuSMnPgQ7ZUIfEsbZN/lzm8s3I= X-Google-Smtp-Source: AGHT+IHyvTEQNqSIQcjpHeGqJ7SNEPZRIYtalkAiLrynTgcv4Dtsm9x9wS8IfPIQOAxIX49l9lI3dg== X-Received: by 2002:a05:6214:8f2:b0:699:2ad4:3dc4 with SMTP id dr18-20020a05621408f200b006992ad43dc4mr1251372qvb.42.1712152883304; Wed, 03 Apr 2024 07:01:23 -0700 (PDT) Received: from vinbuntup3.lan (c-73-143-21-186.hsd1.vt.comcast.net. [73.143.21.186]) by smtp.gmail.com with ESMTPSA id gf12-20020a056214250c00b00698d06df322sm5945706qvb.122.2024.04.03.07.01.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 07:01:22 -0700 (PDT) From: "Vineeth Pillai (Google)" 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: "Vineeth Pillai (Google)" , Steven Rostedt , Joel Fernandes , Suleiman Souhlal , Masami Hiramatsu , himadrics@inria.fr, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Subject: [RFC PATCH v2 1/5] pvsched: paravirt scheduling framework Date: Wed, 3 Apr 2024 10:01:12 -0400 Message-Id: <20240403140116.3002809-2-vineeth@bitbyteword.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240403140116.3002809-1-vineeth@bitbyteword.org> References: <20240403140116.3002809-1-vineeth@bitbyteword.org> 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" Implement a paravirt scheduling framework for linux kernel. The framework allows for pvsched driver to register to the kernel and receive callbacks from hypervisor(eg: kvm) for interested vcpu events like VMENTER, VMEXIT etc. The framework also allows hypervisor to select a pvsched driver (from the available list of registered drivers) for each guest. Also implement a sysctl for listing the available pvsched drivers. Signed-off-by: Vineeth Pillai (Google) Signed-off-by: Joel Fernandes (Google) --- Kconfig | 2 + include/linux/pvsched.h | 102 +++++++++++++++++++ kernel/sysctl.c | 27 +++++ virt/Makefile | 2 +- virt/pvsched/Kconfig | 12 +++ virt/pvsched/Makefile | 2 + virt/pvsched/pvsched.c | 215 ++++++++++++++++++++++++++++++++++++++++ 7 files changed, 361 insertions(+), 1 deletion(-) create mode 100644 include/linux/pvsched.h create mode 100644 virt/pvsched/Kconfig create mode 100644 virt/pvsched/Makefile create mode 100644 virt/pvsched/pvsched.c diff --git a/Kconfig b/Kconfig index 745bc773f567..4a52eaa21166 100644 --- a/Kconfig +++ b/Kconfig @@ -29,4 +29,6 @@ source "lib/Kconfig" =20 source "lib/Kconfig.debug" =20 +source "virt/pvsched/Kconfig" + source "Documentation/Kconfig" diff --git a/include/linux/pvsched.h b/include/linux/pvsched.h new file mode 100644 index 000000000000..59df6b44aacb --- /dev/null +++ b/include/linux/pvsched.h @@ -0,0 +1,102 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (c) 2024 Google */ + +#ifndef _LINUX_PVSCHED_H +#define _LINUX_PVSCHED_H 1 + +/* + * List of events for which hypervisor calls back into pvsched driver. + * Driver can specify the events it is interested in. + */ +enum pvsched_vcpu_events { + PVSCHED_VCPU_VMENTER =3D 0x1, + PVSCHED_VCPU_VMEXIT =3D 0x2, + PVSCHED_VCPU_HALT =3D 0x4, + PVSCHED_VCPU_INTR_INJ =3D 0x8, +}; + +#define PVSCHED_NAME_MAX 32 +#define PVSCHED_MAX 8 +#define PVSCHED_DRV_BUF_MAX (PVSCHED_NAME_MAX * PVSCHED_MAX + PVSCHED_MAX) + +/* + * pvsched driver callbacks. + * TODO: versioning support for better compatibility with the guest + * component implementing this feature. + */ +struct pvsched_vcpu_ops { + /* + * pvsched_vcpu_register() - Register the vcpu with pvsched driver. + * @pid: pid of the vcpu task. + * + * pvsched driver can store the pid internally and initialize + * itself to prepare for receiving callbacks from thsi vcpu. + */ + int (*pvsched_vcpu_register)(struct pid *pid); + + /* + * pvsched_vcpu_unregister() - Un-register the vcpu with pvsched driver. + * @pid: pid of the vcpu task. + */ + void (*pvsched_vcpu_unregister)(struct pid *pid); + + /* + * pvsched_vcpu_notify_event() - Callback for pvsched events + * @addr: Address of the memory region shared with guest + * @pid: pid of the vcpu task. + * @events: bit mask of the events that hypervisor wants to notify. + */ + void (*pvsched_vcpu_notify_event)(void *addr, struct pid *pid, u32 event); + + char name[PVSCHED_NAME_MAX]; + struct module *owner; + struct list_head list; + u32 events; + u32 key; +}; + +#ifdef CONFIG_PARAVIRT_SCHED_HOST +int pvsched_get_available_drivers(char *buf, size_t maxlen); + +int pvsched_register_vcpu_ops(struct pvsched_vcpu_ops *ops); +void pvsched_unregister_vcpu_ops(struct pvsched_vcpu_ops *ops); + +struct pvsched_vcpu_ops *pvsched_get_vcpu_ops(char *name); +void pvsched_put_vcpu_ops(struct pvsched_vcpu_ops *ops); + +static inline int pvsched_validate_vcpu_ops(struct pvsched_vcpu_ops *ops) +{ + /* + * All callbacks are mandatory. + */ + if (!ops->pvsched_vcpu_register || !ops->pvsched_vcpu_unregister || + !ops->pvsched_vcpu_notify_event) + return -EINVAL; + + return 0; +} +#else +static inline void pvsched_get_available_drivers(char *buf, size_t maxlen) +{ +} + +static inline int pvsched_register_vcpu_ops(struct pvsched_vcpu_ops *ops) +{ + return -ENOTSUPP; +} + +static inline void pvsched_unregister_vcpu_ops(struct pvsched_vcpu_ops *op= s) +{ +} + +static inline struct pvsched_vcpu_ops *pvsched_get_vcpu_ops(char *name) +{ + return NULL; +} + +static inline void pvsched_put_vcpu_ops(struct pvsched_vcpu_ops *ops) +{ +} +#endif + +#endif diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 157f7ce2942d..10a18a791b4f 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -63,6 +63,7 @@ #include #include #include +#include =20 #include "../lib/kstrtox.h" =20 @@ -1615,6 +1616,24 @@ int proc_do_static_key(struct ctl_table *table, int = write, return ret; } =20 +#ifdef CONFIG_PARAVIRT_SCHED_HOST +static int proc_pvsched_available_drivers(struct ctl_table *ctl, + int write, void *buffer, + size_t *lenp, loff_t *ppos) +{ + struct ctl_table tbl =3D { .maxlen =3D PVSCHED_DRV_BUF_MAX, }; + int ret; + + tbl.data =3D kmalloc(tbl.maxlen, GFP_USER); + if (!tbl.data) + return -ENOMEM; + pvsched_get_available_drivers(tbl.data, PVSCHED_DRV_BUF_MAX); + ret =3D proc_dostring(&tbl, write, buffer, lenp, ppos); + kfree(tbl.data); + return ret; +} +#endif + static struct ctl_table kern_table[] =3D { { .procname =3D "panic", @@ -2033,6 +2052,14 @@ static struct ctl_table kern_table[] =3D { .extra1 =3D SYSCTL_ONE, .extra2 =3D SYSCTL_INT_MAX, }, +#endif +#ifdef CONFIG_PARAVIRT_SCHED_HOST + { + .procname =3D "pvsched_available_drivers", + .maxlen =3D PVSCHED_DRV_BUF_MAX, + .mode =3D 0444, + .proc_handler =3D proc_pvsched_available_drivers, + }, #endif { } }; diff --git a/virt/Makefile b/virt/Makefile index 1cfea9436af9..9d0f32d775a1 100644 --- a/virt/Makefile +++ b/virt/Makefile @@ -1,2 +1,2 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-y +=3D lib/ +obj-y +=3D lib/ pvsched/ diff --git a/virt/pvsched/Kconfig b/virt/pvsched/Kconfig new file mode 100644 index 000000000000..5ca2669060cb --- /dev/null +++ b/virt/pvsched/Kconfig @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0-only +config PARAVIRT_SCHED_HOST + bool "Paravirt scheduling framework in the host kernel" + default n + help + Paravirtualized scheduling facilitates the exchange of scheduling + related information between the host and guest through shared memory, + enhancing the efficiency of vCPU thread scheduling by the hypervisor. + An illustrative use case involves dynamically boosting the priority of + a vCPU thread when the guest is executing a latency-sensitive workload + on that specific vCPU. + This config enables paravirt scheduling framework in the host kernel. diff --git a/virt/pvsched/Makefile b/virt/pvsched/Makefile new file mode 100644 index 000000000000..4ca38e30479b --- /dev/null +++ b/virt/pvsched/Makefile @@ -0,0 +1,2 @@ + +obj-$(CONFIG_PARAVIRT_SCHED_HOST) +=3D pvsched.o diff --git a/virt/pvsched/pvsched.c b/virt/pvsched/pvsched.c new file mode 100644 index 000000000000..610c85cf90d2 --- /dev/null +++ b/virt/pvsched/pvsched.c @@ -0,0 +1,215 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (c) 2024 Google */ + +/* + * Paravirt scheduling framework + * + */ + +/* + * Heavily inspired from tcp congestion avoidance implementation. + * (net/ipv4/tcp_cong.c) + */ + +#define pr_fmt(fmt) "PVSCHED: " fmt + +#include +#include +#include +#include +#include +#include +#include + +static DEFINE_SPINLOCK(pvsched_drv_list_lock); +static int nr_pvsched_drivers =3D 0; +static LIST_HEAD(pvsched_drv_list); + +/* + * Retrieve pvsched_vcpu_ops given the name. + */ +static struct pvsched_vcpu_ops *pvsched_find_vcpu_ops_name(char *name) +{ + struct pvsched_vcpu_ops *ops; + + list_for_each_entry_rcu(ops, &pvsched_drv_list, list) { + if (strcmp(ops->name, name) =3D=3D 0) + return ops; + } + + return NULL; +} + +/* + * Retrieve pvsched_vcpu_ops given the hash key. + */ +static struct pvsched_vcpu_ops *pvsched_find_vcpu_ops_key(u32 key) +{ + struct pvsched_vcpu_ops *ops; + + list_for_each_entry_rcu(ops, &pvsched_drv_list, list) { + if (ops->key =3D=3D key) + return ops; + } + + return NULL; +} + +/* + * pvsched_get_available_drivers() - Copy space separated list of pvsched + * driver names. + * @buf: buffer to store the list of driver names + * @maxlen: size of the buffer + * + * Return: 0 on success, negative value on error. + */ +int pvsched_get_available_drivers(char *buf, size_t maxlen) +{ + struct pvsched_vcpu_ops *ops; + size_t offs =3D 0; + + if (!buf) + return -EINVAL; + + if (maxlen > PVSCHED_DRV_BUF_MAX) + maxlen =3D PVSCHED_DRV_BUF_MAX; + + rcu_read_lock(); + list_for_each_entry_rcu(ops, &pvsched_drv_list, list) { + offs +=3D snprintf(buf + offs, maxlen - offs, + "%s%s", + offs =3D=3D 0 ? "" : " ", ops->name); + + if (WARN_ON_ONCE(offs >=3D maxlen)) + break; + } + rcu_read_unlock(); + + return 0; +} +EXPORT_SYMBOL_GPL(pvsched_get_available_drivers); + +/* + * pvsched_register_vcpu_ops() - Register the driver in the kernel. + * @ops: Driver data(callbacks) + * + * After the registration, driver will be exposed to the hypervisor + * for assignment to the guest VMs. + * + * Return: 0 on success, negative value on error. + */ +int pvsched_register_vcpu_ops(struct pvsched_vcpu_ops *ops) +{ + int ret =3D 0; + + ops->key =3D jhash(ops->name, sizeof(ops->name), strlen(ops->name)); + spin_lock(&pvsched_drv_list_lock); + if (nr_pvsched_drivers > PVSCHED_MAX) { + ret =3D -ENOSPC; + } if (pvsched_find_vcpu_ops_key(ops->key)) { + ret =3D -EEXIST; + } else if (!(ret =3D pvsched_validate_vcpu_ops(ops))) { + list_add_tail_rcu(&ops->list, &pvsched_drv_list); + nr_pvsched_drivers++; + } + spin_unlock(&pvsched_drv_list_lock); + + return ret; +} +EXPORT_SYMBOL_GPL(pvsched_register_vcpu_ops); + +/* + * pvsched_register_vcpu_ops() - Un-register the driver from the kernel. + * @ops: Driver data(callbacks) + * + * After un-registration, driver will not be visible to hypervisor. + */ +void pvsched_unregister_vcpu_ops(struct pvsched_vcpu_ops *ops) +{ + spin_lock(&pvsched_drv_list_lock); + list_del_rcu(&ops->list); + nr_pvsched_drivers--; + spin_unlock(&pvsched_drv_list_lock); + + synchronize_rcu(); +} +EXPORT_SYMBOL_GPL(pvsched_unregister_vcpu_ops); + +/* + * pvsched_get_vcpu_ops: Acquire the driver. + * @name: Name of the driver to be acquired. + * + * Hypervisor can use this API to get the driver structure for + * assigning it to guest VMs. This API takes a reference on the + * module/bpf program so that driver doesn't vanish under the + * hypervisor. + * + * Return: driver structure if found, else NULL. + */ +struct pvsched_vcpu_ops *pvsched_get_vcpu_ops(char *name) +{ + struct pvsched_vcpu_ops *ops; + + if (!name || (strlen(name) >=3D PVSCHED_NAME_MAX)) + return NULL; + + rcu_read_lock(); + ops =3D pvsched_find_vcpu_ops_name(name); + if (!ops) + goto out; + + if (unlikely(!bpf_try_module_get(ops, ops->owner))) { + ops =3D NULL; + goto out; + } + +out: + rcu_read_unlock(); + return ops; +} +EXPORT_SYMBOL_GPL(pvsched_get_vcpu_ops); + +/* + * pvsched_put_vcpu_ops: Release the driver. + * @name: Name of the driver to be releases. + * + * Hypervisor can use this API to release the driver. + */ +void pvsched_put_vcpu_ops(struct pvsched_vcpu_ops *ops) +{ + bpf_module_put(ops, ops->owner); +} +EXPORT_SYMBOL_GPL(pvsched_put_vcpu_ops); + +/* + * NOP vm_ops Sample implementation. + * This driver doesn't do anything other than registering itself. + * Placeholder for adding some default logic when the feature is + * complete. + */ +static int nop_pvsched_vcpu_register(struct pid *pid) +{ + return 0; +} +static void nop_pvsched_vcpu_unregister(struct pid *pid) +{ +} +static void nop_pvsched_notify_event(void *addr, struct pid *pid, u32 even= t) +{ +} + +struct pvsched_vcpu_ops nop_vcpu_ops =3D { + .events =3D PVSCHED_VCPU_VMENTER | PVSCHED_VCPU_VMEXIT | PVSCHED_VCPU_HAL= T, + .pvsched_vcpu_register =3D nop_pvsched_vcpu_register, + .pvsched_vcpu_unregister =3D nop_pvsched_vcpu_unregister, + .pvsched_vcpu_notify_event =3D nop_pvsched_notify_event, + .name =3D "pvsched_nop", + .owner =3D THIS_MODULE, +}; + +static int __init pvsched_init(void) +{ + return WARN_ON(pvsched_register_vcpu_ops(&nop_vcpu_ops)); +} + +late_initcall(pvsched_init); --=20 2.40.1 From nobody Mon Feb 9 19:25:43 2026 Received: from mail-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) (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 2BEA7149016 for ; Wed, 3 Apr 2024 14:01:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712152888; cv=none; b=kfywfsLBENM7SzM0C1OvdwObtPZvpfaSX8bB6ioPcbXWtOsan0PBh6a2ksaMHscAoNKZc3hvtpSNSVnCMQX5b5B6XJklBH1uOiIpn8XQuD6CuXk3GK2IFhSGcbw5tfo64oQORzZSXKYZNtPjRYy3JjqdxhEh6Aq/jSHEG6pJVVs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712152888; c=relaxed/simple; bh=TDctzrjvOyJsGkgtTdTPKD3E/sGdBBWNU2PAEkT4FWw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SLbqt7OmGFz36ccjWkBXjLeN8U7C/rFuACrXJjSfRXCooWp87GIo+uBcMz2RPGqhRSqN08tPpj9ta+ItkHlbRThDdSP7X0LMThifpjsLmsUiAugmY6jvPcXtkmcIIvfbKNkT1zSwwnkHk2/vDpoD+Qnjay1qsw9i8jyK+l/vBFE= 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=JH9KYukU; arc=none smtp.client-ip=209.85.219.52 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bitbyteword.org header.i=@bitbyteword.org header.b="JH9KYukU" Received: by mail-qv1-f52.google.com with SMTP id 6a1803df08f44-6992d8e7e6dso832556d6.0 for ; Wed, 03 Apr 2024 07:01:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bitbyteword.org; s=google; t=1712152885; x=1712757685; 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=/BPGVzMI1+eo9yvIAgnlTxqk+J0LKPxHXNZYDNRJA58=; b=JH9KYukU0oTCHZDEXfYpMIVEVyCtwpFQMM6lm1YY/9JXIcKNCh/Y4EHvwHXbqt7R/4 fJ8avagTe7AKzsl5yQxW/IRyoPOqTWhnNwznhHn/ooov6AULZBak0k68dKKa58jJ0vYc cy+3FI7DQjSnugPZsk1ilrIeoBJdbRRq7JjS0p+OBCYP75NikQ9NfnWSNfDv6kbRm0V6 ERYOR9M6GuYi3KiJk958KYx1NxHYX5GIkk0MMcm5h6C/t6l937gvr/slczv6dioileq8 i6eHTCmYstWhbg25ZLXSro6urFSxJrJY0xnavry+h9hZH4LjRFZqpt6uy7mN1MYbyL3J aOZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712152885; x=1712757685; 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=/BPGVzMI1+eo9yvIAgnlTxqk+J0LKPxHXNZYDNRJA58=; b=uPkz9fvsYGCiKMG5ybEfi3j3/llWyAH2QhEBWOBFxLx+EcTRB4eeqrfEmxS8P7WH/H y0PvIBAc43LlEuqXGw2Ng/iLkBWrtmpJdvgIQpxuqAssFN3BnJbAUYD9NKrzM5P238cw 6DMAnAkqDvFwS1IAgFoS4eTmTvK2+750ABrzQQDjE9zZ0mpeH49QpOZ/RiefBn9rTlwC /8A2P9A309Il3ovWSvi5x8s0G8OzrlzBTSBpDZOHa0bqiAcUrQmx+JeHhZycku1LATb9 7HX7drTlK48WNFv0V3TBnWPERkVoUpNIz1xFHiwKOCD0NIGZa0Yrq/JErWgUlxp7NDIz ipvw== X-Forwarded-Encrypted: i=1; AJvYcCU8h0kQQG0Ti3mx8ENbQit7CqyIFAsd/3OzecBjo0jb1qy4t9pA8aRaRDkrX2imeHoC9xHDKGfAQV+WsRra1tAf2NWAGwDo3PHOyluQ X-Gm-Message-State: AOJu0Yw3BxA2JgVXRAAgpe1BXR5YGoVA0QnfhmQHZuLUlFwgVb70Z/w5 4D7gCoZGBSjTmTlZjSdrOypEVRpXBeenuy8KZQ9YED1HxcGxnygyRYOyhNkHcAU= X-Google-Smtp-Source: AGHT+IGFZcEaZ2LTTabAkPrVqPjWtdW/Cz0Il+zhLsM9yKyyKZpea5NsINjyFBJZ577Vil8whyw/9g== X-Received: by 2002:a0c:c249:0:b0:699:1fd3:95a3 with SMTP id w9-20020a0cc249000000b006991fd395a3mr3804251qvh.24.1712152884922; Wed, 03 Apr 2024 07:01:24 -0700 (PDT) Received: from vinbuntup3.lan (c-73-143-21-186.hsd1.vt.comcast.net. [73.143.21.186]) by smtp.gmail.com with ESMTPSA id gf12-20020a056214250c00b00698d06df322sm5945706qvb.122.2024.04.03.07.01.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 07:01:24 -0700 (PDT) From: "Vineeth Pillai (Google)" 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: "Vineeth Pillai (Google)" , Steven Rostedt , Joel Fernandes , Suleiman Souhlal , Masami Hiramatsu , himadrics@inria.fr, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Subject: [RFC PATCH v2 2/5] kvm: Implement the paravirt sched framework for kvm Date: Wed, 3 Apr 2024 10:01:13 -0400 Message-Id: <20240403140116.3002809-3-vineeth@bitbyteword.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240403140116.3002809-1-vineeth@bitbyteword.org> References: <20240403140116.3002809-1-vineeth@bitbyteword.org> 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" kvm uses the kernel's paravirt sched framework to assign an available pvsched driver for a guest. guest vcpus registers with the pvsched driver and calls into the driver callback to notify the events that the driver is interested in. This PoC doesn't do the callback on interrupt injection yet. Will be implemented in subsequent iterations. Signed-off-by: Vineeth Pillai (Google) Signed-off-by: Joel Fernandes (Google) --- arch/x86/kvm/Kconfig | 13 ++++ arch/x86/kvm/x86.c | 3 + include/linux/kvm_host.h | 32 +++++++++ virt/kvm/kvm_main.c | 148 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 196 insertions(+) diff --git a/arch/x86/kvm/Kconfig b/arch/x86/kvm/Kconfig index 65ed14b6540b..c1776cdb5b65 100644 --- a/arch/x86/kvm/Kconfig +++ b/arch/x86/kvm/Kconfig @@ -189,4 +189,17 @@ config KVM_MAX_NR_VCPUS the memory footprint of each KVM guest, regardless of how many vCPUs are created for a given VM. =20 +config PARAVIRT_SCHED_KVM + bool "Enable paravirt scheduling capability for kvm" + depends on KVM + default n + help + Paravirtualized scheduling facilitates the exchange of scheduling + related information between the host and guest through shared memory, + enhancing the efficiency of vCPU thread scheduling by the hypervisor. + An illustrative use case involves dynamically boosting the priority of + a vCPU thread when the guest is executing a latency-sensitive workload + on that specific vCPU. + This config enables paravirt scheduling in the kvm hypervisor. + endif # VIRTUALIZATION diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index ffe580169c93..d0abc2c64d47 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -10896,6 +10896,8 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) =20 preempt_disable(); =20 + kvm_vcpu_pvsched_notify(vcpu, PVSCHED_VCPU_VMENTER); + static_call(kvm_x86_prepare_switch_to_guest)(vcpu); =20 /* @@ -11059,6 +11061,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) guest_timing_exit_irqoff(); =20 local_irq_enable(); + kvm_vcpu_pvsched_notify(vcpu, PVSCHED_VCPU_VMEXIT); preempt_enable(); =20 kvm_vcpu_srcu_read_lock(vcpu); diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 179df96b20f8..6381569f3de8 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -45,6 +45,8 @@ #include #include =20 +#include + #ifndef KVM_MAX_VCPU_IDS #define KVM_MAX_VCPU_IDS KVM_MAX_VCPUS #endif @@ -832,6 +834,11 @@ struct kvm { bool vm_bugged; bool vm_dead; =20 +#ifdef CONFIG_PARAVIRT_SCHED_KVM + spinlock_t pvsched_ops_lock; + struct pvsched_vcpu_ops __rcu *pvsched_ops; +#endif + #ifdef CONFIG_HAVE_KVM_PM_NOTIFIER struct notifier_block pm_notifier; #endif @@ -2413,4 +2420,29 @@ static inline int kvm_gmem_get_pfn(struct kvm *kvm, } #endif /* CONFIG_KVM_PRIVATE_MEM */ =20 +#ifdef CONFIG_PARAVIRT_SCHED_KVM +int kvm_vcpu_pvsched_notify(struct kvm_vcpu *vcpu, u32 events); +int kvm_vcpu_pvsched_register(struct kvm_vcpu *vcpu); +void kvm_vcpu_pvsched_unregister(struct kvm_vcpu *vcpu); + +int kvm_replace_pvsched_ops(struct kvm *kvm, char *name); +#else +static inline int kvm_vcpu_pvsched_notify(struct kvm_vcpu *vcpu, u32 event= s) +{ + return 0; +} +static inline int kvm_vcpu_pvsched_register(struct kvm_vcpu *vcpu) +{ + return 0; +} +static inline void kvm_vcpu_pvsched_unregister(struct kvm_vcpu *vcpu) +{ +} + +static inline int kvm_replace_pvsched_ops(struct kvm *kvm, char *name) +{ + return 0; +} +#endif + #endif diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 0f50960b0e3a..0546814e4db7 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -170,6 +170,142 @@ bool kvm_is_zone_device_page(struct page *page) return is_zone_device_page(page); } =20 +#ifdef CONFIG_PARAVIRT_SCHED_KVM +typedef enum { + PVSCHED_CB_REGISTER =3D 1, + PVSCHED_CB_UNREGISTER =3D 2, + PVSCHED_CB_NOTIFY =3D 3 +} pvsched_vcpu_callback_t; + +/* + * Helper function to invoke the pvsched driver callback. + */ +static int __vcpu_pvsched_callback(struct kvm_vcpu *vcpu, u32 events, + pvsched_vcpu_callback_t action) +{ + int ret =3D 0; + struct pid *pid; + struct pvsched_vcpu_ops *ops; + + rcu_read_lock(); + ops =3D rcu_dereference(vcpu->kvm->pvsched_ops); + if (!ops) { + ret =3D -ENOENT; + goto out; + } + + pid =3D rcu_dereference(vcpu->pid); + if (WARN_ON_ONCE(!pid)) { + ret =3D -EINVAL; + goto out; + } + get_pid(pid); + switch(action) { + case PVSCHED_CB_REGISTER: + ops->pvsched_vcpu_register(pid); + break; + case PVSCHED_CB_UNREGISTER: + ops->pvsched_vcpu_unregister(pid); + break; + case PVSCHED_CB_NOTIFY: + if (ops->events & events) { + ops->pvsched_vcpu_notify_event( + NULL, /* TODO: Pass guest allocated sharedmem addr */ + pid, + ops->events & events); + } + break; + default: + WARN_ON_ONCE(1); + } + put_pid(pid); + +out: + rcu_read_unlock(); + return ret; +} + +int kvm_vcpu_pvsched_notify(struct kvm_vcpu *vcpu, u32 events) +{ + return __vcpu_pvsched_callback(vcpu, events, PVSCHED_CB_NOTIFY); +} + +int kvm_vcpu_pvsched_register(struct kvm_vcpu *vcpu) +{ + return __vcpu_pvsched_callback(vcpu, 0, PVSCHED_CB_REGISTER); + /* + * TODO: Action if the registration fails? + */ +} + +void kvm_vcpu_pvsched_unregister(struct kvm_vcpu *vcpu) +{ + __vcpu_pvsched_callback(vcpu, 0, PVSCHED_CB_UNREGISTER); +} + +/* + * Replaces the VM's current pvsched driver. + * if name is NULL or empty string, unassign the + * current driver. + */ +int kvm_replace_pvsched_ops(struct kvm *kvm, char *name) +{ + int ret =3D 0; + unsigned long i; + struct kvm_vcpu *vcpu =3D NULL; + struct pvsched_vcpu_ops *ops =3D NULL, *prev_ops; + + + spin_lock(&kvm->pvsched_ops_lock); + + prev_ops =3D rcu_dereference(kvm->pvsched_ops); + + /* + * Unassign operation if the passed in value is + * NULL or an empty string. + */ + if (name && *name) { + ops =3D pvsched_get_vcpu_ops(name); + if (!ops) { + ret =3D -EINVAL; + goto out; + } + } + + if (prev_ops) { + /* + * Unregister current pvsched driver. + */ + kvm_for_each_vcpu(i, vcpu, kvm) { + kvm_vcpu_pvsched_unregister(vcpu); + } + + pvsched_put_vcpu_ops(prev_ops); + } + + + rcu_assign_pointer(kvm->pvsched_ops, ops); + if (ops) { + /* + * Register new pvsched driver. + */ + kvm_for_each_vcpu(i, vcpu, kvm) { + WARN_ON_ONCE(kvm_vcpu_pvsched_register(vcpu)); + } + } + +out: + spin_unlock(&kvm->pvsched_ops_lock); + + if (ret) + return ret; + + synchronize_rcu(); + + return 0; +} +#endif + /* * Returns a 'struct page' if the pfn is "valid" and backed by a refcounted * page, NULL otherwise. Note, the list of refcounted PG_reserved page ty= pes @@ -508,6 +644,8 @@ static void kvm_vcpu_destroy(struct kvm_vcpu *vcpu) kvm_arch_vcpu_destroy(vcpu); kvm_dirty_ring_free(&vcpu->dirty_ring); =20 + kvm_vcpu_pvsched_unregister(vcpu); + /* * No need for rcu_read_lock as VCPU_RUN is the only place that changes * the vcpu->pid pointer, and at destruction time all file descriptors @@ -1221,6 +1359,10 @@ static struct kvm *kvm_create_vm(unsigned long type,= const char *fdname) =20 BUILD_BUG_ON(KVM_MEM_SLOTS_NUM > SHRT_MAX); =20 +#ifdef CONFIG_PARAVIRT_SCHED_KVM + spin_lock_init(&kvm->pvsched_ops_lock); +#endif + /* * Force subsequent debugfs file creations to fail if the VM directory * is not created (by kvm_create_vm_debugfs()). @@ -1343,6 +1485,8 @@ static void kvm_destroy_vm(struct kvm *kvm) int i; struct mm_struct *mm =3D kvm->mm; =20 + kvm_replace_pvsched_ops(kvm, NULL); + kvm_destroy_pm_notifier(kvm); kvm_uevent_notify_change(KVM_EVENT_DESTROY_VM, kvm); kvm_destroy_vm_debugfs(kvm); @@ -3779,6 +3923,8 @@ bool kvm_vcpu_block(struct kvm_vcpu *vcpu) if (kvm_vcpu_check_block(vcpu) < 0) break; =20 + kvm_vcpu_pvsched_notify(vcpu, PVSCHED_VCPU_HALT); + waited =3D true; schedule(); } @@ -4434,6 +4580,7 @@ static long kvm_vcpu_ioctl(struct file *filp, /* The thread running this VCPU changed. */ struct pid *newpid; =20 + kvm_vcpu_pvsched_unregister(vcpu); r =3D kvm_arch_vcpu_run_pid_change(vcpu); if (r) break; @@ -4442,6 +4589,7 @@ static long kvm_vcpu_ioctl(struct file *filp, rcu_assign_pointer(vcpu->pid, newpid); if (oldpid) synchronize_rcu(); + kvm_vcpu_pvsched_register(vcpu); put_pid(oldpid); } r =3D kvm_arch_vcpu_ioctl_run(vcpu); --=20 2.40.1 From nobody Mon Feb 9 19:25:43 2026 Received: from mail-qv1-f50.google.com (mail-qv1-f50.google.com [209.85.219.50]) (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 BDD0A148FFA for ; Wed, 3 Apr 2024 14:01:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712152899; cv=none; b=fmcyS0RGlgXSx51qMTPkb3fFumGmvF1892bQibCA4uS2TeYhDXMC15lQMpCy3dWJiVr6PI3pBIhDvhka6XteIk+eRb57ZaWN2A3lVIRxTsD7b087pKXwwN78ZBvAZD6XnYn/o4fdo0SaRkTFXILjvQKjKQr22RzUSk3FZY31zps= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712152899; c=relaxed/simple; bh=FDYnvGX3jppgjt0ms5JcBF+Jc7zw8R2BAEn2b+ABJPI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=a5e3GzDCMt/d6TtZlqzFFDo85txyVJO6Lk4b0FJk9XzMmzoxO01ksmHDsHDU7DeBLeOLjxUE/4SnZxMluxn2cU2zp7ncyg+a+1Gk5JSe06Bn/IYlV3/MAoFdj6ooznTlwqACuhRNWldN2tq/bwTzDbVUf5TDHC1XZwYn3WtVmjU= 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=GnE3S7hQ; arc=none smtp.client-ip=209.85.219.50 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bitbyteword.org header.i=@bitbyteword.org header.b="GnE3S7hQ" Received: by mail-qv1-f50.google.com with SMTP id 6a1803df08f44-6991fb8f31dso8922116d6.1 for ; Wed, 03 Apr 2024 07:01:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bitbyteword.org; s=google; t=1712152896; x=1712757696; 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=RAl5yGyZgzeKDHOgPfwgCPdv3gtVirZpx2WY36IzrFA=; b=GnE3S7hQtlBzz5FDFR9gGbJi5gW9SwyzYiv5Lg6Q1W42Y+3WljBLh8H/viIHOSpZ5l mDtivDKn/qfjy5Nfes5lqHs8B6ZSdovK1C7WqAOxe9PWOUhtdDmaN60MohYRrYZKqovC xMurIZIP5Hx0a3gi1yIJbQaOCkHha8SO7T1UXR/e50/xKFS0aFnjhDQKezyWPyE6+pJR cAwFj/QTrvFtCz34A5TfhcSpUZzQrZAWvviCr4vkw2Lf+tvu0ncbu3Kyowm+B59NCBKq FrUcar++MI6oumNg1ElnfIBMhGQbZPXDKKb8yyPezo5zk/4KTBRQd3iBdSxqneOeUGul I3Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712152896; x=1712757696; 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=RAl5yGyZgzeKDHOgPfwgCPdv3gtVirZpx2WY36IzrFA=; b=MN3V//43/NHxXo1BCxbI65iL7Lwf0DprvkBBf6V5U9n96GJcWD0SMGus/GBuoyp/yB F4jqXnYfqgZZdblzVaOyDtP48aT9kK1rdr0LUGRyGtq3SsuwCkSL0XwbN8PU8tPmuFDk ehh9lLQQcaXEfQgEmZvgBKKpllX0AY7l757m/Xdh4i3dd2ZPYnA7zg33zdfJWNEHT19F PFLvaTKp1U+prYAU56igdUJ+pBUvvCZAYGzArlH2s2llYeZ+lCi0fAjVdnMe9BL6IoSm fQJLFdpKlB0XEtYgTr8n38udCT5WbWzyG+zDvBR7e2JP5GhuKCtZZldHOwKi71cpgbwL xrcQ== X-Forwarded-Encrypted: i=1; AJvYcCXzPe5SAfA2arHHgedqaJKaSlFTp/W94fCb9BDNjUcuO4P6shQwmlwVWnGtuRAd6Q49b9mlORzOcEBih5Z5OhrDeWfMpk90x6rTEB78 X-Gm-Message-State: AOJu0Yy3+V0rGCh4/mPhzGAxKjZvp9XU5ocWoIpXq10ngObshAIsiPdC eXGcHnPS/OY6wRibXaO11Vw0kxeNFi6yVGwbRDdT8UlTY01+9yJMOZj8JzMzeIE= X-Google-Smtp-Source: AGHT+IHvc+Z8rAGYdV18GoHSVhAuEJhixIxtB7Sprh49Rl10nkC3+gtuPFpYpMsM5sh5ZkIdR/76QA== X-Received: by 2002:a0c:ed4e:0:b0:699:1b6b:82ae with SMTP id v14-20020a0ced4e000000b006991b6b82aemr4264059qvq.17.1712152896489; Wed, 03 Apr 2024 07:01:36 -0700 (PDT) Received: from vinbuntup3.lan (c-73-143-21-186.hsd1.vt.comcast.net. [73.143.21.186]) by smtp.gmail.com with ESMTPSA id gf12-20020a056214250c00b00698d06df322sm5945706qvb.122.2024.04.03.07.01.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 07:01:26 -0700 (PDT) From: "Vineeth Pillai (Google)" 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: "Vineeth Pillai (Google)" , Steven Rostedt , Joel Fernandes , Suleiman Souhlal , Masami Hiramatsu , himadrics@inria.fr, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Subject: [RFC PATCH v2 3/5] kvm: interface for managing pvsched driver for guest VMs Date: Wed, 3 Apr 2024 10:01:14 -0400 Message-Id: <20240403140116.3002809-4-vineeth@bitbyteword.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240403140116.3002809-1-vineeth@bitbyteword.org> References: <20240403140116.3002809-1-vineeth@bitbyteword.org> 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" 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]; }; =20 +struct kvm_pvsched_ops { + __u8 ops_name[32]; /* PVSCHED_NAME_MAX */ +}; + +#define KVM_GET_PVSCHED_OPS _IOR(KVMIO, 0xe4, struct kvm_pvsched_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) } } =20 +#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, con= st char *fdname) &stat_fops_per_vm); } =20 + 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_name); + 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); --=20 2.40.1 From nobody Mon Feb 9 19:25:43 2026 Received: from mail-ot1-f43.google.com (mail-ot1-f43.google.com [209.85.210.43]) (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 6A9A0149016 for ; Wed, 3 Apr 2024 14:01:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712152901; cv=none; b=YbRuhW4ZyUS6ARBu8mEgNCGiRSlp5wYwIhnuF9g1UfxOMiJGyR65Y4h/Gas07FEZ0j3wpW9Nx4zLIGQ1CsVEMIn95jTl6qLNJCnc8bNqYw8ai/Qsk6rfE/IzxiAVi5eIJmnu0IY9p3RUuHLq88+ks1ZbJnSNmcJx2tK7ur76ARw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712152901; c=relaxed/simple; bh=OKezwxiOEiM9+urpB8402BC4SYCwdxDMf8Df/ISZUg0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NASeRn74gMlerpSlJ0gu9FcyuNZ2rYANCjBLP1l+LAqtuCFQgF3+g5K2EETeNY0DhIoLyUl0zw02SZS+cGWiwwFgmFjNM49rpJX1JFxVXYBUonrnRriNqQKZgrAJdukeC6AK9Moh02tmdDE+gK104ECEx9ViDQaK39Yix4wpIV8= 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=WMp4O7B5; arc=none smtp.client-ip=209.85.210.43 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bitbyteword.org header.i=@bitbyteword.org header.b="WMp4O7B5" Received: by mail-ot1-f43.google.com with SMTP id 46e09a7af769-6e89c87a72eso2387023a34.0 for ; Wed, 03 Apr 2024 07:01:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bitbyteword.org; s=google; t=1712152898; x=1712757698; 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=7VOPM+Isn3puOfkfBMYmv3GVLrqplGzQJegeaxwHn/Q=; b=WMp4O7B5HDNF80hOnwY5oOBZPer+2V1WRXTDTQT+cwY/5Cp1SOsxpk21d9uLih02gC i3HfmYuFYntSuHtC6fOXuoghrDCsR/ezPt2osU/0qs0+CrLfVRKFBQaFcC2ubd3Cv0j0 OTAk+xd8LkK+LnurhzJ9SHITRLBcizvh+kpaaEEDYFSP5+KmFWikp7rBE+xXCFFJHzq5 YNL1dfIr5zpiO3vMAjMka2haB7oOhSztdMHPW51sLHhEcXe2yPb1gOEV494VBQ7k5oTM BeR+WgPLfBFEdcsw0oKznFwshw8vIPxXpG3etMx1YOvEU4wB84e9Q+VpV9aFtgiuwXSS /iSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712152898; x=1712757698; 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=7VOPM+Isn3puOfkfBMYmv3GVLrqplGzQJegeaxwHn/Q=; b=HBRO/flMpJlxZ76AQ/m56/CWVRpSb56QGgp1oLbneztg3azjDfolS0ZJqKk22uziqT p8DWoI2A6xYEaEjMqhc0UVwzK6exAIOzF1Ncr88yDmutxNvhrHIpdlVIqWSouP0APk9q X5NSwYOonsEmxUBDeylBE3D1FbD1L9h6n1eBFeXMWxmIij1Q7flosn2w0OmitaLQIIcr zuYDDrDOhrIzJUpBKesnyA1GDJvWxNctixDJRntUFyZjqKP9OCaQ98nLVJR64Ubxc42z 2WrPLZISAqtW8hXQKpkuUWSD3Vq2T8HDOYe4XRKqBlb7E+49mxzu5DpoKNGnDv5KcrXc fiBA== X-Forwarded-Encrypted: i=1; AJvYcCXqzmX6CBDKjL1T3GRr1qegIzKF/lVraYbL8bJc69xR+CfKPmH4m38MvGvvW8i4W9RFz9BjxZu2sFEtYRbCaZAIsS+leJzE1lbf5vzx X-Gm-Message-State: AOJu0YzXou74LeAoUPEasZ/JeEo1KU8GOa2ryvlTrYCs3wMaQ6y/YFMW gmi8jb7axOiX+SkChLtfexs/NjbkxX0g1mjSQJuPvmNruPkV0BUEuFzLGwkylMw= X-Google-Smtp-Source: AGHT+IFVHhEadwy+vYVbpR80h1N15BwjLDnooutKSgc1bq6Ce0yAUhvCgcTFJsTJXfmfWJbdINes4g== X-Received: by 2002:a05:6830:a44:b0:6e6:d1ac:c989 with SMTP id g4-20020a0568300a4400b006e6d1acc989mr15963532otu.6.1712152898445; Wed, 03 Apr 2024 07:01:38 -0700 (PDT) Received: from vinbuntup3.lan (c-73-143-21-186.hsd1.vt.comcast.net. [73.143.21.186]) by smtp.gmail.com with ESMTPSA id gf12-20020a056214250c00b00698d06df322sm5945706qvb.122.2024.04.03.07.01.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 07:01:38 -0700 (PDT) From: "Vineeth Pillai (Google)" 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: "Vineeth Pillai (Google)" , Steven Rostedt , Joel Fernandes , Suleiman Souhlal , Masami Hiramatsu , himadrics@inria.fr, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Subject: [RFC PATCH v2 4/5] pvsched: bpf support for pvsched Date: Wed, 3 Apr 2024 10:01:15 -0400 Message-Id: <20240403140116.3002809-5-vineeth@bitbyteword.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240403140116.3002809-1-vineeth@bitbyteword.org> References: <20240403140116.3002809-1-vineeth@bitbyteword.org> 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" Add support for implementing bpf pvsched drivers. bpf programs can use the struct_ops to define the callbacks of pvsched drivers. This is only a skeleton of the bpf framework for pvsched. Some verification details are not implemented yet. Signed-off-by: Vineeth Pillai (Google) Signed-off-by: Joel Fernandes (Google) --- kernel/bpf/bpf_struct_ops_types.h | 4 + virt/pvsched/Makefile | 2 +- virt/pvsched/pvsched_bpf.c | 141 ++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 virt/pvsched/pvsched_bpf.c diff --git a/kernel/bpf/bpf_struct_ops_types.h b/kernel/bpf/bpf_struct_ops_= types.h index 5678a9ddf817..9d5e4d1a331a 100644 --- a/kernel/bpf/bpf_struct_ops_types.h +++ b/kernel/bpf/bpf_struct_ops_types.h @@ -9,4 +9,8 @@ BPF_STRUCT_OPS_TYPE(bpf_dummy_ops) #include BPF_STRUCT_OPS_TYPE(tcp_congestion_ops) #endif +#ifdef CONFIG_PARAVIRT_SCHED_HOST +#include +BPF_STRUCT_OPS_TYPE(pvsched_vcpu_ops) +#endif #endif diff --git a/virt/pvsched/Makefile b/virt/pvsched/Makefile index 4ca38e30479b..02bc072cd806 100644 --- a/virt/pvsched/Makefile +++ b/virt/pvsched/Makefile @@ -1,2 +1,2 @@ =20 -obj-$(CONFIG_PARAVIRT_SCHED_HOST) +=3D pvsched.o +obj-$(CONFIG_PARAVIRT_SCHED_HOST) +=3D pvsched.o pvsched_bpf.o diff --git a/virt/pvsched/pvsched_bpf.c b/virt/pvsched/pvsched_bpf.c new file mode 100644 index 000000000000..b125089abc3b --- /dev/null +++ b/virt/pvsched/pvsched_bpf.c @@ -0,0 +1,141 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2024 Google */ + +#include +#include +#include +#include +#include +#include + + +/* "extern" is to avoid sparse warning. It is only used in bpf_struct_ops= .c. */ +extern struct bpf_struct_ops bpf_pvsched_vcpu_ops; + +static int bpf_pvsched_vcpu_init(struct btf *btf) +{ + return 0; +} + +static bool bpf_pvsched_vcpu_is_valid_access(int off, int size, + enum bpf_access_type type, + const struct bpf_prog *prog, + struct bpf_insn_access_aux *info) +{ + if (off < 0 || off >=3D sizeof(__u64) * MAX_BPF_FUNC_ARGS) + return false; + if (type !=3D BPF_READ) + return false; + if (off % size !=3D 0) + return false; + + if (!btf_ctx_access(off, size, type, prog, info)) + return false; + + return true; +} + +static int bpf_pvsched_vcpu_btf_struct_access(struct bpf_verifier_log *log, + const struct bpf_reg_state *reg, + int off, int size) +{ + /* + * TODO: Enable write access to Guest shared mem. + */ + return -EACCES; +} + +static const struct bpf_func_proto * +bpf_pvsched_vcpu_get_func_proto(enum bpf_func_id func_id, const struct bpf= _prog *prog) +{ + return bpf_base_func_proto(func_id); +} + +static const struct bpf_verifier_ops bpf_pvsched_vcpu_verifier_ops =3D { + .get_func_proto =3D bpf_pvsched_vcpu_get_func_proto, + .is_valid_access =3D bpf_pvsched_vcpu_is_valid_access, + .btf_struct_access =3D bpf_pvsched_vcpu_btf_struct_access, +}; + +static int bpf_pvsched_vcpu_init_member(const struct btf_type *t, + const struct btf_member *member, + void *kdata, const void *udata) +{ + const struct pvsched_vcpu_ops *uvm_ops; + struct pvsched_vcpu_ops *vm_ops; + u32 moff; + + uvm_ops =3D (const struct pvsched_vcpu_ops *)udata; + vm_ops =3D (struct pvsched_vcpu_ops *)kdata; + + moff =3D __btf_member_bit_offset(t, member) / 8; + switch (moff) { + case offsetof(struct pvsched_vcpu_ops, events): + vm_ops->events =3D *(u32 *)(udata + moff); + return 1; + case offsetof(struct pvsched_vcpu_ops, name): + if (bpf_obj_name_cpy(vm_ops->name, uvm_ops->name, + sizeof(vm_ops->name)) <=3D 0) + return -EINVAL; + return 1; + } + + return 0; +} + +static int bpf_pvsched_vcpu_check_member(const struct btf_type *t, + const struct btf_member *member, + const struct bpf_prog *prog) +{ + return 0; +} + +static int bpf_pvsched_vcpu_reg(void *kdata) +{ + return pvsched_register_vcpu_ops((struct pvsched_vcpu_ops *)kdata); +} + +static void bpf_pvsched_vcpu_unreg(void *kdata) +{ + pvsched_unregister_vcpu_ops((struct pvsched_vcpu_ops *)kdata); +} + +static int bpf_pvsched_vcpu_validate(void *kdata) +{ + return pvsched_validate_vcpu_ops((struct pvsched_vcpu_ops *)kdata); +} + +static int bpf_pvsched_vcpu_update(void *kdata, void *old_kdata) +{ + return -EOPNOTSUPP; +} + +static int __pvsched_vcpu_register(struct pid *pid) +{ + return 0; +} +static void __pvsched_vcpu_unregister(struct pid *pid) +{ +} +static void __pvsched_notify_event(void *addr, struct pid *pid, u32 event) +{ +} + +static struct pvsched_vcpu_ops __bpf_ops_pvsched_vcpu_ops =3D { + .pvsched_vcpu_register =3D __pvsched_vcpu_register, + .pvsched_vcpu_unregister =3D __pvsched_vcpu_unregister, + .pvsched_vcpu_notify_event =3D __pvsched_notify_event, +}; + +struct bpf_struct_ops bpf_pvsched_vcpu_ops =3D { + .init =3D &bpf_pvsched_vcpu_init, + .validate =3D bpf_pvsched_vcpu_validate, + .update =3D bpf_pvsched_vcpu_update, + .verifier_ops =3D &bpf_pvsched_vcpu_verifier_ops, + .reg =3D bpf_pvsched_vcpu_reg, + .unreg =3D bpf_pvsched_vcpu_unreg, + .check_member =3D bpf_pvsched_vcpu_check_member, + .init_member =3D bpf_pvsched_vcpu_init_member, + .name =3D "pvsched_vcpu_ops", + .cfi_stubs =3D &__bpf_ops_pvsched_vcpu_ops, +}; --=20 2.40.1 From nobody Mon Feb 9 19:25:43 2026 Received: from mail-qv1-f43.google.com (mail-qv1-f43.google.com [209.85.219.43]) (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 438CE149E11 for ; Wed, 3 Apr 2024 14:01:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712152903; cv=none; b=nSMzsi/8yLoU2/zMKVI9cxu97aaKrAGHSOfmUaQbW4cWuFPKKrWRRWABzLE7TIIJT/47O1uMxSXECitVilL2jOodCWh1M/BhkpzTZD163GJdXBaCdYOmQU5qk1XYMcCP5Ebow8n1CI+yxZIJyd6p3Xqbz47n/TxXMpd9LPIF308= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712152903; c=relaxed/simple; bh=+HycdZGuj5OU1W/c5yOM/8/+whc2oRxO0Toug1yf4G8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iu1aOI7qLte775pB+Z61UjgZkWXNjEpz+vEJdF7F+L/tzbo3apR8lhGVJnSDvFVbiTV9axSfu4tRkMR1VJQ6kiCkGO8KrpE/gJCluc/yR1xulXhxolQv57gdEDszE+KygRXb8kRjYb0kPF9tEchkyGyhVcE0xwUUuys+Z3XEmd0= 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=Xn8IhRa6; arc=none smtp.client-ip=209.85.219.43 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bitbyteword.org header.i=@bitbyteword.org header.b="Xn8IhRa6" Received: by mail-qv1-f43.google.com with SMTP id 6a1803df08f44-690c43c5b5aso36652786d6.1 for ; Wed, 03 Apr 2024 07:01:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bitbyteword.org; s=google; t=1712152900; x=1712757700; 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=QaWEC4wEGQ+YlZ6ti6+WrczlEY+i0roOx8Ci2YqikeE=; b=Xn8IhRa6Q1hH8JPkpsL76ia39K74etBsnq86QvXDJzGkDlu4UQISCgwi31tudYRt83 jPhWkuvW0WWDPNO5GqkZlkamSdX5m/51kSnDSQgYHV4I90SE59QgGnExdChoF6Hyxsy/ DEBPORJpE0l965/MP4/PLQef9cZTT3H12g9caRcNBv7jcQ5dxHGDpDKbBGyAdCqr7UmK ii2GkcFQTeoXQ0TKmt2dtFu9E3LqK/cgIBT1TdNEm8K+8WXd1kr3P+HKnrm3VftvFPtB iodG5/lerUuBzTCWeouSem4Ps7N6uKHKXjVY9g1NsXICLR9FA3KpMZ6aSUbRhyMslQY4 5ZNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712152900; x=1712757700; 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=QaWEC4wEGQ+YlZ6ti6+WrczlEY+i0roOx8Ci2YqikeE=; b=eCNGH5WDBQIti0Yk0uo6M14JcmwZzghDDbQ1CzA/frogkkJQdRK4Sd6rFF/6tTix3S OwoKme/rSP+NudwZhuR1r6TWG6+/LQMpu5KSHZj+1B78MXjkGQjgLdNBFd2LVY5e86mV sZbJw3pF9WopUFzyxbhGDYimqYX/TzPXWQtZqs1CcrPFtd992xOySlOseAouLzCf1Oui GiYXZ49iLwp5Xl9GBtM5P4ylkJmwCzYmlhLP2cPqd2FG+/czJkY+iM970Ok1d0zSc1cv riOrhtkSH6t6k5yjObvWFrM+I9SMnykqIs6R5QiNaVGIrJqbJfaFCgJTATn/+5gbU6Fv suhA== X-Forwarded-Encrypted: i=1; AJvYcCWMatoqIMnNdBxgfkHKsLlUGQpcShvodKrOnWILxChDrAMvPEeBt58P4a/rjnh69ueBm8cyyWcWjgHDrsmk8O7vFepUGwHM29646JHy X-Gm-Message-State: AOJu0Yz+h1znc3CumoDg8x1vtI+0Med956B/B+OYyMgjThHtKLwj9cuN TF0xDyNkE+vO86w8bSTY4+QFlHqV+eL6kBxcVGu22N/B75AvkKpH09gUg7aOXDc= X-Google-Smtp-Source: AGHT+IGXzY5eGF4cfLmjKD8WCxnHKVScVbM/F99svOb+MTbMgCl4GsOWSudI3dDOqx11Q2sEA8gtCA== X-Received: by 2002:a05:6214:1384:b0:699:1ad9:259 with SMTP id pp4-20020a056214138400b006991ad90259mr2834018qvb.31.1712152900149; Wed, 03 Apr 2024 07:01:40 -0700 (PDT) Received: from vinbuntup3.lan (c-73-143-21-186.hsd1.vt.comcast.net. [73.143.21.186]) by smtp.gmail.com with ESMTPSA id gf12-20020a056214250c00b00698d06df322sm5945706qvb.122.2024.04.03.07.01.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 07:01:39 -0700 (PDT) From: "Vineeth Pillai (Google)" 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: "Vineeth Pillai (Google)" , Steven Rostedt , Joel Fernandes , Suleiman Souhlal , Masami Hiramatsu , himadrics@inria.fr, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Subject: [RFC PATCH v2 5/5] selftests/bpf: sample implementation of a bpf pvsched driver. Date: Wed, 3 Apr 2024 10:01:16 -0400 Message-Id: <20240403140116.3002809-6-vineeth@bitbyteword.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240403140116.3002809-1-vineeth@bitbyteword.org> References: <20240403140116.3002809-1-vineeth@bitbyteword.org> 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" A dummy skeleton of a bpf pvsched driver. This is just for demonstration purpose and would need more work to be included as a test for this feature. Not-Signed-off-by: Vineeth Pillai (Google) --- .../testing/selftests/bpf/progs/bpf_pvsched.c | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/bpf_pvsched.c diff --git a/tools/testing/selftests/bpf/progs/bpf_pvsched.c b/tools/testin= g/selftests/bpf/progs/bpf_pvsched.c new file mode 100644 index 000000000000..a653baa3034b --- /dev/null +++ b/tools/testing/selftests/bpf/progs/bpf_pvsched.c @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2019 Facebook */ + +#include "vmlinux.h" +#include "bpf_tracing_net.h" +#include +#include + +char _license[] SEC("license") =3D "GPL"; + +SEC("struct_ops/pvsched_vcpu_reg") +int BPF_PROG(pvsched_vcpu_reg, struct pid *pid) +{ + bpf_printk("pvsched_vcpu_reg: pid: %p", pid); + return 0; +} + +SEC("struct_ops/pvsched_vcpu_unreg") +void BPF_PROG(pvsched_vcpu_unreg, struct pid *pid) +{ + bpf_printk("pvsched_vcpu_unreg: pid: %p", pid); +} + +SEC("struct_ops/pvsched_vcpu_notify_event") +void BPF_PROG(pvsched_vcpu_notify_event, void *addr, struct pid *pid, __u3= 2 event) +{ + bpf_printk("pvsched_vcpu_notify: pid: %p, event:%u", pid, event); +} + +SEC(".struct_ops") +struct pvsched_vcpu_ops pvsched_ops =3D { + .pvsched_vcpu_register =3D (void *)pvsched_vcpu_reg, + .pvsched_vcpu_unregister =3D (void *)pvsched_vcpu_unreg, + .pvsched_vcpu_notify_event =3D (void *)pvsched_vcpu_notify_event, + .events =3D 0x6, + .name =3D "bpf_pvsched_ops", +}; --=20 2.40.1