Received: by 10.223.185.116 with SMTP id b49csp1101929wrg; Sat, 3 Mar 2018 15:36:34 -0800 (PST) X-Google-Smtp-Source: AG47ELuQMV7P62cb1Q/sXzhNT2mgXDSuerCVM1z1BRvPAaj3WvTaS9hORme5GnkDrvR//TZYlBbS X-Received: by 10.99.116.69 with SMTP id e5mr8532294pgn.437.1520120194677; Sat, 03 Mar 2018 15:36:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520120194; cv=none; d=google.com; s=arc-20160816; b=Z4MiVOM0BKX2ETwfRiof6DEzRyV8ulZqz/LSrFdHw+RJ9Ow6o8u0ruYwp9GCocF9b6 hWgM3JVaEu4iY0R/6ZRXcxcMNz4Clb3UH22ino8vH3IBZKvUZNZ7X+IKjNGCZkNBtrEM 4pT//reB5OAAridHEZ5196mt6gDp4xSaeRlT6QN3ezzU8n5yoN80DY0FHf8L9h5+3Z19 23c4sM2lZYbv0M/zvz1PvSn4pX9807nUhRd6qT1FA8+LTJuSOphKDcDgyyv0tD0DzIZR LqedCfT59s/Z0sNyn6frupYSWaotI8zSqJ89QgiXv0yFbbioRlLLCog5L/LUYSYbBjhp Endg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=X2rtFQ9bloVJ/2ON48XpZaWGtZwZXAsKIayDa9QB0cA=; b=wKl8gvp3WScf5oK4dk6lL3f/sPbYoQQYIm2JAli7gqPkQpP+Rtavbz7bNHl5LF7qlb g28iFMNH4oU92DG1DjQ7vS6/tFwdVjMYs/4tt7owcbFJ9QTpMJIgw9E8gOjlQcHF5Ooz iMUOo0ucU3DGVq0P2aY4BxEjE3N5tc1gP9k3lyQo85D0SFTI3PTOxDTDvBto/rrQwWLv 4wHjBWFO+v2wcw/WFM7WbjyV7u4weItivbeFI2Xyztvkr4xppC0Jzvj3nXdpbHsajt4z syumDTowfV60Oa52LWCccQ+9clnb0Z85kUIqZd+X0LgrNJpdiNSZGC9YfBvmRXw7wx9i QcEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=UlAjsP52; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k64si4006984pgk.256.2018.03.03.15.36.20; Sat, 03 Mar 2018 15:36:34 -0800 (PST) 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; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=UlAjsP52; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934442AbeCCWfv (ORCPT + 99 others); Sat, 3 Mar 2018 17:35:51 -0500 Received: from mail-bn3nam01on0090.outbound.protection.outlook.com ([104.47.33.90]:43384 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933950AbeCCWfo (ORCPT ); Sat, 3 Mar 2018 17:35:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=X2rtFQ9bloVJ/2ON48XpZaWGtZwZXAsKIayDa9QB0cA=; b=UlAjsP52IwDJ2X8cU86+aFobxfbtTxJyUrW+pLKiVGR6qxGPp7HOUxxAja1TlmM7tZH9nDBZUW5XbiGvl9tbuPh8tDYh6lV/PLvDc5qnJRWRr2iWi1CIj8cA5IBY81RKXZGDxqumWcXIdT6aibZWR2fNIU3ldeyjaZ8mGnHfNNQ= Received: from MW2PR2101MB1034.namprd21.prod.outlook.com (52.132.149.10) by MW2PR2101MB1034.namprd21.prod.outlook.com (52.132.149.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.567.3; Sat, 3 Mar 2018 22:35:41 +0000 Received: from MW2PR2101MB1034.namprd21.prod.outlook.com ([fe80::1d56:338f:e2b:cec0]) by MW2PR2101MB1034.namprd21.prod.outlook.com ([fe80::1d56:338f:e2b:cec0%3]) with mapi id 15.20.0567.006; Sat, 3 Mar 2018 22:35:41 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Alexey Kardashevskiy , Alex Williamson , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 154/219] vfio/powerpc/spapr_tce: Enforce IOMMU type compatibility check Thread-Topic: [PATCH AUTOSEL for 4.9 154/219] vfio/powerpc/spapr_tce: Enforce IOMMU type compatibility check Thread-Index: AQHTsz8WEWVh4EeVrEarG005DCGQOQ== Date: Sat, 3 Mar 2018 22:29:26 +0000 Message-ID: <20180303222716.26640-154-alexander.levin@microsoft.com> References: <20180303222716.26640-1-alexander.levin@microsoft.com> In-Reply-To: <20180303222716.26640-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;MW2PR2101MB1034;6:Pt7UP0cc7PfParJ8y64sQKLC/3Twvgu6WUQXzYtTS6ZiOiPnDTwLhXzr2eoeQ/AePg8fzOt9htDrO9YZ+RTaaljBHH1jxYDFhPFrq6rZoF6qqRqXQbmgvspMMIfs5LD6ZnQhz2RViEyRZppHaWSxmMJ7HNk9ZtsPWz9xQc37N4u3F3UbosYZ84qpQVHgXUCCvUi507ziJLnTnBXhNecbqBRC8sQS8x2jzs1m+UeYIY3rjt+n2mwuBwqc73AW7k3lhwPCtWOEUL3JKd19m31Dwx5vgUOtLHy1jIU8gfswsQGpwchrXyadQOrH9zwBR4nlYSbulj9++B0DuxIXR8uEN/v/h2GmpwWanV9M9ETv+RQRWoWOO9HqfdeAxfuP7MyC;5:QE1K0pJD1E2YITonLb8aal1ZkwVfCoSuqN7GWKSCYiR8s68AF+2S8lFkHvC9aPGsjmU6cnZ/W0V4K2eM6C001hn9q63qgiKg+QMvryfC+5Skoyt7r9sr2HB41ycIRbTHGQdlpFNLmpo+CLJ9ec0wxNPG9iDb6p9rRo+8m68OOVI=;24:KmMmINZ6zdziKKMvDaBhftTLC8/6++TnnXC7z/ag73h5b4Q/zjrGPteUnv/d972G7u3q81PpahpGmIWg921VcnWHchQQLQaH1QZdUxV6YhI=;7:I6DpmaEKuFlQcyBxhlUEFZ0C0JGE55+m/1SagETDxokwz0WnYJKbrAY9T7jqkS3gFwcAUd2MkXfLmsRsHzbFJFWo2uhLpuoCznEq/Gppxa0z733RsrlXdAbEBtVWWv1i2zqgoU5W45Me5qpQxVaRbowJOkEnmlLoza6QwkDDKr/FvI1Y5RmdK/09bXayRTvm8R6aitFvNoc30fOQFMuUyVm85PbGdRfEArTLSUyYdgXrReh3Qx0vZxPuumLe+yf6 x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: d4582aae-86da-4867-d0e5-08d581571848 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(5600026)(4604075)(3008032)(2017052603307)(7193020);SRVR:MW2PR2101MB1034; x-ms-traffictypediagnostic: MW2PR2101MB1034: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040501)(2401047)(5005006)(8121501046)(3231220)(944501244)(52105095)(93006095)(93001095)(10201501046)(3002001)(6055026)(61426038)(61427038)(6041288)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123558120)(20161123560045)(6072148)(201708071742011);SRVR:MW2PR2101MB1034;BCL:0;PCL:0;RULEID:;SRVR:MW2PR2101MB1034; x-forefront-prvs: 0600F93FE1 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(376002)(346002)(39860400002)(39380400002)(366004)(396003)(199004)(189003)(99286004)(22452003)(72206003)(316002)(3846002)(6116002)(186003)(26005)(478600001)(76176011)(54906003)(110136005)(102836004)(97736004)(1076002)(2501003)(3660700001)(66066001)(5250100002)(5660300001)(86362001)(10090500001)(10290500003)(86612001)(6506007)(68736007)(575784001)(5890100001)(106356001)(25786009)(8676002)(4326008)(59450400001)(6512007)(305945005)(2906002)(14454004)(107886003)(8936002)(7736002)(81166006)(3280700002)(53936002)(105586002)(81156014)(6666003)(6486002)(36756003)(4477795004)(2900100001)(6436002)(2950100002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:MW2PR2101MB1034;H:MW2PR2101MB1034.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: IaleUCXiJbn4Z3asv1Ih4hJbIq9Y31i4HYXdmYGVFBQCVj7xzhnLk0/0xHJORJWdffmmMEV9l9b0yCGAA5aVdWYQRm6o7MdVqGvvi/TgYvkjOFZZoqcmdFMVa6DlnTWsVigZ1sOLte4rp6O0dWvbFxH2Rat+Z24eQEozv0o1bOk= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: d4582aae-86da-4867-d0e5-08d581571848 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Mar 2018 22:29:26.2913 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR2101MB1034 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/vfio/vfio_iommu_spapr_tce.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/vfio/vfio_iommu_spapr_tce.c b/drivers/vfio/vfio_iommu_= spapr_tce.c index 59b3f62a2d64..87ad0d72d8a9 100644 --- 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 *iommu_data, =20 if (!table_group->ops || !table_group->ops->take_ownership || !table_group->ops->release_ownership) { + if (container->v2) { + ret =3D -EPERM; + goto unlock_exit; + } ret =3D tce_iommu_take_ownership(container, table_group); } else { + if (!container->v2) { + ret =3D -EPERM; + goto unlock_exit; + } ret =3D tce_iommu_take_ownership_ddw(container, table_group); if (!tce_groups_attached(container) && !container->tables[0]) container->def_window_pending =3D true; --=20 2.14.1