From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Jiqian Chen <Jiqian.Chen@amd.com>
Cc: xen-devel@lists.xenproject.org, Huang Rui <ray.huang@amd.com>,
Anthony PERARD <anthony.perard@vates.tech>
Subject: Re: [PATCH v2 5/8] vpci: Refactor vpci_remove_register to remove matched registers
Date: Tue, 15 Apr 2025 13:06:06 +0200 [thread overview]
Message-ID: <Z_49nsZbVU6F2tu0@macbook.lan> (raw)
In-Reply-To: <20250409064528.405573-6-Jiqian.Chen@amd.com>
On Wed, Apr 09, 2025 at 02:45:25PM +0800, Jiqian Chen wrote:
> vpci_remove_register() only supports removing a register in a time,
> but the follow-on changes need to remove all registers within a
> range. And it is only used for test. So, refactor it to support
> removing all matched registers in a calling time.
>
> And it is no matter to remove a non exist register, so remove the
> __must_check prefix.
>
> Signed-off-by: Jiqian Chen <Jiqian.Chen@amd.com>
> ---
> cc: "Roger Pau Monné" <roger.pau@citrix.com>
> cc: Anthony PERARD <anthony.perard@vates.tech>
> ---
> v1->v2 changes:
> new patch
>
> Best regards,
> Jiqian Chen.
> ---
> tools/tests/vpci/main.c | 4 ++--
> xen/drivers/vpci/vpci.c | 23 ++++++++++++-----------
> xen/include/xen/vpci.h | 4 ++--
> 3 files changed, 16 insertions(+), 15 deletions(-)
>
> diff --git a/tools/tests/vpci/main.c b/tools/tests/vpci/main.c
> index 33223db3eb77..ca72877d60cd 100644
> --- a/tools/tests/vpci/main.c
> +++ b/tools/tests/vpci/main.c
> @@ -132,10 +132,10 @@ static void vpci_write32_mask(const struct pci_dev *pdev, unsigned int reg,
> rsvdz_mask))
>
> #define VPCI_REMOVE_REG(off, size) \
> - assert(!vpci_remove_register(test_pdev.vpci, off, size))
> + assert(!vpci_remove_registers(test_pdev.vpci, off, size))
>
> #define VPCI_REMOVE_INVALID_REG(off, size) \
> - assert(vpci_remove_register(test_pdev.vpci, off, size))
> + assert(vpci_remove_registers(test_pdev.vpci, off, size))
>
> /* Read a 32b register using all possible sizes. */
> void multiread4_check(unsigned int reg, uint32_t val)
> diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c
> index f1f125bfdab1..115d3c5f0c84 100644
> --- a/xen/drivers/vpci/vpci.c
> +++ b/xen/drivers/vpci/vpci.c
> @@ -418,34 +418,35 @@ int vpci_add_register_mask(struct vpci *vpci, vpci_read_t *read_handler,
> return 0;
> }
>
> -int vpci_remove_register(struct vpci *vpci, unsigned int offset,
> - unsigned int size)
> +int vpci_remove_registers(struct vpci *vpci, unsigned int offset,
> + unsigned int size)
> {
> const struct vpci_register r = { .offset = offset, .size = size };
> struct vpci_register *rm;
> + int rc = -ENOENT;
Thinking about this, not sure returning ENOENT makes much sense now,
as the (new) purpose of the function is to zap all handlers from a
range, without possibly prior knowledge whether there are any
handlers in the range.
>
> spin_lock(&vpci->lock);
> list_for_each_entry ( rm, &vpci->handlers, node )
> {
> int cmp = vpci_register_cmp(&r, rm);
>
> - /*
> - * NB: do not use a switch so that we can use break to
> - * get out of the list loop earlier if required.
> - */
> - if ( !cmp && rm->offset == offset && rm->size == size )
> + if ( !cmp )
> {
> + struct vpci_register *prev =
> + list_entry(rm->node.prev, struct vpci_register, node);
> +
> list_del(&rm->node);
> - spin_unlock(&vpci->lock);
> xfree(rm);
> - return 0;
> + rm = prev;
> + rc = 0;
I think you want some extra checks here to ensure you are not removing
partially overlapping registers. IOW, you need to assert the register
in rm is fully contained inside the range to zap.
It might be best to simply not use vpci_register_cmp(), and instead
open code the comparison here to ensure "rm" is fuly contained inside
the [offset, offset + size - 1] range. You will need to return an
error if there's a partially overlapping register.
Thanks, Roger.
next prev parent reply other threads:[~2025-04-15 11:06 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-09 6:45 [PATCH v2 0/8] Support hiding capability when its initialization fails Jiqian Chen
2025-04-09 6:45 ` [PATCH v2 1/8] driver/pci: Get next capability without passing caps Jiqian Chen
2025-04-10 12:34 ` Jan Beulich
2025-04-11 2:51 ` Chen, Jiqian
2025-04-11 8:00 ` Jan Beulich
2025-04-11 8:08 ` Chen, Jiqian
2025-04-09 6:45 ` [PATCH v2 2/8] vpci/header: Emulate legacy capability list for host Jiqian Chen
2025-04-10 12:40 ` Jan Beulich
2025-04-11 2:54 ` Chen, Jiqian
2025-04-11 8:01 ` Jan Beulich
2025-04-15 9:25 ` Roger Pau Monné
2025-04-15 10:07 ` Chen, Jiqian
2025-04-15 10:08 ` Jan Beulich
2025-04-15 10:23 ` Chen, Jiqian
2025-04-15 10:50 ` Roger Pau Monné
2025-04-15 10:10 ` Roger Pau Monné
2025-04-16 2:51 ` Chen, Jiqian
2025-04-16 7:32 ` Roger Pau Monné
2025-04-09 6:45 ` [PATCH v2 3/8] vpci/header: Emulate extended " Jiqian Chen
2025-04-15 9:42 ` Roger Pau Monné
2025-04-15 10:11 ` Chen, Jiqian
2025-04-15 9:49 ` Jan Beulich
2025-04-15 10:18 ` Chen, Jiqian
2025-04-15 10:20 ` Jan Beulich
2025-04-09 6:45 ` [PATCH v2 4/8] vpci: Hide capability when it fails to initialize Jiqian Chen
2025-04-15 10:47 ` Roger Pau Monné
2025-04-16 6:07 ` Chen, Jiqian
2025-04-09 6:45 ` [PATCH v2 5/8] vpci: Refactor vpci_remove_register to remove matched registers Jiqian Chen
2025-04-15 11:06 ` Roger Pau Monné [this message]
2025-04-09 6:45 ` [PATCH v2 6/8] vpci/rebar: Remove registers when init_rebar() fails Jiqian Chen
2025-04-15 12:59 ` Roger Pau Monné
2025-04-09 6:45 ` [PATCH v2 7/8] vpci/msi: Free MSI resources when init_msi() fails Jiqian Chen
2025-04-15 13:29 ` Roger Pau Monné
2025-04-16 6:16 ` Chen, Jiqian
2025-04-16 7:47 ` Roger Pau Monné
2025-04-09 6:45 ` [PATCH v2 8/8] vpci/msix: Add function to clean MSIX resources Jiqian Chen
2025-04-15 13:45 ` Roger Pau Monné
2025-04-16 6:20 ` Chen, Jiqian
2025-04-16 7:54 ` Roger Pau Monné
2025-04-17 7:34 ` Jan Beulich
2025-04-17 7:38 ` Chen, Jiqian
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=Z_49nsZbVU6F2tu0@macbook.lan \
--to=roger.pau@citrix.com \
--cc=Jiqian.Chen@amd.com \
--cc=anthony.perard@vates.tech \
--cc=ray.huang@amd.com \
--cc=xen-devel@lists.xenproject.org \
/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.