Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2512223imm; Mon, 24 Sep 2018 05:43:25 -0700 (PDT) X-Google-Smtp-Source: ACcGV627wZh29GA57Y8NuBGNmw2pK5kpMKedlum39+qQKcsg6/ZJbYugfjD9qlL+DrruX+uBc4V0 X-Received: by 2002:a17:902:464:: with SMTP id 91-v6mr10689800ple.125.1537793005540; Mon, 24 Sep 2018 05:43:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537793005; cv=none; d=google.com; s=arc-20160816; b=J4w3lP16MiGrhYPU5Umgi45dECIyWYhEv3JBUyW/t4YrdH7YNrzs6X70BX7BMBPhoN UVVuDHSBAUmG5+bqzPRPPPQ5jtb3bIWQGoAyeS7PuiFk/KKxd5tScO3smrrEtQWjdQx5 atEaUAJxktZMvjN6rTzNM9rZ+Tcr9KNwB/lBjcf6ihpT7/cMHWsS2s4UajxFezBFCSBL Grb+vPSsQMUHXpiiIbWn/tyYXAGNQUW6T44qYSjgNvP95FYlM2g/iZ0LnRCwiOGhOZVw jOKHCjSswsY/iVgNCLqGb73x5Vm4oNGDQKAhbwhBPTPx9CgAEgkluL7b0dvimNPVZzsM 6HhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=KDcYBXK+QzuqnLK2GQUf4PEjajTwPa/mN4nUxDgIY4Y=; b=OGG4RmHDeLXofFWcsoJlKmq5+jyiR3bGw5ZEW1AVoXi5dXIuimN76bC+WxupeudFGh in/idtqoFFk0256QCxY8/isvwmkdz11Ij3RpJ3N4QaEaqd3IzuGuq9p/OR35/MTe8qsI aif5XzWKbEUDnSfzJeKRK9/h1BqTSnutvHAP26qwBQCHisVlJ5+3Fniu7+2FduG4PNv5 JZ/r3Wl3xxnfoEC3SV5wN2jgXIXv1X785tH7skAL2iNnq7NZh1ddqJTXeAnA3BmEz+iJ WR7NLdzo+OOeX5V3BSz9UqgqCUv6WYRSilycn+AoDO8J04huz8xrRr/u2Sxt2wxg8hnU VKYw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m24-v6si38144688pfk.56.2018.09.24.05.43.10; Mon, 24 Sep 2018 05:43:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388610AbeIXSma (ORCPT + 99 others); Mon, 24 Sep 2018 14:42:30 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:58988 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733259AbeIXSm3 (ORCPT ); Mon, 24 Sep 2018 14:42:29 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id F3714109A; Mon, 24 Sep 2018 12:40:30 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexey Kardashevskiy , David Gibson , Paul Mackerras , Sasha Levin Subject: [PATCH 4.18 159/235] KVM: PPC: Book3S: Fix matching of hardware and emulated TCE tables Date: Mon, 24 Sep 2018 13:52:25 +0200 Message-Id: <20180924113121.095540331@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180924113103.999624566@linuxfoundation.org> References: <20180924113103.999624566@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexey Kardashevskiy [ Upstream commit 76346cd93a5eca33700f82685d56172dd65d4c0a ] When attaching a hardware table to LIOBN in KVM, we match table parameters such as page size, table offset and table size. However the tables are created via very different paths - VFIO and KVM - and the VFIO path goes through the platform code which has minimum TCE page size requirement (which is 4K but since we allocate memory by pages and cannot avoid alignment anyway, we align to 64k pages for powernv_defconfig). So when we match the tables, one might be bigger that the other which means the hardware table cannot get attached to LIOBN and DMA mapping fails. This removes the table size alignment from the guest visible table. This does not affect the memory allocation which is still aligned - kvmppc_tce_pages() takes care of this. This relaxes the check we do when attaching tables to allow the hardware table be bigger than the guest visible table. Ideally we want the KVM table to cover the same space as the hardware table does but since the hardware table may use multiple levels, and all levels must use the same table size (IODA2 design), the area it can actually cover might get very different from the window size which the guest requested, even though the guest won't map it all. Fixes: ca1fc489cf "KVM: PPC: Book3S: Allow backing bigger guest IOMMU pages with smaller physical pages" Signed-off-by: Alexey Kardashevskiy Reviewed-by: David Gibson Signed-off-by: Paul Mackerras Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/kvm/book3s_64_vio.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) --- a/arch/powerpc/kvm/book3s_64_vio.c +++ b/arch/powerpc/kvm/book3s_64_vio.c @@ -180,7 +180,7 @@ extern long kvm_spapr_tce_attach_iommu_g if ((tbltmp->it_page_shift <= stt->page_shift) && (tbltmp->it_offset << tbltmp->it_page_shift == stt->offset << stt->page_shift) && - (tbltmp->it_size << tbltmp->it_page_shift == + (tbltmp->it_size << tbltmp->it_page_shift >= stt->size << stt->page_shift)) { /* * Reference the table to avoid races with @@ -296,7 +296,7 @@ long kvm_vm_ioctl_create_spapr_tce(struc { struct kvmppc_spapr_tce_table *stt = NULL; struct kvmppc_spapr_tce_table *siter; - unsigned long npages, size; + unsigned long npages, size = args->size; int ret = -ENOMEM; int i; @@ -304,7 +304,6 @@ long kvm_vm_ioctl_create_spapr_tce(struc (args->offset + args->size > (ULLONG_MAX >> args->page_shift))) return -EINVAL; - size = _ALIGN_UP(args->size, PAGE_SIZE >> 3); npages = kvmppc_tce_pages(size); ret = kvmppc_account_memlimit(kvmppc_stt_pages(npages), true); if (ret)