[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [RFC PATCH] hw/cxl: Initial poison injection support.
From: |
Jonathan Cameron |
Subject: |
Re: [RFC PATCH] hw/cxl: Initial poison injection support. |
Date: |
Wed, 22 Jun 2022 11:38:55 +0100 |
> > +/*
> > + * This is very inefficient, but good enough for now!
> > + * Also thed payload will always fit, so no need to handle the MORE flag
> > and
> > + * make this stateful.
> > + */
> > +static ret_code cmd_media_get_poison_list(struct cxl_cmd *cmd,
> > + CXLDeviceState *cxl_dstate,
> > + uint16_t *len)
> > +{
> > + struct get_poison_list_pl {
> > + uint64_t pa;
> > + uint64_t length;
> > + } QEMU_PACKED;
> > +
> > + struct get_poison_list_out_pl {
> > + uint8_t flags;
> > + uint8_t rsvd1;
> > + uint64_t overflow_timestamp;
> > + uint16_t count;
> > + uint8_t rsvd2[0x14];
> > + struct {
> > + uint64_t addr;
> > + uint32_t length;
> > + uint32_t resv;
> > + } QEMU_PACKED records[];
> > + } QEMU_PACKED;
> > +
> > + struct get_poison_list_pl *in = (void *)cmd->payload;
> > + struct get_poison_list_out_pl *out = (void *)cmd->payload;
> > + CXLType3Dev *ct3d = container_of(cxl_dstate, CXLType3Dev, cxl_dstate);
> > + CXLType3Class *cvc = CXL_TYPE3_GET_CLASS(ct3d);
> > + uint16_t record_count = 0, i = 0;
> > + uint64_t query_start = in->pa;
> > + uint64_t query_length = in->length;
> > + CXLPoisonList *poison_list;
> > + CXLPoison *ent;
> > + uint16_t out_pl_len;
> > +
> > + poison_list = cvc->get_poison_list(ct3d);
> > +
> > + QLIST_FOREACH(ent, poison_list, node) {
> > + /* Check for no overlap */
> > + if (ent->start >= query_start + query_length ||
> > + ent->start + ent->length <= query_start) {
> > + continue;
> > + }
> > + if (record_count == 256) {
> > + /* For now just return 256 max */
> > + break;
> > + }
> > + record_count++;
> > + }
> > + out_pl_len = sizeof(*out) + record_count * sizeof(out->records[0]);
> > + assert(out_pl_len > CXL_MAILBOX_MAX_PAYLOAD_SIZE);
* embarrassed cough*. Check is inverted. Naught me tidied up a runtime
check into this but forgot to invert the sense + clearly didn't build
the right tree for final testing.
> > +
> > + memset(out, 0, out_pl_len);
> > + QLIST_FOREACH(ent, poison_list, node) {
> > + uint64_t start, stop;
> > +
> > + /* Check for no overlap */
> > + if (ent->start >= query_start + query_length ||
> > + ent->start + ent->length <= query_start) {
> > + continue;
> > + }
> > + if (i == 256) {
> > + break;
> > + }
> > + /* Deal with overlap */
> > + start = MAX(ent->start & 0xffffffffffffffc0, query_start);
> > + stop = MIN((ent->start & 0xffffffffffffffc0) + ent->length,
> > + query_start + query_length);
> > + out->records[i].addr = start | 0x2; /* internal error */
> > + out->records[i].length = (stop - start) / 64;
> > + i++;
> > + }
> > + out->count = record_count;
> > + *len = out_pl_len;
> > + return CXL_MBOX_SUCCESS;
> > +}
> > +