From: Leah Rumancik <leah.rumancik@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Bob Liu <bob.liu@oracle.com>,
bpf@vger.kernel.org, linux-block@vger.kernel.org,
orbekk@google.com, harshads@google.com, jasiu@google.com,
saranyamohan@google.com, tytso@google.com, bvanassche@google.com,
"Martin K. Petersen" <martin.petersen@oracle.com>
Subject: Re: [RFC PATCH 1/4] bpf: add new prog_type BPF_PROG_TYPE_IO_FILTER
Date: Fri, 4 Sep 2020 12:46:06 -0400 [thread overview]
Message-ID: <20200904164605.GB2048@leah-Ubuntu> (raw)
In-Reply-To: <20200817163207.p53guehd7kpxfvat@ast-mbp.dhcp.thefacebook.com>
On Mon, Aug 17, 2020 at 09:32:07AM -0700, Alexei Starovoitov wrote:
> On Mon, Aug 17, 2020 at 10:18:47PM +0800, Bob Liu wrote:
> > > +
> > > +/* allows IO by default if no programs attached */
> > > +int io_filter_bpf_run(struct bio *bio)
> > > +{
> > > + struct bpf_io_request io_req = {
> > > + .sector_start = bio->bi_iter.bi_sector,
> > > + .sector_cnt = bio_sectors(bio),
> > > + .opf = bio->bi_opf,
> > > + };
> > > +
> > > + return BPF_PROG_RUN_ARRAY_CHECK(bio->bi_disk->progs, &io_req, BPF_PROG_RUN);
> >
> >
> > I think pass "struct bpf_io_request" is not enough, since we may want to do the filter based on
> > some special patterns against the io data.
> >
> > I used to pass "page_to_virt(bio->bi_io_vec->bv_page)" into ebpf program..
>
> Bob,
>
> Just like other bpf uapi structs the bpf_io_request is extensible and
> such pointer can be added later, but I have a different question.
>
> Leah,
>
> Do you really need the arguments to be stable?
> If so 'opf' above is not enough.
> sector_start, sector_cnt are clean from uapi pov,
> but 'opf' exposes kernel internals.
> The patch 2 is doing:
> +int protect_gpt(struct bpf_io_request *io_req)
> +{
> + /* within GPT and not a read operation */
> + if (io_req->sector_start < GPT_SECTORS && (io_req->opf & REQ_OP_MASK) != REQ_OP_READ)
> + return IO_BLOCK;
>
> The way ops are encoded changed quite a bit over the kernel releases.
> First it was REQ_WRITE, then REQ_OP_SHIFT, now REQ_OP_MASK.
> From kernel pov it would be simpler if bpf side didn't impose stability
> requriment on the program arguments. Then the kernel will be free to change
> REG_OP_READ into something else. The progs would break, of course, and would
> have to be adjusted. That's what we've been doing with tools like biosnoop.
> If you're ok with unstable arguments then you wouldn't need to introduce
> new prog type and this patch set.
> You can do this filtering already with should_fail_bio().
> bpf prog can attach to should_fail_bio() and walk all bio arguments
> in unstable way.
> Instead of:
> + if (io_req->sector_start < GPT_SECTORS && (io_req->opf & REQ_OP_MASK) != REQ_OP_READ)
> you'll write:
> if (bio->bi_iter.bi_sector < GPT_SECTORS && (bio->bi_opf & REQ_OP_MASK) != REQ_OP_READ)
> It will also work on different kernels because libbpf can adjust field offsets and
> check for type matching via CO-RE facility.
> Will that work for you?
Alexei,
I need the arguments to be stable. What would be the best way to go
about this? Pulling selected information from the opf field and defining
my own constants?
Thanks,
Leah
next prev parent reply other threads:[~2020-09-04 16:46 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-12 16:33 [RFC PATCH 0/4] block/bpf: add eBPF based block layer IO filtering Leah Rumancik
2020-08-12 16:33 ` [RFC PATCH 1/4] bpf: add new prog_type BPF_PROG_TYPE_IO_FILTER Leah Rumancik
2020-08-13 23:00 ` Martin KaFai Lau
2020-09-04 15:43 ` Leah Rumancik
2020-08-17 14:18 ` Bob Liu
2020-08-17 16:32 ` Alexei Starovoitov
2020-09-04 16:46 ` Leah Rumancik [this message]
2020-09-04 18:50 ` Alexei Starovoitov
2020-09-17 18:33 ` Leah Rumancik
2020-09-01 16:53 ` Leah Rumancik
2020-09-02 7:36 ` Bob Liu
2020-08-18 12:53 ` Jakub Sitnicki
2020-09-04 17:29 ` Leah Rumancik
2020-08-12 16:33 ` [RFC PATCH 2/4] bpf: add protect_gpt sample program Leah Rumancik
2020-08-13 22:58 ` Martin KaFai Lau
2020-09-01 16:33 ` Leah Rumancik
2020-08-12 16:33 ` [RFC PATCH 3/4] bpf: add eBPF IO filter documentation Leah Rumancik
2020-08-12 17:04 ` Bart Van Assche
2020-08-12 17:50 ` Jonathan Corbet
2020-09-01 15:35 ` Leah Rumancik
2020-08-12 16:33 ` [RFC PATCH 4/4] bpf: add BPF_PROG_TYPE_LSM to bpftool name array Leah Rumancik
2020-08-12 17:00 ` Bart Van Assche
2020-08-12 18:17 ` Tobias Klauser
2020-09-01 15:18 ` Leah Rumancik
2020-08-17 6:37 ` [RFC PATCH 0/4] block/bpf: add eBPF based block layer IO filtering Christoph Hellwig
2020-08-18 2:44 ` Ming Lei
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=20200904164605.GB2048@leah-Ubuntu \
--to=leah.rumancik@gmail.com \
--cc=alexei.starovoitov@gmail.com \
--cc=bob.liu@oracle.com \
--cc=bpf@vger.kernel.org \
--cc=bvanassche@google.com \
--cc=harshads@google.com \
--cc=jasiu@google.com \
--cc=linux-block@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=orbekk@google.com \
--cc=saranyamohan@google.com \
--cc=tytso@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox