From: David Gibson <david@gibson.dropbear.id.au>
To: Greg Kurz <groug@kaod.org>
Cc: "Daniel Henrique Barboza" <danielhb@linux.ibm.com>,
qemu-ppc@nongnu.org, "Cédric Le Goater" <clg@kaod.org>,
qemu-devel@nongnu.org
Subject: Re: [PATCH for-5.2 4/5] spapr/xive: Convert KVM device fd checks to assert()
Date: Thu, 6 Aug 2020 15:09:08 +1000 [thread overview]
Message-ID: <20200806050908.GD100968@yekko.fritz.box> (raw)
In-Reply-To: <159664894478.638781.7802223440952803421.stgit@bahia.lan>
[-- Attachment #1: Type: text/plain, Size: 3746 bytes --]
On Wed, Aug 05, 2020 at 07:35:44PM +0200, Greg Kurz wrote:
> All callers guard these functions with kvmppc_xive_in_kernel() or one
> of its variants. Make it clear that these functions are only to be
> called when the KVM XIVE device is active.
>
> Note that the check on xive is dropped in kvmppc_xive_disconnect(). It
> really cannot be NULL since it comes from set_active_intc() which only
> passes pointers to allocated objects.
>
> Signed-off-by: Greg Kurz <groug@kaod.org>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> ---
> hw/intc/spapr_xive_kvm.c | 35 +++++++----------------------------
> 1 file changed, 7 insertions(+), 28 deletions(-)
>
> diff --git a/hw/intc/spapr_xive_kvm.c b/hw/intc/spapr_xive_kvm.c
> index a9657e2b0cda..3364832de83a 100644
> --- a/hw/intc/spapr_xive_kvm.c
> +++ b/hw/intc/spapr_xive_kvm.c
> @@ -79,10 +79,7 @@ void kvmppc_xive_cpu_set_state(XiveTCTX *tctx, Error **errp)
> uint64_t state[2];
> int ret;
>
> - /* The KVM XIVE device is not in use yet */
> - if (xive->fd == -1) {
> - return;
> - }
> + assert(xive->fd != -1);
>
> /* word0 and word1 of the OS ring. */
> state[0] = *((uint64_t *) &tctx->regs[TM_QW1_OS]);
> @@ -101,10 +98,7 @@ void kvmppc_xive_cpu_get_state(XiveTCTX *tctx, Error **errp)
> uint64_t state[2] = { 0 };
> int ret;
>
> - /* The KVM XIVE device is not in use */
> - if (xive->fd == -1) {
> - return;
> - }
> + assert(xive->fd != -1);
>
> ret = kvm_get_one_reg(tctx->cs, KVM_REG_PPC_VP_STATE, state);
> if (ret != 0) {
> @@ -156,10 +150,7 @@ void kvmppc_xive_cpu_connect(XiveTCTX *tctx, Error **errp)
> unsigned long vcpu_id;
> int ret;
>
> - /* The KVM XIVE device is not in use */
> - if (xive->fd == -1) {
> - return;
> - }
> + assert(xive->fd != -1);
>
> /* Check if CPU was hot unplugged and replugged. */
> if (kvm_cpu_is_enabled(tctx->cs)) {
> @@ -245,10 +236,7 @@ int kvmppc_xive_source_reset_one(XiveSource *xsrc, int srcno, Error **errp)
> SpaprXive *xive = SPAPR_XIVE(xsrc->xive);
> uint64_t state = 0;
>
> - /* The KVM XIVE device is not in use */
> - if (xive->fd == -1) {
> - return -ENODEV;
> - }
> + assert(xive->fd != -1);
>
> if (xive_source_irq_is_lsi(xsrc, srcno)) {
> state |= KVM_XIVE_LEVEL_SENSITIVE;
> @@ -592,10 +580,7 @@ static void kvmppc_xive_change_state_handler(void *opaque, int running,
>
> void kvmppc_xive_synchronize_state(SpaprXive *xive, Error **errp)
> {
> - /* The KVM XIVE device is not in use */
> - if (xive->fd == -1) {
> - return;
> - }
> + assert(xive->fd != -1);
>
> /*
> * When the VM is stopped, the sources are masked and the previous
> @@ -622,10 +607,7 @@ int kvmppc_xive_pre_save(SpaprXive *xive)
> {
> Error *local_err = NULL;
>
> - /* The KVM XIVE device is not in use */
> - if (xive->fd == -1) {
> - return 0;
> - }
> + assert(xive->fd != -1);
>
> /* EAT: there is no extra state to query from KVM */
>
> @@ -845,10 +827,7 @@ void kvmppc_xive_disconnect(SpaprInterruptController *intc)
> XiveSource *xsrc;
> size_t esb_len;
>
> - /* The KVM XIVE device is not in use */
> - if (!xive || xive->fd == -1) {
> - return;
> - }
> + assert(xive->fd != -1);
>
> /* Clear the KVM mapping */
> xsrc = &xive->source;
>
>
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2020-08-06 12:12 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-05 17:35 [PATCH for-5.2 0/5] spapr: Cleanups for XIVE and PHB Greg Kurz
2020-08-05 17:35 ` [PATCH for-5.2 1/5] spapr/xive: Fix xive->fd if kvm_create_device() fails Greg Kurz
2020-08-06 5:05 ` David Gibson
2020-08-05 17:35 ` [PATCH for-5.2 2/5] spapr/xive: Simplify kvmppc_xive_disconnect() Greg Kurz
2020-08-06 5:05 ` David Gibson
2020-08-05 17:35 ` [PATCH for-5.2 3/5] ppc/xive: Introduce dedicated kvm_irqchip_in_kernel() wrappers Greg Kurz
2020-08-06 5:08 ` David Gibson
2020-08-06 9:23 ` Greg Kurz
2020-08-05 17:35 ` [PATCH for-5.2 4/5] spapr/xive: Convert KVM device fd checks to assert() Greg Kurz
2020-08-06 5:09 ` David Gibson [this message]
2020-08-05 17:35 ` [PATCH for-5.2 5/5] spapr: Simplify error handling in spapr_phb_realize() Greg Kurz
2020-08-06 5:10 ` David Gibson
2020-08-05 17:43 ` [PATCH for-5.2 0/5] spapr: Cleanups for XIVE and PHB no-reply
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=20200806050908.GD100968@yekko.fritz.box \
--to=david@gibson.dropbear.id.au \
--cc=clg@kaod.org \
--cc=danielhb@linux.ibm.com \
--cc=groug@kaod.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.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 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).