Received: by 10.213.65.68 with SMTP id h4csp37625imn; Mon, 19 Mar 2018 18:46:14 -0700 (PDT) X-Google-Smtp-Source: AG47ELuRkIoDL97I2YMAGhUCHLM16PGnMF0hHJBg9xSbM+jH/2xkhForzh82LWu8SomK+T05TX8L X-Received: by 2002:a17:902:4003:: with SMTP id b3-v6mr9586093pld.15.1521510374360; Mon, 19 Mar 2018 18:46:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521510374; cv=none; d=google.com; s=arc-20160816; b=F+W2kAuFqZcp5ugnmR/CkqJYxY++oKcK4Q1hLK1C0I6/dra/sWGpP/YtrV14B53sSI dfjjqFeWxY+s40aifUrllBifjIyetlt59TfJtLW/SdsgTHygkHvQjZRGq5yIQNdUA4/5 fCt96NfJniEarmz8OAa2Qd+zLCPBzX+m6xodCIAjAbh3nHbeL9YF8eGXvRVnjGKrr1My Svffi0FXH3ViAkkhnKziXuNSM7oSz8NWR2CtOnHPFA9fzztnZcM3FRYLo+m7IC85SG9e rpLGnWCIr9+SfY24YKTi7XQ647GT4UdMO0E8XJ/qIOZuArD/wFI0u8gfzwuN/VaTeGgZ tVDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=D4Z2YFpxYtjjbl9u94v+o1XwmsqNloPr77NKCcVoFE0=; b=HUrWqeDr7jZA9uV19rkuXOHGo0eEwPDjRSP1j70t9eL6UimiOSgIky7DhNwXhEGHMO Ku9SPjx7JKgTD7FE/0LvAoMUU7BgrYcAE/gPUj4BTL9eDkvqXvbbo+TBR0o+gyVzsGJK Yq5abWvbyHgxqK5esvls42TVJ1Lp3xuLINbAe68EnWbvZjHEbj4f2gvJQQAsfNo6p+xI XjKWIIL9q1x41ivEXgW0bYn/3LFNB110kyzbXA93p3o3Dd05lJWYz9wfrMFH1GZFy/PI Fb9Rr9lHqioJpw0nBHkS+0+eFProafUw9VjvXa35Fdk3W5EFeZKRSa+36dZFiMN3YZWp Mp+w== 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 p29si410055pgn.123.2018.03.19.18.46.00; Mon, 19 Mar 2018 18:46:14 -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 S935851AbeCSTSD (ORCPT + 99 others); Mon, 19 Mar 2018 15:18:03 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:50684 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966182AbeCSS0G (ORCPT ); Mon, 19 Mar 2018 14:26:06 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 738EC10F3; Mon, 19 Mar 2018 18:26:05 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexey Kardashevskiy , Alex Williamson , Sasha Levin Subject: [PATCH 4.9 147/241] vfio/powerpc/spapr_tce: Enforce IOMMU type compatibility check Date: Mon, 19 Mar 2018 19:06:52 +0100 Message-Id: <20180319180757.272609289@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319180751.172155436@linuxfoundation.org> References: <20180319180751.172155436@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexey Kardashevskiy [ Upstream commit 1282ba7fc28dbc66c3f0e4aaafaaa228361d1ae5 ] The existing SPAPR TCE driver advertises both VFIO_SPAPR_TCE_IOMMU and VFIO_SPAPR_TCE_v2_IOMMU types to the userspace and the userspace usually picks the v2. Normally the userspace would create a container, attach an IOMMU group to it and only then set the IOMMU type (which would normally be v2). However a specific IOMMU group may not support v2, in other words it may not implement set_window/unset_window/take_ownership/ release_ownership and such a group should not be attached to a v2 container. This adds extra checks that a new group can do what the selected IOMMU type suggests. The userspace can then test the return value from ioctl(VFIO_SET_IOMMU, VFIO_SPAPR_TCE_v2_IOMMU) and try VFIO_SPAPR_TCE_IOMMU. Signed-off-by: Alexey Kardashevskiy Signed-off-by: Alex Williamson Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/vfio/vfio_iommu_spapr_tce.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/drivers/vfio/vfio_iommu_spapr_tce.c +++ b/drivers/vfio/vfio_iommu_spapr_tce.c @@ -1332,8 +1332,16 @@ static int tce_iommu_attach_group(void * if (!table_group->ops || !table_group->ops->take_ownership || !table_group->ops->release_ownership) { + if (container->v2) { + ret = -EPERM; + goto unlock_exit; + } ret = tce_iommu_take_ownership(container, table_group); } else { + if (!container->v2) { + ret = -EPERM; + goto unlock_exit; + } ret = tce_iommu_take_ownership_ddw(container, table_group); if (!tce_groups_attached(container) && !container->tables[0]) container->def_window_pending = true;