[{"id":1770858,"web_url":"http://patchwork.ozlabs.org/comment/1770858/","msgid":"<20170919075008.GP27153@umbus>","list_archive_url":null,"date":"2017-09-19T07:50:08","subject":"Re: [Qemu-devel] [RFC PATCH v2 12/21] ppc/xive: notify the CPU when\n\tinterrupt priority is more privileged","submitter":{"id":47,"url":"http://patchwork.ozlabs.org/api/people/47/","name":"David Gibson","email":"david@gibson.dropbear.id.au"},"content":"On Mon, Sep 11, 2017 at 07:12:26PM +0200, Cédric Le Goater wrote:\n> The Pending Interrupt Priority Register (PIPR) contains the priority\n> of the most favored pending notification. It is calculated from the\n> Interrupt Pending Buffer (IPB) which indicates a pending interrupt at\n> the priority corresponding to the bit number.\n> \n> If the PIPR is more favored (1) than the Current Processor Priority\n> Register (CPPR), the CPU interrupt line can be raised and the EO bit\n> of the Notification Source Register is updated to notify the presence\n> of an exception for the O/S. The check needs to be done whenever the\n> PIPR or the CPPR is changed.\n> \n> (1) numerically less than\n> \n> Signed-off-by: Cédric Le Goater <clg@kaod.org>\n> ---\n>  hw/intc/spapr_xive.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++\n>  1 file changed, 50 insertions(+)\n> \n> diff --git a/hw/intc/spapr_xive.c b/hw/intc/spapr_xive.c\n> index 4bc61cfda67a..e5d4b723b7e0 100644\n> --- a/hw/intc/spapr_xive.c\n> +++ b/hw/intc/spapr_xive.c\n> @@ -28,11 +28,39 @@\n>  #include \"xive-internal.h\"\n>  \n>  \n> +/* Convert a priority number to an Interrupt Pending Buffer (IPB)\n> + * register, which indicates a pending interrupt at the priority\n> + * corresponding to the bit number\n> + */\n> +static uint8_t priority_to_ipb(uint8_t priority)\n> +{\n> +    return priority > XIVE_PRIORITY_MAX ? 0 :  1 << (7 - priority);\n> +}\n> +\n> +/* Convert an Interrupt Pending Buffer (IPB) register to a Pending\n> + * Interrupt Priority Register (PIPR), which contains the priority of\n> + * the most favored pending notification.\n> + *\n> + * TODO: PIPR can never be OxFF. Needs a fix.\n> + */\n> +static uint8_t ipb_to_pipr(uint8_t ibp)\n> +{\n> +    return ibp ? clz32((uint32_t)ibp << 24) : 0xff;\n> +}\n> +\n>  static uint64_t spapr_xive_icp_accept(ICPState *icp)\n>  {\n>      return 0;\n>  }\n>  \n> +static void spapr_xive_icp_notify(ICPState *icp)\n> +{\n> +    if (icp->tima_os[TM_PIPR] < icp->tima_os[TM_CPPR]) {\n> +        icp->tima_os[TM_NSR] |= TM_QW1_NSR_EO;\n> +        qemu_irq_raise(ICP(icp)->output);\n\nThe CPU interrupt lines are effectively level sensitive, but you never\nlower this, AFAICT.\n\n> +    }\n> +}\n> +\n>  static void spapr_xive_icp_set_cppr(ICPState *icp, uint8_t cppr)\n>  {\n>      if (cppr > XIVE_PRIORITY_MAX) {\n> @@ -40,6 +68,10 @@ static void spapr_xive_icp_set_cppr(ICPState *icp, uint8_t cppr)\n>      }\n>  \n>      icp->tima_os[TM_CPPR] = cppr;\n> +\n> +    /* CPPR has changed, inform the ICP which might raise an\n> +     * exception */\n> +    spapr_xive_icp_notify(icp);\n>  }\n>  \n>  /*\n> @@ -206,6 +238,8 @@ static void spapr_xive_irq(sPAPRXive *xive, int srcno)\n>      XiveEQ *eq;\n>      uint32_t eq_idx;\n>      uint32_t priority;\n> +    uint32_t target;\n> +    ICPState *icp;\n>  \n>      ive = spapr_xive_get_ive(xive, srcno);\n>      if (!ive || !(ive->w & IVE_VALID)) {\n> @@ -235,6 +269,13 @@ static void spapr_xive_irq(sPAPRXive *xive, int srcno)\n>          qemu_log_mask(LOG_UNIMP, \"XIVE: !UCOND_NOTIFY not implemented\\n\");\n>      }\n>  \n> +    target = GETFIELD(EQ_W6_NVT_INDEX, eq->w6);\n> +    icp = xics_icp_get(xive->ics->xics, target);\n> +    if (!icp) {\n> +        qemu_log_mask(LOG_GUEST_ERROR, \"XIVE: No ICP for target %d\\n\", target);\n> +        return;\n> +    }\n> +\n>      if (GETFIELD(EQ_W6_FORMAT_BIT, eq->w6) == 0) {\n>          priority = GETFIELD(EQ_W7_F0_PRIORITY, eq->w7);\n>  \n> @@ -242,9 +283,18 @@ static void spapr_xive_irq(sPAPRXive *xive, int srcno)\n>          if (priority == 0xff) {\n>              return;\n>          }\n> +\n> +        /* Update the IPB (Interrupt Pending Buffer) with the priority\n> +         * of the new notification and inform the ICP, which will\n> +         * decide to raise the exception, or not, depending the CPPR.\n> +         */\n> +        icp->tima_os[TM_IPB] |= priority_to_ipb(priority);\n> +        icp->tima_os[TM_PIPR] = ipb_to_pipr(icp->tima_os[TM_IPB]);\n>      } else {\n>          qemu_log_mask(LOG_UNIMP, \"XIVE: w7 format1 not implemented\\n\");\n>      }\n> +\n> +    spapr_xive_icp_notify(icp);\n>  }\n>  \n>  /*","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=gibson.dropbear.id.au\n\theader.i=@gibson.dropbear.id.au header.b=\"AMtBQ/D1\"; \n\tdkim-atps=neutral"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xxKWK5XK6z9s7m\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 19 Sep 2017 20:54:21 +1000 (AEST)","from localhost ([::1]:41444 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1duGAV-0006zn-T0\n\tfor incoming@patchwork.ozlabs.org; Tue, 19 Sep 2017 06:54:19 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:51158)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <dgibson@ozlabs.org>) id 1duFtV-0001FM-Uh\n\tfor qemu-devel@nongnu.org; Tue, 19 Sep 2017 06:36:49 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <dgibson@ozlabs.org>) id 1duFtT-0002sR-IH\n\tfor qemu-devel@nongnu.org; Tue, 19 Sep 2017 06:36:45 -0400","from ozlabs.org ([2401:3900:2:1::2]:34471)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <dgibson@ozlabs.org>)\n\tid 1duFtT-0002ob-4m; Tue, 19 Sep 2017 06:36:43 -0400","by ozlabs.org (Postfix, from userid 1007)\n\tid 3xxK6q40M5z9t3J; Tue, 19 Sep 2017 20:36:34 +1000 (AEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple;\n\td=gibson.dropbear.id.au; s=201602; t=1505817395;\n\tbh=+tQ5nxkB+n3iMCWqCV4vv8+zX9mm3Dmwx4OPBFyrta4=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=AMtBQ/D1LX1JTTBfeDeNy/b6ZD08zvCXDSsPs8AFc9Q9sA6m4AnMNJ1hU0UzzhC3o\n\tRl2mRlXRu3qRHsP7Y4xNSGNlYjSLhzfeknYr7asRPNUkYANcFVl784WyuTMH0OXv5O\n\tKNm7cicgYt6wf17BMAflD50OrGV2wdbP27q6WYeY=","Date":"Tue, 19 Sep 2017 17:50:08 +1000","From":"David Gibson <david@gibson.dropbear.id.au>","To":"=?iso-8859-1?q?C=E9dric?= Le Goater <clg@kaod.org>","Message-ID":"<20170919075008.GP27153@umbus>","References":"<20170911171235.29331-1-clg@kaod.org>\n\t<20170911171235.29331-13-clg@kaod.org>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"hHiQ9nAwW5IGN2dL\"","Content-Disposition":"inline","In-Reply-To":"<20170911171235.29331-13-clg@kaod.org>","User-Agent":"Mutt/1.8.3 (2017-05-23)","X-detected-operating-system":"by eggs.gnu.org: Genre and OS details not\n\trecognized.","X-Received-From":"2401:3900:2:1::2","Subject":"Re: [Qemu-devel] [RFC PATCH v2 12/21] ppc/xive: notify the CPU when\n\tinterrupt priority is more privileged","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Alexey Kardashevskiy <aik@ozlabs.ru>, qemu-ppc@nongnu.org,\n\tqemu-devel@nongnu.org, Alexander Graf <agraf@suse.de>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}}]