From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Ninad Palsule <ninad@linux.ibm.com>
Cc: qemu-devel@nongnu.org, clg@kaod.org, peter.maydell@linaro.org,
andrew@aj.id.au, joel@jms.id.au, pbonzini@redhat.com,
marcandre.lureau@redhat.com, thuth@redhat.com, philmd@linaro.org,
lvivier@redhat.com, qemu-arm@nongnu.org
Subject: Re: [PATCH v5 02/10] hw/fsi: Introduce IBM's scratchpad
Date: Thu, 19 Oct 2023 09:20:04 +0100 [thread overview]
Message-ID: <ZTDmtBUkuvYNkFlQ@redhat.com> (raw)
In-Reply-To: <20231011151339.2782132-3-ninad@linux.ibm.com>
On Wed, Oct 11, 2023 at 10:13:31AM -0500, Ninad Palsule wrote:
> This is a part of patchset where scratchpad is introduced.
>
> The scratchpad provides a set of non-functional registers. The firmware
> is free to use them, hardware does not support any special management
> support. The scratchpad registers can be read or written from LBUS
> slave.
>
> In this model, The LBUS device is parent for the scratchpad.
>
> Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
> Signed-off-by: Cédric Le Goater <clg@kaod.org>
> Signed-off-by: Ninad Palsule <ninad@linux.ibm.com>
> ---
> v2:
> - Incorporated Joel's review comments.
> v5:
> - Incorporated review comments by Cedric.
> ---
> include/hw/fsi/engine-scratchpad.h | 33 ++++++++++
> hw/fsi/engine-scratchpad.c | 99 ++++++++++++++++++++++++++++++
> hw/fsi/Kconfig | 4 ++
> hw/fsi/meson.build | 1 +
> hw/fsi/trace-events | 2 +
> 5 files changed, 139 insertions(+)
> create mode 100644 include/hw/fsi/engine-scratchpad.h
> create mode 100644 hw/fsi/engine-scratchpad.c
> create mode 100644 hw/fsi/trace-events
>
> diff --git a/include/hw/fsi/engine-scratchpad.h b/include/hw/fsi/engine-scratchpad.h
> new file mode 100644
> index 0000000000..17e9570c5c
> --- /dev/null
> +++ b/include/hw/fsi/engine-scratchpad.h
> @@ -0,0 +1,33 @@
> +/*
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + * Copyright (C) 2023 IBM Corp.
> + *
> + * IBM scratchpad engne
> + */
> +#ifndef FSI_ENGINE_SCRATCHPAD_H
> +#define FSI_ENGINE_SCRATCHPAD_H
> +
> +#include "qemu/bitops.h"
> +
> +#include "hw/fsi/lbus.h"
> +
> +#define ENGINE_CONFIG_NEXT BE_BIT(0)
> +#define ENGINE_CONFIG_VPD BE_BIT(1)
> +#define ENGINE_CONFIG_SLOTS BE_GENMASK(8, 15)
> +#define ENGINE_CONFIG_VERSION BE_GENMASK(16, 19)
> +#define ENGINE_CONFIG_TYPE BE_GENMASK(20, 27)
> +#define ENGINE_CONFIG_TYPE_PEEK (0x02 << 4)
> +#define ENGINE_CONFIG_TYPE_FSI (0x03 << 4)
> +#define ENGINE_CONFIG_TYPE_SCRATCHPAD (0x06 << 4)
> +#define ENGINE_CONFIG_CRC BE_GENMASK(28, 31)
> +
> +#define TYPE_SCRATCHPAD "scratchpad"
> +#define SCRATCHPAD(obj) OBJECT_CHECK(ScratchPad, (obj), TYPE_SCRATCHPAD)
> +
> +typedef struct ScratchPad {
> + FSILBusDevice parent;
> +
> + uint32_t reg;
> +} ScratchPad;
> +
> +#endif /* FSI_ENGINE_SCRATCHPAD_H */
> diff --git a/hw/fsi/engine-scratchpad.c b/hw/fsi/engine-scratchpad.c
> new file mode 100644
> index 0000000000..60f678eec4
> --- /dev/null
> +++ b/hw/fsi/engine-scratchpad.c
> @@ -0,0 +1,99 @@
> +/*
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + * Copyright (C) 2023 IBM Corp.
> + *
> + * IBM scratchpad engine
> + */
> +
> +#include "qemu/osdep.h"
> +
> +#include "qapi/error.h"
> +#include "qemu/log.h"
> +#include "trace.h"
> +
> +#include "hw/fsi/engine-scratchpad.h"
> +
> +static uint64_t scratchpad_read(void *opaque, hwaddr addr, unsigned size)
> +{
> + ScratchPad *s = SCRATCHPAD(opaque);
> +
> + trace_scratchpad_read(addr, size);
> +
> + if (addr) {
> + qemu_log_mask(LOG_GUEST_ERROR,
> + "%s: Out of bounds read: 0x%"HWADDR_PRIx" for %u\n",
> + __func__, addr, size);
We already have a trace point in the line above. I don't think we should
be unconditionally logging errors like this, as this becomes a guest
triggerable denial of service on the host log collector for the guest.
eg it could flood the logfile connected to stderr with unlimited data
by repeatedly doing bad reads/writes.
> + return 0;
> + }
> +
> + return s->reg;
> +}
> +
> +static void scratchpad_write(void *opaque, hwaddr addr, uint64_t data,
> + unsigned size)
> +{
> + ScratchPad *s = SCRATCHPAD(opaque);
> +
> + trace_scratchpad_write(addr, size, data);
> +
> + if (addr) {
> + qemu_log_mask(LOG_GUEST_ERROR,
> + "%s: Out of bounds write: 0x%"HWADDR_PRIx" for %u\n",
> + __func__, addr, size);
> + return;
> + }
> +
> + s->reg = data;
> +}
> +
> +static const struct MemoryRegionOps scratchpad_ops = {
> + .read = scratchpad_read,
> + .write = scratchpad_write,
> + .endianness = DEVICE_BIG_ENDIAN,
> +};
> +
> +static void scratchpad_realize(DeviceState *dev, Error **errp)
> +{
> + FSILBusDevice *ldev = FSI_LBUS_DEVICE(dev);
> +
> + memory_region_init_io(&ldev->iomem, OBJECT(ldev), &scratchpad_ops,
> + ldev, TYPE_SCRATCHPAD, 0x400);
> +}
> +
> +static void scratchpad_reset(DeviceState *dev)
> +{
> + ScratchPad *s = SCRATCHPAD(dev);
> +
> + s->reg = 0;
> +}
> +
> +static void scratchpad_class_init(ObjectClass *klass, void *data)
> +{
> + DeviceClass *dc = DEVICE_CLASS(klass);
> + FSILBusDeviceClass *ldc = FSI_LBUS_DEVICE_CLASS(klass);
> +
> + dc->realize = scratchpad_realize;
> + dc->reset = scratchpad_reset;
> +
> + ldc->config =
> + ENGINE_CONFIG_NEXT /* valid */
> + | 0x00010000 /* slots */
> + | 0x00001000 /* version */
> + | ENGINE_CONFIG_TYPE_SCRATCHPAD /* type */
> + | 0x00000007; /* crc */
More common QEMU style would be for the "|" to be on the end
of line rather than start.
End of line:
$ git grep '.*\s|\s*$' "*.c" | wc -l
5381
Start of line:
$ git grep '^\s*|\s.*' "*.c" | wc -l
581
> +}
> +
> +static const TypeInfo scratchpad_info = {
> + .name = TYPE_SCRATCHPAD,
> + .parent = TYPE_FSI_LBUS_DEVICE,
> + .instance_size = sizeof(ScratchPad),
> + .class_init = scratchpad_class_init,
> + .class_size = sizeof(FSILBusDeviceClass),
> +};
> +
> +static void scratchpad_register_types(void)
> +{
> + type_register_static(&scratchpad_info);
> +}
> +
> +type_init(scratchpad_register_types);
> diff --git a/hw/fsi/Kconfig b/hw/fsi/Kconfig
> index e650c660f0..f7c7fd1b28 100644
> --- a/hw/fsi/Kconfig
> +++ b/hw/fsi/Kconfig
> @@ -1,2 +1,6 @@
> +config FSI_SCRATCHPAD
> + bool
> + select FSI_LBUS
> +
> config FSI_LBUS
> bool
> diff --git a/hw/fsi/meson.build b/hw/fsi/meson.build
> index 4074d3a7d2..d45a98c223 100644
> --- a/hw/fsi/meson.build
> +++ b/hw/fsi/meson.build
> @@ -1 +1,2 @@
> system_ss.add(when: 'CONFIG_FSI_LBUS', if_true: files('lbus.c'))
> +system_ss.add(when: 'CONFIG_FSI_SCRATCHPAD', if_true: files('engine-scratchpad.c'))
> diff --git a/hw/fsi/trace-events b/hw/fsi/trace-events
> new file mode 100644
> index 0000000000..97fd070354
> --- /dev/null
> +++ b/hw/fsi/trace-events
> @@ -0,0 +1,2 @@
> +scratchpad_read(uint64_t addr, uint32_t size) "@0x%" PRIx64 " size=%d"
> +scratchpad_write(uint64_t addr, uint32_t size, uint64_t data) "@0x%" PRIx64 " size=%d value=0x%"PRIx64
> --
> 2.39.2
>
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2023-10-19 8:20 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-11 15:13 [PATCH v5 00/10] Introduce model for IBM's FSI Ninad Palsule
2023-10-11 15:13 ` [PATCH v5 01/10] hw/fsi: Introduce IBM's Local bus Ninad Palsule
2023-10-19 8:03 ` Cédric Le Goater
2023-10-21 20:20 ` Ninad Palsule
2023-10-19 8:08 ` Cédric Le Goater
2023-10-21 20:21 ` Ninad Palsule
2023-10-19 8:14 ` Daniel P. Berrangé
2023-10-19 15:34 ` Ninad Palsule
2023-10-19 16:09 ` Daniel P. Berrangé
2023-10-21 20:22 ` Ninad Palsule
2023-10-11 15:13 ` [PATCH v5 02/10] hw/fsi: Introduce IBM's scratchpad Ninad Palsule
2023-10-19 8:20 ` Daniel P. Berrangé [this message]
2023-10-21 20:27 ` Ninad Palsule
2023-10-11 15:13 ` [PATCH v5 03/10] hw/fsi: Introduce IBM's cfam,fsi-slave Ninad Palsule
2023-10-19 8:00 ` Cédric Le Goater
2023-10-21 20:33 ` Ninad Palsule
2023-10-19 8:26 ` Daniel P. Berrangé
2023-10-21 20:34 ` Ninad Palsule
2023-10-19 17:28 ` Cédric Le Goater
2023-10-21 20:35 ` Ninad Palsule
2023-10-11 15:13 ` [PATCH v5 04/10] hw/fsi: Introduce IBM's FSI Ninad Palsule
2023-10-19 7:44 ` Cédric Le Goater
2023-10-21 20:36 ` Ninad Palsule
2023-10-19 8:28 ` Daniel P. Berrangé
2023-10-21 20:37 ` Ninad Palsule
2023-10-11 15:13 ` [PATCH v5 05/10] hw/fsi: IBM's On-chip Peripheral Bus Ninad Palsule
2023-10-19 7:26 ` Cédric Le Goater
2023-10-21 20:40 ` Ninad Palsule
2023-10-19 8:30 ` Daniel P. Berrangé
2023-10-21 20:42 ` Ninad Palsule
2023-10-11 15:13 ` [PATCH v5 06/10] hw/fsi: Aspeed APB2OPB interface Ninad Palsule
2023-10-19 7:16 ` Cédric Le Goater
2023-10-21 20:43 ` Ninad Palsule
2023-10-11 15:13 ` [PATCH v5 07/10] hw/arm: Hook up FSI module in AST2600 Ninad Palsule
2023-10-11 15:13 ` [PATCH v5 08/10] hw/fsi: Added qtest Ninad Palsule
2023-10-11 15:35 ` Thomas Huth
2023-10-11 16:54 ` Ninad Palsule
2023-10-11 15:13 ` [PATCH v5 09/10] hw/fsi: Added FSI documentation Ninad Palsule
2023-10-11 15:13 ` [PATCH v5 10/10] hw/fsi: Update MAINTAINER list Ninad Palsule
2023-10-19 8:16 ` [PATCH v5 00/10] Introduce model for IBM's FSI Cédric Le Goater
2023-10-21 20:45 ` Ninad Palsule
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=ZTDmtBUkuvYNkFlQ@redhat.com \
--to=berrange@redhat.com \
--cc=andrew@aj.id.au \
--cc=clg@kaod.org \
--cc=joel@jms.id.au \
--cc=lvivier@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=ninad@linux.ibm.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=thuth@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).