Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1362413lqe; Mon, 8 Apr 2024 07:01:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU2PZHf1cFquhPsMHhVBIGqQswLjb2yX9Y22ealcm0TU84yUImH0SY5IXlSWgel9JouRmdAXSu0WvwocO9sjCKzdSoxvowwyShwtrOsyg== X-Google-Smtp-Source: AGHT+IHkmDQ1bk0KOZ5J/0OudAGX+DoPsIiLss+dwUYLohr2+Hy/TeXN/uQh2/bEpGL7z7Yy+6h+ X-Received: by 2002:a17:902:dacd:b0:1e2:bed0:317a with SMTP id q13-20020a170902dacd00b001e2bed0317amr8551346plx.21.1712584901547; Mon, 08 Apr 2024 07:01:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712584901; cv=pass; d=google.com; s=arc-20160816; b=uOCDRyNBpvGaxIhLE4Mo4QjpazRuy9Dq3SVNdPzmR9ZPw1DSPwG7HDZGXpxWqT9Ehx kY+69DmPnYQfkAIC+jTAuE09t2NOFet8glAjbTH6YVLjKXtdN6BDDVCfWCBpYD31FCsY Z+JMKmhrHQb+3VDrF2xsWp32MIRb5S+2o6qTYp1JR3Gw8hBfxvQ57OnpD+tVCHH+ol5q JljVNYzpZ4r01Gmh78QYmuSrMfGVA4D1cOjfGudGtMx8nXl6wakvCLRJVw/qc+JuvjLT iJU+9fcNz/YTMz4QHIZZqFh4iV/Kq1+giIYWl08EpgF099tDQLnoqpQUR1qa8V/Y6PDw AbnQ== 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=RgX5uLFPvKhCe0/l1qGuqD81V2YeLLzt+zbkFfBro1o=; fh=AAQbBrvke6ZYaHpfD011BqvRo1r7IXgdXWY5meoGQWY=; b=t2VC1fIL6/0rnbKcA5zhDZ4G5QaSfjlTLdPLqNbfxMXhTowFzOH9sXmvEf3rsTPCOr GMDESEbB3wRBASl9S3B7WI0mQw+KJWxgoVzmw0X+JjCx8bKXTgwYb0+KT2NV2bpDJc0M Q3qfPuiPk2LlpixXdQVJ/ilkw3yw0G+2gEfmo1/UJ3tOJEVjHoZxRvm8LlbsJW33sImp RI2+oENINnOdYrpjptJ9q7KhllsEodYQc67/mGNwkVGVMFbfWgKb++sq/8BoXiD5xm/c HlgtZeu+RP2dPRkG6NP9VdHyT2UpaDp+jY6L1hjBlUMcXwxAyqs/u1zOSxYTv4uxmj3C SpPQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bitbyteword.org header.s=google header.b=ATMp6C0P; arc=pass (i=1 spf=pass spfdomain=bitbyteword.org dkim=pass dkdomain=bitbyteword.org); spf=pass (google.com: domain of linux-kernel+bounces-135477-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135477-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 h17-20020a170902f71100b001e0afc34ae1si5398187plo.40.2024.04.08.07.01.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 07:01:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-135477-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=ATMp6C0P; arc=pass (i=1 spf=pass spfdomain=bitbyteword.org dkim=pass dkdomain=bitbyteword.org); spf=pass (google.com: domain of linux-kernel+bounces-135477-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135477-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 0542D284577 for ; Mon, 8 Apr 2024 14:01:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B708D7F7CE; Mon, 8 Apr 2024 14:01:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bitbyteword.org header.i=@bitbyteword.org header.b="ATMp6C0P" Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com [209.85.128.175]) (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 E9C6F7E0FF for ; Mon, 8 Apr 2024 14:00:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712584859; cv=none; b=uTConbMoP71M+6Ew0ZbkEexgMB4y4TF3qjcm7zna5L1arj4+sfZy80QBnKEJBX0e+uLhNnLlsItdhzQplaMOHRD5KBekUavSoVFDyn4N5wiGOr93rIL4xvGnMBV8GzMt6xVnsotASVu7g+n34KoP1I18k0yZ7x/lFcHr3ZNUXZE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712584859; c=relaxed/simple; bh=pmcfq5HWbvOuPZ7ktQYB9L7EjebiET7N8ip2h9xS9rQ=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=sYWCDgmgj2FGO7iAD7cfedR1PNb5AvnHTrkdkRUGlzC8FHkoSWgOt5TAg7h8TwXYQrAUDM1NO9ATLqYg1vmVRVzLwdA2xQjpgVIMN7y76f+Mnn7VILKI6cl75wPOnWm9zYmopw/+h+N2BWzmKPdDbYQZjwCWrIpDi0/8kuVm+Dc= 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=ATMp6C0P; arc=none smtp.client-ip=209.85.128.175 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-yw1-f175.google.com with SMTP id 00721157ae682-61804067da0so11064857b3.0 for ; Mon, 08 Apr 2024 07:00:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bitbyteword.org; s=google; t=1712584857; x=1713189657; 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=RgX5uLFPvKhCe0/l1qGuqD81V2YeLLzt+zbkFfBro1o=; b=ATMp6C0PwraBAkKa0KdnsEiAzvTxU5Zp9hFsmSbNkJSEeHRsISmuuYbvL9jRXjj6rf PJdt8b5g5tXBfq5iXFMUvyhQIGcCYX3pLBXXP+dKJAWKfn8LfxxFz4dyClTqOpM142qe QkueL1lDlD4RKRZxqHx75Dz70nYuqQIpuxx8qnY1aPKnz8PJyyTLl0/iK2eSN/oCg8lJ SASa4MURhi2jNP7yNkYehAD3D0ToqV9TlyVU2J0qLahXpa/LBMe2z2mVfSvsfXIBaaXi N5rGMVWtOuksJGntr3c1S0t74qQ5xjRSR6obIOwRlHRs41QegFGf7gWYrTBEPynoQyyt 7zfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712584857; x=1713189657; 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=RgX5uLFPvKhCe0/l1qGuqD81V2YeLLzt+zbkFfBro1o=; b=lO4AQZkenZEajNX2Rt7+mFY0sypoulK/yCUFC1Den/vmx0b5IOF8sudeiYQnp2Mxm+ fwqrasaxkcHeifO91KySn4sHW1VhSm1n8pk1zI9dFGKntquEUxcoamWtl8Dwu8+QKa8D ldwVIeUbN0l5XLr+pCA5D2Y3D0q6rr0haIxnEKQr4UcA2F6PnUGb2PdIoBSGgDJDjoG8 dOVqh3oktnoYu0aiPWYjg9pAtbZbmqXfueW+jOe9PgxDcvEHBcz+RrsULicd2pbjnzdb bafSJmVEQFWjSk8oBhCAXgdK0xDRjDJoRVocWLof6uyFFDjApHOiDvoyduWeOHu4/iRy PiCw== X-Forwarded-Encrypted: i=1; AJvYcCW5Na2VimiQqQEbFgXmi8Iy7Aq/SbV5YHrakiKPxudzm7Ed9Jzoeoxxdp6MmqLbDcG5dB2y2W84Y6/n8KZA+5easHnVMVpGgMwi+j8M X-Gm-Message-State: AOJu0YyenVVq00sTI1e7EHzHCSMuecrFVNrHg+m+UOn1fPqWMNDIHKri NbQDVpWcTLwEIPjNGjgZpfcx1hnmnnin//yJ02/FZIvb7VjUke8XhCm9c70FZvjbiMiswqnmdZh 5aCQIlYPlnh0a6oJ1o4i1oEpS/tsCGQpNpnvNDg== X-Received: by 2002:a05:6902:1547:b0:dc6:17d2:3b89 with SMTP id r7-20020a056902154700b00dc617d23b89mr6556651ybu.61.1712584856879; Mon, 08 Apr 2024 07:00:56 -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-5-vineeth@bitbyteword.org> In-Reply-To: <20240403140116.3002809-5-vineeth@bitbyteword.org> From: Vineeth Remanan Pillai Date: Mon, 8 Apr 2024 10:00:46 -0400 Message-ID: Subject: Re: [RFC PATCH v2 4/5] pvsched: bpf support for pvsched 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 , Josh Don , Barret Rhoden , David Vernet 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: > > 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_op= s_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 @@ > > -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_o= ps.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 *l= og, > + 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 b= pf_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 even= t) > +{ > +} > + > +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, > +}; > -- > 2.40.1 >