From patchwork Mon Oct 9 08:51:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 149877 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1730501vqo; Mon, 9 Oct 2023 01:51:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFVXzk6zyxMIKaFURQUkAk09igWXG4H/otvdik2VJ1WfEp30M5+wd1/Q0Fb40oXvH5nxbMs X-Received: by 2002:a05:6358:528f:b0:143:96ac:96ec with SMTP id g15-20020a056358528f00b0014396ac96ecmr20460849rwa.25.1696841514953; Mon, 09 Oct 2023 01:51:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696841514; cv=none; d=google.com; s=arc-20160816; b=u8lfkYByx+KsV+2QrFXBLQNwnfP7xAvETJY7Gjv6wWv2ThhRTkTtUddHFJWoHr+gmw JYERzvL8s7327w0W/Jzrt40rkeGlbjQpoHBuVzOZykCy39Ksb8afcC3cPLCzXyzckFfP A4D3EWWYB6B1zJaYvON3vP72mJ2viDyJc3MsbOTCVwWzyDGj/bOdIgGUFrcTKO1PnJJY ESM/v6lVLut7e7MvyPfnA4voQDQZYJtC8AWhKsfSUljU0aCWtBfzcY475xcNArjviQis EpicrE9Xw0X4hw2/eUYNliZRM1S57hn1HQQNUu08x4uKXMhUIrJmo7GDX7aaYoElJRZd ADWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=IeXb3sIAz+dpC1N84f26s6Hanip96jjfN2NiQCsaNOg=; fh=ncJBVmsnOSqrX1O37yfYEzicwaA2e7ARxnsU7aiysyE=; b=tAReXrB/SoRYZFs2jhicej/7m7hOgcVsTQ+vfqk25MGQxAkeixqDPHA/GiN15Sq76j lm+BzN7VumBK481kgR5iOMLtmYlnZIacHMl/LWfH4DbGC4CDOEmbQVz+MZcVvn4P2HMK f4lJo9iS6WBRAY57qTI5G64JRac2y6nhI5WCJ/UQ/Ro6ZwejFL+wrvN8hLSOCT16f7la ZdVcgoi9UZX6K3kNVMnHLqOFwBRhtzslz8WtBaIqcsdRZYV+C3km4eQkt4mm8H2gCGoA D3p9R5aMY5Gxr0yVylURdDPpq0OBO7KfYSfpCwVGWyt4gHt9xyjoYXpWw6Zmgz72pdDV 1rXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=DrquFYH3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id o7-20020a63f147000000b00577dd005706si8975360pgk.779.2023.10.09.01.51.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 01:51:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=DrquFYH3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id A8B59802C7E0; Mon, 9 Oct 2023 01:51:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345655AbjJIIvn (ORCPT + 18 others); Mon, 9 Oct 2023 04:51:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345577AbjJIIvb (ORCPT ); Mon, 9 Oct 2023 04:51:31 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36E9ED8; Mon, 9 Oct 2023 01:51:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696841488; x=1728377488; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oW307Sz3JLhBJDdKvXdymtYFyyVye4wCg0yXRx4S4UE=; b=DrquFYH3kHqbyy/zHQxiY7t75YyhKn/89vJnDpro4QThddoKWYUHmd7a xyx3Sa2sjjJADFgXE+6gAcsTloCcRK9eJAp/mH7Qgx+ZIr4x+eWRc6MM9 YY3vC5+F/407ap6m57FvSZy5eB4rHORytK8r4dRpcsbwHPJqivK/KCBwM 3OgMIfEL5eHQS8jXwu1MXVYGvPh0Mm/xI0gHw+R+loId781qTcsmmUqTW W0oGXa+uAnh9GhZY9G1NMQR67NkbGauTosLM9E3Amk93+kOBhQF/f4+y8 h26OZex0JN7NssA2GiNNNoXsTNoHborUvqblhiTqP7TZVUNjBnHyhK5FM A==; X-IronPort-AV: E=McAfee;i="6600,9927,10857"; a="364390755" X-IronPort-AV: E=Sophos;i="6.03,209,1694761200"; d="scan'208";a="364390755" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2023 01:51:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10857"; a="818781645" X-IronPort-AV: E=Sophos;i="6.03,209,1694761200"; d="scan'208";a="818781645" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga008.fm.intel.com with ESMTP; 09 Oct 2023 01:51:27 -0700 From: Yi Liu To: joro@8bytes.org, alex.williamson@redhat.com, jgg@nvidia.com, kevin.tian@intel.com, robin.murphy@arm.com, baolu.lu@linux.intel.com Cc: cohuck@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, mjrosato@linux.ibm.com, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, yi.y.sun@linux.intel.com, peterx@redhat.com, jasowang@redhat.com, shameerali.kolothum.thodi@huawei.com, lulu@redhat.com, suravee.suthikulpanit@amd.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, zhenzhong.duan@intel.com, joao.m.martins@oracle.com Subject: [RFC 1/7] iommufd: Handle unsafe interrupts in a separate function Date: Mon, 9 Oct 2023 01:51:17 -0700 Message-Id: <20231009085123.463179-2-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231009085123.463179-1-yi.l.liu@intel.com> References: <20231009085123.463179-1-yi.l.liu@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 09 Oct 2023 01:51:53 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779267287994863392 X-GMAIL-MSGID: 1779267287994863392 From: Kevin Tian This wraps the unsafe interrupts handling into helper as same check is also required when supporting iommufd_device_bind_pasid() later. Signed-off-by: Kevin Tian Signed-off-by: Yi Liu --- drivers/iommu/iommufd/device.c | 36 ++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index 6a6145b4a25e..ca3919fecc89 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -145,6 +145,25 @@ void iommufd_device_destroy(struct iommufd_object *obj) iommufd_ctx_put(idev->ictx); } +/* + * For historical compat with VFIO the insecure interrupt path is + * allowed if the module parameter is set. Insecure means that a MemWr + * operation from the device (eg a simple DMA) cannot trigger an + * interrupt outside this iommufd context. + */ +static int iommufd_allow_unsafe_interrupts(struct device *dev) +{ + if (!allow_unsafe_interrupts) + return -EPERM; + + dev_warn( + dev, + "MSI interrupts are not secure, they cannot be isolated by the platform. " + "Check that platform features like interrupt remapping are enabled. " + "Use the \"allow_unsafe_interrupts\" module parameter to override\n"); + return 0; +} + /** * iommufd_device_bind - Bind a physical device to an iommu fd * @ictx: iommufd file descriptor @@ -179,24 +198,11 @@ struct iommufd_device *iommufd_device_bind(struct iommufd_ctx *ictx, if (IS_ERR(igroup)) return ERR_CAST(igroup); - /* - * For historical compat with VFIO the insecure interrupt path is - * allowed if the module parameter is set. Secure/Isolated means that a - * MemWr operation from the device (eg a simple DMA) cannot trigger an - * interrupt outside this iommufd context. - */ if (!iommufd_selftest_is_mock_dev(dev) && !iommu_group_has_isolated_msi(igroup->group)) { - if (!allow_unsafe_interrupts) { - rc = -EPERM; + rc = iommufd_allow_unsafe_interrupts(dev); + if (rc) goto out_group_put; - } - - dev_warn( - dev, - "MSI interrupts are not secure, they cannot be isolated by the platform. " - "Check that platform features like interrupt remapping are enabled. " - "Use the \"allow_unsafe_interrupts\" module parameter to override\n"); } rc = iommu_device_claim_dma_owner(dev, ictx);