From patchwork Tue Nov 29 12:09:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balbir Singh X-Patchwork-Id: 700484 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3tSj6s1GVpz9vDl for ; Tue, 29 Nov 2016 23:10:29 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="qleCSGVu"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932265AbcK2MKL (ORCPT ); Tue, 29 Nov 2016 07:10:11 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:34787 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757093AbcK2MKJ (ORCPT ); Tue, 29 Nov 2016 07:10:09 -0500 Received: by mail-pf0-f194.google.com with SMTP id y68so8275227pfb.1; Tue, 29 Nov 2016 04:10:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=to:subject:cc:from:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=6eNDzyOPpQN1/l9tNPdM4PDsgXRqcQ4zjCxsuADGWGU=; b=qleCSGVukI7vvBhY+5QzPsf8zjS4e1pvY6YhEv02SQN6FLra/GWPrN0SWoXdcLcEaT whMmEAKIkiUgGg19R1I9KyftS1n9IBRuqUTJdLmxHpX4ndeI3KxqEkIMBvfUr0+RN3CI ybHQjJ+s0SZd9hIeUMXOwjl41SWDANalm/d2IGrGR7oX+oCGhffiEJZ4UJyL36luu/nD WgmOkauRne7+Tff7k23g1x99phpyraK1jfRQaL4KIfIYrZyDaiH/XRYGSkoN13RGQ2eu NyhW6lYr8ziSvEJx8micnLpQVnw545I4GtNxA8cENlzMv9CFNCEE/chM2t+F4ixeL9wq 6c1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:subject:cc:from:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=6eNDzyOPpQN1/l9tNPdM4PDsgXRqcQ4zjCxsuADGWGU=; b=hmlobEZ53vyksXhA4baNpgjwlLADdqnc8BeKILnuEps0XEjQRCCoCS6G1Y+YQql88e 5pWZFzSAHb/jGmIHEF9PJYf9oH/JpuETfnUy6uRaY/Zhpq0hQ8pfUW3nF7FoxRhF2n88 K/qr2jINfckDvD8bEorUi6gXbVlNGUKqCTvRZcUERwLo83d0pks9FrNajkrUTfO0ewm1 2NNE+FQs/9JsfuZhFEJniMWLT9VVELuN24aemAJIWMGYkRLXKGJ+VK4spzNIhIpSNCpb 0YfbFDcZmpVFbO2BMWmUbjlXIqxNdy8GQx/r7axxaXRk+iNwXKtc9IuQtvSRI6r2vkni KgLw== X-Gm-Message-State: AKaTC01Z1jrKZCB+js3RRiLFjQi07uraanX7b1POMePlri3a0gAIeG1tLyGbKy91k/doAw== X-Received: by 10.84.209.143 with SMTP id y15mr61154521plh.173.1480421407142; Tue, 29 Nov 2016 04:10:07 -0800 (PST) Received: from balbir.ozlabs.ibm.com (14-202-194-140.static.tpgi.com.au. [14.202.194.140]) by smtp.gmail.com with ESMTPSA id 65sm94762383pfn.12.2016.11.29.04.10.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Nov 2016 04:10:06 -0800 (PST) To: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org Subject: [PATCH] KVM/PPC Patch for KVM issue in real mode Cc: Paul Mackerras , Paolo Bonzini , Radim K From: Balbir Singh Message-ID: <6f8db92b-4391-c475-6335-7192b821dddb@gmail.com> Date: Tue, 29 Nov 2016 23:09:57 +1100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.0 MIME-Version: 1.0 Sender: kvm-ppc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm-ppc@vger.kernel.org Some KVM functions for book3s_hv are called in real mode. In real mode the top 4 bits of the address space are ignored, hence an address beginning with 0xc0000000+offset is the same as 0xd0000000+offset. The issue was observed when a kvm memslot resolution lead to random values when accessed from kvmppc_h_enter(). The issue is hit if the KVM host is running with a page size of 4K, since kvzalloc() looks at size < PAGE_SIZE. On systems with 64K the issue is not observed easily, it largely depends on the size of the structure being allocated. The proposed fix moves all KVM allocations for book3s_hv to kzalloc() until all structures used in real mode are audited. For safety allocations are moved to kmalloc space. The impact is a large allocation on systems with 4K page size. Signed-off-by: Balbir Singh --- arch/powerpc/include/asm/kvm_host.h | 18 ++++++++++++++++++ include/linux/kvm_host.h | 11 +++++++++++ virt/kvm/kvm_main.c | 2 +- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h index f15713a..efcdc1d 100644 --- a/arch/powerpc/include/asm/kvm_host.h +++ b/arch/powerpc/include/asm/kvm_host.h @@ -733,6 +733,24 @@ struct kvm_vcpu_arch { #define __KVM_HAVE_ARCH_WQP #define __KVM_HAVE_CREATE_DEVICE +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE +#define __KVM_HAVE_ARCH_VZALLOC_OVERRIDE +#endif + +/* + * KVM uses some of these data structures -- the ones + * from kvzalloc() in real mode. If the data structure + * happens to come from a vmalloc'd range then its access + * in real mode will lead to problems due to the aliasing + * issue - (top 4 bits are ignore). + * A 0xd000+offset will point to a 0xc000+offset in realmode + * Hence we want our data structures from come from kmalloc'd + * regions, so that we don't have these aliasing issues + */ +static inline void *kvm_arch_vzalloc(unsigned long size) +{ + return kzalloc(size, GFP_KERNEL); +} static inline void kvm_arch_hardware_disable(void) {} static inline void kvm_arch_hardware_unsetup(void) {} diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 01c0b9c..0c88af5 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -793,6 +794,16 @@ static inline bool kvm_arch_has_noncoherent_dma(struct kvm *kvm) return false; } #endif + +#ifdef __KVM_HAVE_ARCH_VZALLOC_OVERRIDE +static void *kvm_arch_vzalloc(unsigned long size); +#else +static inline void *kvm_arch_vzalloc(unsigned long size) +{ + return vzalloc(size); +} +#endif + #ifdef __KVM_HAVE_ARCH_ASSIGNED_DEVICE void kvm_arch_start_assignment(struct kvm *kvm); void kvm_arch_end_assignment(struct kvm *kvm); diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index fbf04c0..57e3dca 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -689,7 +689,7 @@ static struct kvm *kvm_create_vm(unsigned long type) void *kvm_kvzalloc(unsigned long size) { if (size > PAGE_SIZE) - return vzalloc(size); + return kvm_arch_vzalloc(size); else return kzalloc(size, GFP_KERNEL); }