All of lore.kernel.org
 help / color / mirror / Atom feed
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 v3 08/11] vpci: Refactor vpci_remove_register to remove matched registers
Date: Tue, 6 May 2025 18:29:20 +0200	[thread overview]
Message-ID: <aBo44G-DuEFO4_7S@macbook.lan> (raw)
In-Reply-To: <20250421061903.1542652-9-Jiqian.Chen@amd.com>

On Mon, Apr 21, 2025 at 02:19:00PM +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 vpci_remove_register() is only used for test currently.
> 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>
> ---
> v2->v3 changes:
> * Add new check to return error if registers overlap but not inside range.
> 
> v1->v2 changes:
> new patch
> 
> Best regards,
> Jiqian Chen.
> ---
>  tools/tests/vpci/main.c |  4 ++--
>  xen/drivers/vpci/vpci.c | 34 ++++++++++++++++++++--------------
>  xen/include/xen/vpci.h  |  4 ++--
>  3 files changed, 24 insertions(+), 18 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 8ff5169bdd18..904770628a2a 100644
> --- a/xen/drivers/vpci/vpci.c
> +++ b/xen/drivers/vpci/vpci.c
> @@ -497,34 +497,40 @@ 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 start,
> +                          unsigned int size)
>  {
> -    const struct vpci_register r = { .offset = offset, .size = size };
>      struct vpci_register *rm;
> +    unsigned int end = start + size;
>  
>      spin_lock(&vpci->lock);
>      list_for_each_entry ( rm, &vpci->handlers, node )

You might want to use list_for_each_entry_safe ( ) so that...

>      {
> -        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 )
> +        /* Remove rm if rm is inside the range. */
> +        if ( rm->offset >= start && rm->offset + rm->size <= end )
>          {
> +            struct vpci_register *prev =
> +                list_entry(rm->node.prev, struct vpci_register, node);

... you don't need to find prev here.

>              list_del(&rm->node);
> -            spin_unlock(&vpci->lock);
>              xfree(rm);
> -            return 0;
> +            rm = prev;
> +            continue;
>          }
> -        if ( cmp <= 0 )
> +
> +        /* Return error if registers overlap but not inside. */
> +        if ( rm->offset + rm->size > start && rm->offset < end )
> +        {
> +            spin_unlock(&vpci->lock);
> +            return -EINVAL;

-ERANGE might be more descriptive here.

Thanks, Roger.


  reply	other threads:[~2025-05-06 16:29 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-21  6:18 [PATCH v3 00/11] Support hiding capability when its initialization fails Jiqian Chen
2025-04-21  6:18 ` [PATCH v3 01/11] vpci/header: Move emulating cap list logic into new function Jiqian Chen
2025-04-29  7:10   ` Chen, Jiqian
2025-05-06 13:30   ` Roger Pau Monné
2025-04-21  6:18 ` [PATCH v3 02/11] driver/pci: Get next capability without passing caps Jiqian Chen
2025-04-22 15:59   ` Jan Beulich
2025-04-23  3:13     ` Chen, Jiqian
2025-04-21  6:18 ` [PATCH v3 03/11] vpci/header: Emulate legacy capability list for dom0 Jiqian Chen
2025-04-22 16:01   ` Jan Beulich
2025-04-23  3:31     ` Chen, Jiqian
2025-04-23  7:27       ` Jan Beulich
2025-05-06 13:47   ` Roger Pau Monné
2025-05-06 13:50   ` Roger Pau Monné
2025-05-07  2:46     ` Chen, Jiqian
2025-05-07  2:50       ` Chen, Jiqian
2025-05-07  7:49       ` Roger Pau Monné
2025-05-07  8:13         ` Chen, Jiqian
2025-04-21  6:18 ` [PATCH v3 04/11] vpci/header: Emulate extended " Jiqian Chen
2025-05-06 14:14   ` Roger Pau Monné
2025-05-07  3:32     ` Chen, Jiqian
2025-05-07  7:55       ` Roger Pau Monné
2025-04-21  6:18 ` [PATCH v3 05/11] vpci: Refactor REGISTER_VPCI_INIT Jiqian Chen
2025-04-22 16:03   ` Jan Beulich
2025-04-23  3:49     ` Chen, Jiqian
2025-04-23  7:36       ` Jan Beulich
2025-04-23  8:17         ` Chen, Jiqian
2025-05-06 14:37   ` Roger Pau Monné
2025-05-07  5:59     ` Chen, Jiqian
2025-05-07  8:04       ` Roger Pau Monné
2025-05-07  8:23         ` Chen, Jiqian
2025-04-21  6:18 ` [PATCH v3 06/11] vpci: Hide legacy capability when it fails to initialize Jiqian Chen
2025-05-06 16:00   ` Roger Pau Monné
2025-05-07  6:38     ` Chen, Jiqian
2025-05-07  8:07       ` Roger Pau Monné
2025-04-21  6:18 ` [PATCH v3 07/11] vpci: Hide extended " Jiqian Chen
2025-04-22 16:06   ` Jan Beulich
2025-05-08  9:16     ` Chen, Jiqian
2025-05-08  9:47       ` Roger Pau Monné
2025-05-06 16:21   ` Roger Pau Monné
2025-05-07  7:26     ` Chen, Jiqian
2025-05-07  8:09       ` Roger Pau Monné
2025-05-07  8:49         ` Chen, Jiqian
2025-05-07  9:05           ` Roger Pau Monné
2025-04-21  6:19 ` [PATCH v3 08/11] vpci: Refactor vpci_remove_register to remove matched registers Jiqian Chen
2025-05-06 16:29   ` Roger Pau Monné [this message]
2025-04-21  6:19 ` [PATCH v3 09/11] vpci/rebar: Remove registers when init_rebar() fails Jiqian Chen
2025-05-08  9:39   ` Roger Pau Monné
2025-05-09  5:27     ` Chen, Jiqian
2025-04-21  6:19 ` [PATCH v3 10/11] vpci/msi: Free MSI resources when init_msi() fails Jiqian Chen
2025-05-08  9:57   ` Roger Pau Monné
2025-04-21  6:19 ` [PATCH v3 11/11] vpci/msix: Add function to clean MSIX resources Jiqian Chen
2025-05-08 10:04   ` Roger Pau Monné
2025-05-09  5:45     ` 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=aBo44G-DuEFO4_7S@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.