From mboxrd@z Thu Jan 1 00:00:00 1970 From: Claudio Imbrenda Subject: [PATCH v2 1/2] KVM: s390x: some utility functions for migration Date: Thu, 18 Jan 2018 13:56:37 +0100 Message-ID: <1516280198-25386-2-git-send-email-imbrenda@linux.vnet.ibm.com> References: <1516280198-25386-1-git-send-email-imbrenda@linux.vnet.ibm.com> Cc: borntraeger@de.ibm.com, cohuck@redhat.com, pbonzini@redhat.com, david@redhat.com, schwidefsky@de.ibm.com, frankja@linux.vnet.ibm.com To: kvm@vger.kernel.org Return-path: Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:42752 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755039AbeARM4s (ORCPT ); Thu, 18 Jan 2018 07:56:48 -0500 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w0ICtcu9045333 for ; Thu, 18 Jan 2018 07:56:48 -0500 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 2fjsne761x-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 18 Jan 2018 07:56:47 -0500 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 18 Jan 2018 12:56:43 -0000 In-Reply-To: <1516280198-25386-1-git-send-email-imbrenda@linux.vnet.ibm.com> Sender: kvm-owner@vger.kernel.org List-ID: These are some utilty functions that will be used later on for storage attributes migration. Signed-off-by: Claudio Imbrenda --- arch/s390/kvm/kvm-s390.c | 32 ++++++++++++++++++++++++++++++++ arch/s390/kvm/kvm-s390.h | 6 ++++++ 2 files changed, 38 insertions(+) diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c index 6f17031..5a69334 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -1512,6 +1512,38 @@ static long kvm_s390_set_skeys(struct kvm *kvm, struct kvm_s390_skeys *args) #define KVM_S390_CMMA_SIZE_MAX ((u32)KVM_S390_SKEYS_MAX) /* + * Similar to gfn_to_memslot, but returns a memslot also when the address falls + * in a hole. In that case a memslot near the hole is returned. + */ +static int gfn_to_memslot_approx(struct kvm *kvm, gfn_t gfn) +{ + struct kvm_memslots *slots = kvm_memslots(kvm); + int start = 0, end = slots->used_slots; + int slot = atomic_read(&slots->lru_slot); + struct kvm_memory_slot *memslots = slots->memslots; + + if (gfn >= memslots[slot].base_gfn && + gfn < memslots[slot].base_gfn + memslots[slot].npages) + return slot; + + while (start < end) { + slot = start + (end - start) / 2; + + if (gfn >= memslots[slot].base_gfn) + end = slot; + else + start = slot + 1; + } + + if (gfn >= memslots[start].base_gfn && + gfn < memslots[start].base_gfn + memslots[start].npages) { + atomic_set(&slots->lru_slot, start); + } + + return start; +} + +/* * This function searches for the next page with dirty CMMA attributes, and * saves the attributes in the buffer up to either the end of the buffer or * until a block of at least KVM_S390_MAX_BIT_DISTANCE clean bits is found; diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h index 04a3e91..b86c1ad 100644 --- a/arch/s390/kvm/kvm-s390.h +++ b/arch/s390/kvm/kvm-s390.h @@ -183,6 +183,12 @@ static inline int kvm_s390_user_cpu_state_ctrl(struct kvm *kvm) return kvm->arch.user_cpu_state_ctrl != 0; } +static inline unsigned long *cmma_bitmap(struct kvm_memory_slot *slot) +{ + return slot->dirty_bitmap + + kvm_dirty_bitmap_bytes(slot) / sizeof(*slot->dirty_bitmap); +} + /* implemented in interrupt.c */ int kvm_s390_handle_wait(struct kvm_vcpu *vcpu); void kvm_s390_vcpu_wakeup(struct kvm_vcpu *vcpu); -- 2.7.4