From: Eric Biggers <ebiggers@kernel.org>
To: Jasper Surmont <surmontjasper@gmail.com>
Cc: linux-block@vger.kernel.org
Subject: Re: [Question] Editing a bio write request
Date: Wed, 18 May 2022 11:33:13 -0700 [thread overview]
Message-ID: <YoU76RzXfV6Js9T7@sol.localdomain> (raw)
In-Reply-To: <CAH4tiUssBd1vKjUMtbNcmHt8X+-TzdgSFCfT=3coZZedGVESsg@mail.gmail.com>
On Wed, May 18, 2022 at 01:56:31PM +0300, Jasper Surmont wrote:
> I'm writing a device-mapper which has to edit incoming writes, for
> example: Incoming bio request contains a biovec with a page full of 0
> bytes, and I want to change it to all 0xFF bytes.
>
> I tried using bvec_kmap_local() to get the page address, to then read
> the data and if needed adjust it using memcpy or similar. Initial
> tests seemed to work, but if I execute things like mkfs on the created
> dm, I get a lot of segmentation faults. I narrowed down the problem
> that this only happens if I actually write something to the mapped
> page. However, I see no reason why it should cause this fault as I
> (after checking probably 100 times) don't access invalid memory. I'm
> wondering whether my method of editing the write is actually correct,
> or if I am doing something else very stupid.
Data in bios can't be modified in-place, as submitters of writes (e.g.,
filesystems) expect that their data buffers aren't modified. To modify the data
you'd need to allocate a new bio with new pages and submit that instead. See
dm-crypt for an example of a device-mapper target which does this.
What sort of device-mapper target are you trying to implement, anyway? If
you're trying to do encryption, dm-crypt already solves that problem.
- Eric
next prev parent reply other threads:[~2022-05-18 18:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-18 10:56 [Question] Editing a bio write request Jasper Surmont
2022-05-18 18:33 ` Eric Biggers [this message]
2022-05-18 19:08 ` Jasper Surmont
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=YoU76RzXfV6Js9T7@sol.localdomain \
--to=ebiggers@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=surmontjasper@gmail.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