All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Snow <jsnow@redhat.com>
To: Peter Crosthwaite <crosthwaitepeter@gmail.com>,
	Alistair Francis <alistair.francis@xilinx.com>
Cc: "Edgar Iglesias" <edgar.iglesias@xilinx.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	mst@redhat.com,
	"qemu-devel@nongnu.org Developers" <qemu-devel@nongnu.org>,
	"Sai Pavan Boddu" <saipava@xilinx.com>,
	"Andreas Färber" <afaerber@suse.de>
Subject: Re: [Qemu-devel] [PATCH v1 2/3] object.c: object_class_dynamic_cast return NULL if the class has no type
Date: Wed, 26 Aug 2015 17:46:44 -0400	[thread overview]
Message-ID: <55DE33C4.1010107@redhat.com> (raw)
In-Reply-To: <CAPokK=qn5Ha13y9d+rhd-HVsaROgkyJcEEc2mKfPymk6z2cEjw@mail.gmail.com>



On 08/26/2015 05:02 PM, Peter Crosthwaite wrote:
> On Wed, Aug 26, 2015 at 1:36 PM, Alistair Francis
> <alistair.francis@xilinx.com> wrote:
>> On Tue, Aug 25, 2015 at 12:43 AM, Peter Crosthwaite
>> <crosthwaitepeter@gmail.com> wrote:
>>> On Mon, Aug 24, 2015 at 4:36 PM, Alistair Francis
>>> <alistair.francis@xilinx.com> wrote:
>>>> On Mon, Aug 17, 2015 at 4:37 PM, Peter Crosthwaite
>>>> <crosthwaitepeter@gmail.com> wrote:
>>>>> On Mon, Aug 17, 2015 at 3:33 PM, Andreas Färber <afaerber@suse.de> wrote:
>>>>>> Am 18.08.2015 um 00:24 schrieb Alistair Francis:
>>>>>>> On Sat, Aug 15, 2015 at 2:22 PM, Peter Crosthwaite
>>>>>>> <crosthwaitepeter@gmail.com> wrote:
>>>>>>>> On Mon, Jul 27, 2015 at 11:37 AM, Alistair Francis
>>>>>>>> <alistair.francis@xilinx.com> wrote:
>>>>>>>>> If the ObjectClass has no type return NULL instead of trying to compare
>>>>>>>>> the type name.
>>>>>>>>>
>>>>>>>>
>>>>>>>> What was the issue?
>>>>>>>
>>>>>>> There is a seg fault in object_class_dynamic_cast() because there is
>>>>>>> no type in the ObjectClass struct.
>>>>>>
>>>>>> That should never happen, ever since TYPE_OBJECT is no longer NULL.
>>>>>>
>>>>>>> It happens when it is trying to cast the "pci-device", which is called
>>>>>>> from the ahci_irq_lower() function. The function is testing if the
>>>>>>> device is a pci device, so it should return NULL if it isn't valid.
>>>>>
>>>>> Yes so I vaguely remember this now. It is about MSI interrupts which
>>>>> have nothing to do with sysbus implementation. My solution was to rip
>>>>> that PCI specific stuff out of AHCI completely in my branch. Should
>>>>> sysbus and PCI AHCI classes install their own separate logic for this
>>>>> part via a virtualised hook?
>>>>>
>>>>> On the topic though, I notice many PCI devices have this MSI specific
>>>>> logic in them. Is it possible for devs to just treat interrupts as
>>>>> pins and the PCI layers do the MSI vs non-MSI logic switch in core
>>>>> layers?
>>>>>
>>>>> If Andreas' idea don't work this is still a core QOM bug though. I
>>>>> think object_dynamic_cast should not have this segfault when passed a
>>>>> non implementing object.
>>>>>
>>>>> Regards,
>>>>> Peter
>>>>>
>>>>>>
>>>>>> It rather sounds as if some build-time dependency is wrong, which we
>>>>>> used to run into for the Container type before Paolo macrofied this.
>>>>>>
>>>>>> Please try again with a clean build - if it still occurs, we'll need a
>>>>>> reproducible test case to investigate what is going on rather than
>>>>>> papering over a latent bug.
>>>>
>>>> Hey,
>>>>
>>>> Sorry abut the delay, but I didn't get a chance to look at this last
>>>> week. I tried with a clean setup and still see the seg fault.
>>>>
>>>> I will try to look into it more this week, but if anyone is interested
>>>> here are the steps to reproduce:
>>>>
>>>> On the latest mainline QEMU, with my 2nd and 3rd patches applied
>>>> $ ./configure --target-list="aarch64-softmmu,microblazeel-softmmu"
>>>> --disable-pie --disable-sdl --disable-werror # This is what is
>>>> required at work
>>>> $ ./aarch64-softmmu/qemu-system-aarch64 -M xlnx-ep108 -display none
>>>> -kernel ./u-boot.elf -m 8000000 -nographic -serial mon:stdio # Boot
>>>> u-boot on QEMU
>>>>
>>>> The image I'm using is available at: http://1drv.ms/1NxDXLo
>>>>
>>>
>>> So it's not a core bug. That container_of in ahci_lower_irq is
>>> incorrectly assuming that the passed AHCIState * is always for a PCI,
>>> which it is not in the sysbus case. So it's incorrectly getting the
>>> offset of QOM the object and the QOM cast is treating some invalid
>>> offset into the (or past) object as a QOM object base address.
>>>
>>> The simplest solution is a back pointer in AHCIState to the
>>> encapsulating device (would be a DeviceState *). The container_of is
>>> replaced with a nav of this pointer and then the conditional PCI cast
>>> can work.
>>
>> This seems to fix the problem.
> 
> I assume you have the appropriate setters for the new variable
> elsewhere in the code as well?
> 
>> It seems hacky though, I can't find a
>> better way to check the validity of the PCIDevice. Any ideas?
>>
> 
> So there a few problems in the way of a correct solution. The caller
> for ahci_lower_irq does not have access to the QOM object pointer,
> it's been abstracted away by AHCIState (which is not a QOM object). So
> you would need to replumb the call path to ahci_lower_irq to pass the
> QOM object. This would let you drop the container_of completely.
> 
> The next step would be to virtualise ahci_lower_irq, as this is
> implementation dependent (assume specific devices really do need to
> control the use of PCI MSI?), one implementation for sysbus, one for
> PCI. This is blocked by the re-plumbing described above as the
> virtualised called itself will need a ptr to the QOM object.
> 
> But I think the back ptr is an acceptable solution for the meantime,
> this is a clear bug in Sysbus AHCI and should probably even go to
> qemu-stable.
> 

I'm not intricately familiar with how the QOM plumbing works, but I can
definitely see how assuming all AHCIState pointers come from
AHCIPCIState is a problem...

For the uninitiated, how does MSI work with Sysbus? What does a Sysbus
AHCI device look like to a guest, and what happens if it tries to
utilize the functionality?

(Well, segfault, I guess.)

If someone wants to clue in the device model newbie and send a patch my
way, I'll take it.

--js

>> diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
>> index 02d85fa..77e58a9 100644
>> --- a/hw/ide/ahci.c
>> +++ b/hw/ide/ahci.c
>> @@ -137,8 +137,11 @@ static void ahci_irq_raise(AHCIState *s, AHCIDevice *dev)
>>  static void ahci_irq_lower(AHCIState *s, AHCIDevice *dev)
>>  {
>>      AHCIPCIState *d = container_of(s, AHCIPCIState, ahci);
>> -    PCIDevice *pci_dev =
>> -        (PCIDevice *)object_dynamic_cast(OBJECT(d), TYPE_PCI_DEVICE);
>> +    PCIDevice *pci_dev = NULL;
>> +
>> +    if (s->parent_obj) {
> 
> I would make the parent obj compulsory for all AHCIState
> implementations and drop the NULL guard.
> 
>> +        pci_dev = PCI_DEVICE(d);
>> +    }
>>
>>      DPRINTF(0, "lower irq\n");
>>
>> diff --git a/hw/ide/ahci.h b/hw/ide/ahci.h
>> index c055d6b..ac7d2de 100644
>> --- a/hw/ide/ahci.h
>> +++ b/hw/ide/ahci.h
>> @@ -287,6 +287,8 @@ struct AHCIDevice {
>>  };
>>
>>  typedef struct AHCIState {
>> +    DeviceState *parent_obj;
> 
> This name is really for QOM inline parents. We decided a while back to
> use "parent" for the QOM parents and "container" for non-parental
> containers. Memory regions use the .container field for a similar
> purpose.
> 
> Regards,
> Peter
> 
>> +
>>      AHCIDevice *dev;
>>      AHCIControlRegs control_regs;
>>      MemoryRegion mem;
>>
>> Thanks,
>>
>> Alistair
>>
>>>
>>> Regards,
>>> Peter
>>>
>>>> Thanks,
>>>>
>>>> Alistair
>>>>
>>>>>>
>>>>>> Thanks,
>>>>>> Andreas
>>>>>>
>>>>>> --
>>>>>> SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
>>>>>> GF: Felix Imendörffer, Jane Smithard, Graham Norton; HRB 21284 (AG Nürnberg)
>>>>>
>>>

  reply	other threads:[~2015-08-26 21:46 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-27 18:37 [Qemu-devel] [PATCH v1 0/3] xlnx-zynqmp: Connect the AHCI SATA device Alistair Francis
2015-07-27 18:37 ` [Qemu-devel] [PATCH v1 1/3] ahci: Separate the AHCI state structure into the header Alistair Francis
2015-07-29 22:21   ` John Snow
2015-07-30  0:12     ` Alistair Francis
2015-08-15 21:18       ` Peter Crosthwaite
2015-08-15 21:57         ` Peter Maydell
2015-08-15 21:21   ` Peter Crosthwaite
2015-08-15 21:25     ` Peter Crosthwaite
2015-08-17 22:31       ` Alistair Francis
2015-07-27 18:37 ` [Qemu-devel] [PATCH v1 2/3] object.c: object_class_dynamic_cast return NULL if the class has no type Alistair Francis
2015-08-15 21:22   ` Peter Crosthwaite
2015-08-17 22:24     ` Alistair Francis
2015-08-17 22:33       ` Andreas Färber
2015-08-17 23:37         ` Peter Crosthwaite
2015-08-24 23:36           ` Alistair Francis
2015-08-25  7:43             ` Peter Crosthwaite
2015-08-26 20:36               ` Alistair Francis
2015-08-26 21:02                 ` Peter Crosthwaite
2015-08-26 21:46                   ` John Snow [this message]
2015-08-26 22:15                     ` Peter Crosthwaite
2015-08-26 22:39                       ` Peter Maydell
2015-08-26 23:11                       ` John Snow
2015-08-27 18:56                         ` Alistair Francis
2015-07-27 18:37 ` [Qemu-devel] [PATCH v1 3/3] xlnx-zynqmp: Connect the sysbus AHCI to ZynqMP Alistair Francis
2015-08-15 21:29   ` Peter Crosthwaite
2015-08-17 22:38     ` Alistair Francis
2015-08-14 17:24 ` [Qemu-devel] [PATCH v1 0/3] xlnx-zynqmp: Connect the AHCI SATA device Alistair Francis

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=55DE33C4.1010107@redhat.com \
    --to=jsnow@redhat.com \
    --cc=afaerber@suse.de \
    --cc=alistair.francis@xilinx.com \
    --cc=crosthwaitepeter@gmail.com \
    --cc=edgar.iglesias@xilinx.com \
    --cc=mst@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=saipava@xilinx.com \
    /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.