All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Peter Xu" <peterx@redhat.com>, "Bibo Mao" <maobibo@loongson.cn>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: [RFC PATCH 00/12] exec/memory: Experimental API to catch unaligned accesses
Date: Thu, 20 May 2021 13:09:07 +0200	[thread overview]
Message-ID: <20210520110919.2483190-1-philmd@redhat.com> (raw)

Hi,

This series is an experiment after chatting with Stefan and having
received review from Peter / Richard on an orthogonal series aiming
to handle unaligned pointers (atomically):
https://www.mail-archive.com/qemu-devel@nongnu.org/msg808954.html

Here we don't aim to fix unatomic accesses, however we are interested
in catching malicious unaligned accesses from guests.

For that we introduce the MemTxAttrs::aligned field which allow
accessors to return MEMTX_UNALIGNED_ERROR early enough, instead
of trying the unaligned access which can potentially trigger a
SIGBUS and abort the process.

To be able to pass/return alignment information we modify the
memory load/store cached API, then add the
virtio_ld/st*_phys_cached_with_attrs() handler (we only implement
lduw for this experiment).

Finaly we modify vring_avail_flags() to return whether the guest
requested an illegal (unaligned) memory access.

Note: The current virtio_ld/st*_phys_cached_with_attrs() API returns
the value, and take the MemTxResult as argument, so I choose to
return -1 (marked with /* XXX */ comment. We should switch to using
an API which returns a MemTxResult and takes the value accessed as
argument, this way we don't have to return random meaningless value.

But this is beyond the scope of this experiment, here we want to
emphasize the introduction of the MemTxAttrs::aligned field and the
MEMTX_UNALIGNED_ERROR return value.

Regards,

Phil.

Philippe Mathieu-Daudé (12):
  exec/memory_ldst: Use correct type sizes
  exec/memattrs: Add attribute/error for address alignment
  exec/memory_ldst: Return MEMTX_UNALIGNED_ERROR for unaligned addresses
  exec/memory_ldst_cached: Sort declarations
  exec/memory_ldst_cached: Use correct type size
  exec/memory_ldst_cached: Set MemTxResult on success
  exec/memory_ldst_cached: Document aligned addresses are expected
  exec/memory_ldst_cached: Check address alignment if requested
  hw/virtio: Use correct type sizes
  hw/virtio: Extract virtio_lduw_phys_cached_with_attrs()
  hw/virtio: Have vring_avail_flags() return a boolean value
  hw/virtio: Display error if vring flag field is not aligned

 include/exec/memattrs.h               |   3 +
 include/hw/virtio/virtio-access.h     |  39 +++++++--
 include/exec/memory_ldst.h.inc        |  16 ++--
 include/exec/memory_ldst_cached.h.inc | 114 ++++++++++++++++++++------
 hw/virtio/virtio.c                    |  22 ++++-
 memory_ldst.c.inc                     |  69 +++++++++++++---
 6 files changed, 211 insertions(+), 52 deletions(-)

-- 
2.26.3




             reply	other threads:[~2021-05-20 11:11 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-20 11:09 Philippe Mathieu-Daudé [this message]
2021-05-20 11:09 ` [RFC PATCH 01/12] exec/memory_ldst: Use correct type sizes Philippe Mathieu-Daudé
2021-05-20 11:09 ` [RFC PATCH 02/12] exec/memattrs: Add attribute/error for address alignment Philippe Mathieu-Daudé
2021-06-02 12:39   ` Stefan Hajnoczi
2021-05-20 11:09 ` [RFC PATCH 03/12] exec/memory_ldst: Return MEMTX_UNALIGNED_ERROR for unaligned addresses Philippe Mathieu-Daudé
2021-05-20 11:09 ` [RFC PATCH 04/12] exec/memory_ldst_cached: Sort declarations Philippe Mathieu-Daudé
2021-05-20 11:09 ` [RFC PATCH 05/12] exec/memory_ldst_cached: Use correct type size Philippe Mathieu-Daudé
2021-05-20 11:09 ` [RFC PATCH 06/12] exec/memory_ldst_cached: Set MemTxResult on success Philippe Mathieu-Daudé
2021-05-20 11:09 ` [RFC PATCH 07/12] exec/memory_ldst_cached: Document aligned addresses are expected Philippe Mathieu-Daudé
2021-05-20 11:09 ` [RFC PATCH 08/12] exec/memory_ldst_cached: Check address alignment if requested Philippe Mathieu-Daudé
2021-05-20 11:09 ` [RFC PATCH 09/12] hw/virtio: Use correct type sizes Philippe Mathieu-Daudé
2021-05-20 11:09 ` [RFC PATCH 10/12] hw/virtio: Extract virtio_lduw_phys_cached_with_attrs() Philippe Mathieu-Daudé
2021-05-20 11:09 ` [RFC PATCH 11/12] hw/virtio: Have vring_avail_flags() return a boolean value Philippe Mathieu-Daudé
2021-05-20 11:09 ` [RFC PATCH 12/12] hw/virtio: Display error if vring flag field is not aligned Philippe Mathieu-Daudé
2021-06-02 12:44   ` Stefan Hajnoczi
2021-06-01  3:32 ` [RFC PATCH 00/12] exec/memory: Experimental API to catch unaligned accesses Philippe Mathieu-Daudé

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=20210520110919.2483190-1-philmd@redhat.com \
    --to=philmd@redhat.com \
    --cc=maobibo@loongson.cn \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=stefanha@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.