From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50427) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YOFv8-0006nH-Rb for qemu-devel@nongnu.org; Wed, 18 Feb 2015 20:28:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YOFv4-0004qN-Rr for qemu-devel@nongnu.org; Wed, 18 Feb 2015 20:28:50 -0500 Received: from e9.ny.us.ibm.com ([32.97.182.139]:40932) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YOFv4-0004qD-Of for qemu-devel@nongnu.org; Wed, 18 Feb 2015 20:28:46 -0500 Received: from /spool/local by e9.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 18 Feb 2015 20:28:43 -0500 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Michael Roth In-Reply-To: <20150216053209.GA8304@shangw> References: <1424042162-12249-1-git-send-email-gwshan@linux.vnet.ibm.com> <1424042162-12249-2-git-send-email-gwshan@linux.vnet.ibm.com> <20150216015248.GG26645@voom.fritz.box> <20150216053209.GA8304@shangw> Message-ID: <20150219012829.22240.51782@loki> Date: Wed, 18 Feb 2015 19:28:29 -0600 Subject: Re: [Qemu-devel] [PATCH v18 1/2] sPAPR: Implement EEH RTAS calls List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gavin Shan , David Gibson Cc: agraf@suse.de, aik@ozlabs.ru, qemu-devel@nongnu.org, alex.williamson@redhat.com, qemu-ppc@nongnu.org Quoting Gavin Shan (2015-02-15 23:32:09) > On Mon, Feb 16, 2015 at 12:52:48PM +1100, David Gibson wrote: > >On Mon, Feb 16, 2015 at 10:16:01AM +1100, Gavin Shan wrote: > >> The emulation for EEH RTAS requests from guest isn't covered > >> by QEMU yet and the patch implements them. > >> = > >> The patch defines constants used by EEH RTAS calls and adds > >> callbacks sPAPRPHBClass::{eeh_set_option, eeh_get_state, eeh_reset, > >> eeh_configure}, which are going to be used as follows: > >> = > >> * RTAS calls are received in spapr_pci.c, sanity check is done > >> there. > >> * RTAS handlers handle what they can. If there is something it > >> cannot handle and the corresponding sPAPRPHBClass callback is > >> defined, it is called. > >> * Those callbacks are only implemented for VFIO now. They do ioctl() > >> to the IOMMU container fd to complete the calls. Error codes from > >> that ioctl() are transferred back to the guest. > >> = > >> [aik: defined RTAS tokens for EEH RTAS calls] > >> Signed-off-by: Gavin Shan > >> --- > >> hw/ppc/spapr_pci.c | 281 +++++++++++++++++++++++++++++++++++= +++++++++ > >> include/hw/pci-host/spapr.h | 4 + > >> include/hw/ppc/spapr.h | 43 ++++++- > >> 3 files changed, 326 insertions(+), 2 deletions(-) > >> = > >> diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c > >> index cebdeb3..29b071d 100644 > >> --- a/hw/ppc/spapr_pci.c > >> +++ b/hw/ppc/spapr_pci.c > >> @@ -406,6 +406,268 @@ static void rtas_ibm_query_interrupt_source_numb= er(PowerPCCPU *cpu, > >> rtas_st(rets, 2, 1);/* 0 =3D=3D level; 1 =3D=3D edge */ > >> } > >> = > >> +static void rtas_ibm_set_eeh_option(PowerPCCPU *cpu, > >> + sPAPREnvironment *spapr, > >> + uint32_t token, uint32_t nargs, > >> + target_ulong args, uint32_t nret, > >> + target_ulong rets) > >> +{ > >> + sPAPRPHBState *sphb; > >> + sPAPRPHBClass *spc; > >> + uint32_t addr, option; > >> + uint64_t buid; > >> + int ret; > >> + > >> + if ((nargs !=3D 4) || (nret !=3D 1)) { > >> + goto param_error_exit; > >> + } > >> + > >> + buid =3D ((uint64_t)rtas_ld(args, 1) << 32) | rtas_ld(args, 2); > >> + addr =3D rtas_ld(args, 0); > >> + option =3D rtas_ld(args, 3); > >> + > >> + sphb =3D find_phb(spapr, buid); > >> + if (!sphb) { > >> + goto param_error_exit; > >> + } > >> + > >> + spc =3D SPAPR_PCI_HOST_BRIDGE_GET_CLASS(sphb); > >> + if (!spc->eeh_set_option) { > >> + goto param_error_exit; > >> + } > >> + > >> + /* > >> + * The EEH functionality is enabled on basis of PCI device, > >> + * instead of PE. We need check the validity of the PCI > >> + * device address. > >> + */ > >> + if (option =3D=3D RTAS_EEH_ENABLE && > >> + !find_dev(spapr, buid, addr)) { > >> + goto param_error_exit; > >> + } > > > >You're still breaking your layering by doing checks dependent on the > >specific option both here and in the callback. > > > >What I meant by my comments on the previous version was that this > >find_dev() test should also move into the eeh_set_option callback. > >Obviously that means adding addr into the parameters - but surely if > >the addr has any meaning whatsoever, it must be at least potentially > >needed by the callback anyway. > > > = > Ok. Either simply dropping the check here, or moving find_dev() to > sPAPRPHBClass::eeh_set_option() as you suggested. However, there're more > things needed for sPAPRPHBClass::eeh_set_option() to do the check as foll= ows. > David, could you help to confirm which way you prefer? > = > - Rename find_dev() to spapr_find_pci_dev() and make it public. It will be > called in spapr_pci_vfio.c > - Add one field sPAPRPHBState::spapr to reference the associated sPAPREnv= ironment, > which is required by spapr_find_pci_dev(). Otherwise, we have to pass s= PAPREnvironment > to sPAPRPHBClass::eeh_set_option(). AFAICT spapr_pci.c:find_dev() only needs sPAPREnvironment to look up the phb given a buid, but in your case you already have the phb and pass it on to eeh_set_option(), so within eeh_set_option() you can call pci_find_device() just like spapr_pci.c:find_dev() does to do the validation. The validation seems to assume the addr value is a config_addr for the devi= ce though, isn't it possible we might recieve a pe_addr of the form returned by rtas_ibm_get_config_addr_info2? That value would happen to correspond to bus:n,device:0,func:0,reg:1, and find_dev in that case would just mask off the reg value and verify there's a device in PCI slot 0, instead of whatever actually needs to be validated in that situation (which isn't clear to me). > = > Thanks, > Gavin > = > >Apart from that, > > > >Reviewed-by: David Gibson > > > >-- = > >David Gibson | I'll have my music baroque, and my code > >david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _othe= r_ > > | _way_ _around_! > >http://www.ozlabs.org/~dgibson