static void spapr_reallocate_hpt(sPAPRMachineState *spapr, int shift,

                                 Error **errp)

{

    long rc;



    /* Clean up any HPT info from a previous boot */

    g_free(spapr->htab);

    spapr->htab = NULL;

    spapr->htab_shift = 0;

    close_htab_fd(spapr);



    rc = kvmppc_reset_htab(shift);

    if (rc < 0) {

        /* kernel-side HPT needed, but couldn't allocate one */

        error_setg_errno(errp, errno,

                         "Failed to allocate KVM HPT of order %d (try smaller maxmem?)",

                         shift);

        /* This is almost certainly fatal, but if the caller really

         * wants to carry on with shift == 0, it's welcome to try */

    } else if (rc > 0) {

        /* kernel-side HPT allocated */

        if (rc != shift) {

            error_setg(errp,

                       "Requested order %d HPT, but kernel allocated order %ld (try smaller maxmem?)",

                       shift, rc);

        }



        spapr->htab_shift = shift;

        kvmppc_kern_htab = true;

    } else {

        /* kernel-side HPT not needed, allocate in userspace instead */

        size_t size = 1ULL << shift;

        int i;



        spapr->htab = qemu_memalign(size, size);

        if (!spapr->htab) {

            error_setg_errno(errp, errno,

                             "Could not allocate HPT of order %d", shift);

            return;

        }



        memset(spapr->htab, 0, size);

        spapr->htab_shift = shift;

        kvmppc_kern_htab = false;



        for (i = 0; i < size / HASH_PTE_SIZE_64; i++) {

            DIRTY_HPTE(HPTE(spapr->htab, i));

        }

    }

}

static void spapr_reallocate_hpt(sPAPRMachineState *spapr, int shift,

                                 Error **errp)

{

    long rc;



    

    g_free(spapr->htab);

    spapr->htab = NULL;

    spapr->htab_shift = 0;

    close_htab_fd(spapr);



    rc = kvmppc_reset_htab(shift);

    if (rc < 0) {

        

        error_setg_errno(errp, errno,

                         "Failed to allocate KVM HPT of order %d (try smaller maxmem?)",

                         shift);

        



    } else if (rc > 0) {

        

        if (rc != shift) {

            error_setg(errp,

                       "Requested order %d HPT, but kernel allocated order %ld (try smaller maxmem?)",

                       shift, rc);

        }



        spapr->htab_shift = shift;

        kvmppc_kern_htab = true;

    } else {

        

        size_t size = 1ULL << shift;

        int i;



        spapr->htab = qemu_memalign(size, size);

        if (!spapr->htab) {

            error_setg_errno(errp, errno,

                             "Could not allocate HPT of order %d", shift);

            return;

        }



        memset(spapr->htab, 0, size);

        spapr->htab_shift = shift;

        kvmppc_kern_htab = false;



        for (i = 0; i < size / HASH_PTE_SIZE_64; i++) {

            DIRTY_HPTE(HPTE(spapr->htab, i));

        }

    }

}

static void FUNC_0(sPAPRMachineState *VAR_0, int VAR_1,

                                 Error **VAR_2)

{

    long VAR_3;



    

    g_free(VAR_0->htab);

    VAR_0->htab = NULL;

    VAR_0->htab_shift = 0;

    close_htab_fd(VAR_0);



    VAR_3 = kvmppc_reset_htab(VAR_1);

    if (VAR_3 < 0) {

        

        error_setg_errno(VAR_2, errno,

                         "Failed to allocate KVM HPT of order %d (try smaller maxmem?)",

                         VAR_1);

        



    } else if (VAR_3 > 0) {

        

        if (VAR_3 != VAR_1) {

            error_setg(VAR_2,

                       "Requested order %d HPT, but kernel allocated order %ld (try smaller maxmem?)",

                       VAR_1, VAR_3);

        }



        VAR_0->htab_shift = VAR_1;

        kvmppc_kern_htab = true;

    } else {

        

        size_t size = 1ULL << VAR_1;

        int VAR_4;



        VAR_0->htab = qemu_memalign(size, size);

        if (!VAR_0->htab) {

            error_setg_errno(VAR_2, errno,

                             "Could not allocate HPT of order %d", VAR_1);

            return;

        }



        memset(VAR_0->htab, 0, size);

        VAR_0->htab_shift = VAR_1;

        kvmppc_kern_htab = false;



        for (VAR_4 = 0; VAR_4 < size / HASH_PTE_SIZE_64; VAR_4++) {

            DIRTY_HPTE(HPTE(VAR_0->htab, VAR_4));

        }

    }

}

static void FUNC_0(sPAPRMachineState *VAR_0, int VAR_1,
Error **VAR_2)
{ long VAR_3; g_free(VAR_0->htab); VAR_0->htab = NULL; VAR_0->htab_shift = 0; close_htab_fd(VAR_0); VAR_3 = kvmppc_reset_htab(VAR_1); if (VAR_3 < 0) { error_setg_errno(VAR_2, errno,
"Failed to allocate KVM HPT of order %d (try smaller maxmem?)",
VAR_1); } else if (VAR_3 > 0) { if (VAR_3 != VAR_1) { error_setg(VAR_2,
"Requested order %d HPT, but kernel allocated order %ld (try smaller maxmem?)",
VAR_1, VAR_3); } VAR_0->htab_shift = VAR_1; kvmppc_kern_htab = true; } else { size_t size = 1ULL << VAR_1; int VAR_4; VAR_0->htab = qemu_memalign(size, size); if (!VAR_0->htab) { error_setg_errno(VAR_2, errno,
"Could not allocate HPT of order %d", VAR_1); return; } memset(VAR_0->htab, 0, size); VAR_0->htab_shift = VAR_1; kvmppc_kern_htab = false; for (VAR_4 = 0; VAR_4 < size / HASH_PTE_SIZE_64; VAR_4++) { DIRTY_HPTE(HPTE(VAR_0->htab, VAR_4)); } } }