From nobody Sun Feb 8 20:25:47 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1665040533; cv=none; d=zohomail.com; s=zohoarc; b=fUNc96uOdiE5JlFKiI2atEN5affrTXOhFM19b9xJWY6TzxJ9g1QF2DHfIMfj+tAKXaIhAu47v1PG435bVVxfBUpslBLD5q27mbDLPzoG3ZfOToBniSqxNTdxX0xpByN1q7PN4PmgynXEFGirVuvFKw1d3lkDme1B76UYLKkckKw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665040533; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=blGlAxVjw5/6eJY5lj12Ctgxq+MWh1jybNrPJW65ItI=; b=khUbToBlyuIXShtfyC2Vx+Nb1wfrW0eR5SBQogrYuVWmrwq9Tu3Qkd5txp2egzsbG8MjWkrrOVOZbP26rrX2eZd+amG2ZzMuG1bAaqNUSgaXxMaouhSfAgCZa3rlyMpCqJXPchkQGVDiweMaRKsZR4OwE4nSPJkUSSVLItR4b14= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1665040533334984.9823889753786; Thu, 6 Oct 2022 00:15:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.416626.661274 (Exim 4.92) (envelope-from ) id 1ogL67-0004I5-DM; Thu, 06 Oct 2022 07:15:11 +0000 Received: by outflank-mailman (output) from mailman id 416626.661274; Thu, 06 Oct 2022 07:15:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ogL67-0004Hy-AN; Thu, 06 Oct 2022 07:15:11 +0000 Received: by outflank-mailman (input) for mailman id 416626; Thu, 06 Oct 2022 07:15:09 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ogL65-00041m-N8 for xen-devel@lists.xenproject.org; Thu, 06 Oct 2022 07:15:09 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [2001:67c:2178:6::1d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 9c1a63a5-4546-11ed-964a-05401a9f4f97; Thu, 06 Oct 2022 09:15:09 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id A3F671F8B4; Thu, 6 Oct 2022 07:15:08 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 7644B1376E; Thu, 6 Oct 2022 07:15:08 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id rbaVG3yAPmM2EwAAMHmgww (envelope-from ); Thu, 06 Oct 2022 07:15:08 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 9c1a63a5-4546-11ed-964a-05401a9f4f97 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1665040508; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=blGlAxVjw5/6eJY5lj12Ctgxq+MWh1jybNrPJW65ItI=; b=hEHbAXRF22OPAX4YwHMgYgKd+iQAS3wV7mC+JrG0P8AVlfkPo0WePQjoqPsc5Nl7tiSieZ WxEBs9ooEwZN9U51qi3U3mm7BkCip8gDxHEeKdnfEEpPnI3MR8OhF9HS2HnYCz0uyTHvm4 Oh+J6mcwl3G1+irYY+RAILlGW50XPss= From: Juergen Gross To: linux-kernel@vger.kernel.org Cc: Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , xen-devel@lists.xenproject.org Subject: [PATCH 1/3] xen/virtio: restructure xen grant dma setup Date: Thu, 6 Oct 2022 09:14:58 +0200 Message-Id: <20221006071500.15689-2-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221006071500.15689-1-jgross@suse.com> References: <20221006071500.15689-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1665040533848100003 Content-Type: text/plain; charset="utf-8" In order to prepare supporting other means than device tree for setting up virtio devices under Xen, restructure the functions xen_is_grant_dma_device() and xen_grant_setup_dma_ops() a little bit. Signed-off-by: Juergen Gross Acked-by: Stefano Stabellini Reviewed-by: Oleksandr Tyshchenko Tested-by: Oleksandr Tyshchenko # Arm64=20 --- drivers/xen/grant-dma-ops.c | 68 +++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 25 deletions(-) diff --git a/drivers/xen/grant-dma-ops.c b/drivers/xen/grant-dma-ops.c index 8973fc1e9ccc..f29759d5301f 100644 --- a/drivers/xen/grant-dma-ops.c +++ b/drivers/xen/grant-dma-ops.c @@ -273,22 +273,28 @@ static const struct dma_map_ops xen_grant_dma_ops =3D= { .dma_supported =3D xen_grant_dma_supported, }; =20 -bool xen_is_grant_dma_device(struct device *dev) +static bool xen_is_dt_grant_dma_device(struct device *dev) { struct device_node *iommu_np; bool has_iommu; =20 - /* XXX Handle only DT devices for now */ - if (!dev->of_node) - return false; - iommu_np =3D of_parse_phandle(dev->of_node, "iommus", 0); - has_iommu =3D iommu_np && of_device_is_compatible(iommu_np, "xen,grant-dm= a"); + has_iommu =3D iommu_np && + of_device_is_compatible(iommu_np, "xen,grant-dma"); of_node_put(iommu_np); =20 return has_iommu; } =20 +bool xen_is_grant_dma_device(struct device *dev) +{ + /* XXX Handle only DT devices for now */ + if (dev->of_node) + return xen_is_dt_grant_dma_device(dev); + + return false; +} + bool xen_virtio_mem_acc(struct virtio_device *dev) { if (IS_ENABLED(CONFIG_XEN_VIRTIO_FORCE_GRANT)) @@ -297,45 +303,56 @@ bool xen_virtio_mem_acc(struct virtio_device *dev) return xen_is_grant_dma_device(dev->dev.parent); } =20 -void xen_grant_setup_dma_ops(struct device *dev) +static int xen_dt_grant_setup_dma_ops(struct device *dev, + struct xen_grant_dma_data *data) { - struct xen_grant_dma_data *data; struct of_phandle_args iommu_spec; =20 - data =3D find_xen_grant_dma_data(dev); - if (data) { - dev_err(dev, "Xen grant DMA data is already created\n"); - return; - } - - /* XXX ACPI device unsupported for now */ - if (!dev->of_node) - goto err; - if (of_parse_phandle_with_args(dev->of_node, "iommus", "#iommu-cells", 0, &iommu_spec)) { dev_err(dev, "Cannot parse iommus property\n"); - goto err; + return -ESRCH; } =20 if (!of_device_is_compatible(iommu_spec.np, "xen,grant-dma") || iommu_spec.args_count !=3D 1) { dev_err(dev, "Incompatible IOMMU node\n"); of_node_put(iommu_spec.np); - goto err; + return -ESRCH; } =20 of_node_put(iommu_spec.np); =20 + /* + * The endpoint ID here means the ID of the domain where the + * corresponding backend is running + */ + data->backend_domid =3D iommu_spec.args[0]; + + return 0; +} + +void xen_grant_setup_dma_ops(struct device *dev) +{ + struct xen_grant_dma_data *data; + + data =3D find_xen_grant_dma_data(dev); + if (data) { + dev_err(dev, "Xen grant DMA data is already created\n"); + return; + } + data =3D devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); if (!data) goto err; =20 - /* - * The endpoint ID here means the ID of the domain where the corresponding - * backend is running - */ - data->backend_domid =3D iommu_spec.args[0]; + if (dev->of_node) { + if (xen_dt_grant_setup_dma_ops(dev, data)) + goto err; + } else { + /* XXX ACPI device unsupported for now */ + goto err; + } =20 if (xa_err(xa_store(&xen_grant_dma_devices, (unsigned long)dev, data, GFP_KERNEL))) { @@ -348,6 +365,7 @@ void xen_grant_setup_dma_ops(struct device *dev) return; =20 err: + devm_kfree(dev, data); dev_err(dev, "Cannot set up Xen grant DMA ops, retain platform DMA ops\n"= ); } =20 --=20 2.35.3 From nobody Sun Feb 8 20:25:47 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1665040533; cv=none; d=zohomail.com; s=zohoarc; b=QfR4mjwnrck3+ZJgVUz8whrjw/C55pYWncYgXCmg3tusVKVLI4sdJpLgv53soNriAwpHo6NI0b3l58grMOCyGY7mtCy9g6J9h4DQuA53Uh8om/YQMUfmexvBcKF0GjiiBOpf1ZiK0ODuNmbB+edkMgyMRFHYshdPMA3kFqn35zc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665040533; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0CshijtaHr92stGSDZHMzCA/tn87geqWqdgj21TRuNc=; b=my07d1Rf4RkzS5xqE14FjeVT1lXDAl/snVgFTpILsKOk9Fko30piPAWmkCcynnUqQ7OOKa1GJQkk3ZeDzTRYnQg66ra6kx/5omcN85Qk7a7QAYUQglpcM+6LHi8WuEJErPDJf8oA/TQfPwqia4gxijTT73hFF8gV57aTH92jSNM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1665040533838976.4189989051181; Thu, 6 Oct 2022 00:15:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.416627.661284 (Exim 4.92) (envelope-from ) id 1ogL6C-0004bc-L3; Thu, 06 Oct 2022 07:15:16 +0000 Received: by outflank-mailman (output) from mailman id 416627.661284; Thu, 06 Oct 2022 07:15:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ogL6C-0004bN-IK; Thu, 06 Oct 2022 07:15:16 +0000 Received: by outflank-mailman (input) for mailman id 416627; Thu, 06 Oct 2022 07:15:15 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ogL6B-0004aP-QI for xen-devel@lists.xenproject.org; Thu, 06 Oct 2022 07:15:15 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 9f7e7a24-4546-11ed-9377-c1cf23e5d27e; Thu, 06 Oct 2022 09:15:14 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 547FD1F8C8; Thu, 6 Oct 2022 07:15:14 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 17F3B1376E; Thu, 6 Oct 2022 07:15:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 7+JTBIKAPmM+EwAAMHmgww (envelope-from ); Thu, 06 Oct 2022 07:15:14 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 9f7e7a24-4546-11ed-9377-c1cf23e5d27e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1665040514; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0CshijtaHr92stGSDZHMzCA/tn87geqWqdgj21TRuNc=; b=XcbUCD9o3PCb96W7Lx2pJ43DcJkjWoXykE9e7nTT/kS3m1zFb9YDxpuUVs2na45rQC+PCh sSh5iPuz1gLVgaZnLLoLdLvXZkXtz3YLIoZEYeZhhm6DGcwghEs1QYGawjNYkSah65JQsq EYuLVLQs3J+dFpZRCHv148T+yFFyXM4= From: Juergen Gross To: linux-kernel@vger.kernel.org Cc: Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , xen-devel@lists.xenproject.org Subject: [PATCH 2/3] xen/virtio: use dom0 as default backend for CONFIG_XEN_VIRTIO_FORCE_GRANT Date: Thu, 6 Oct 2022 09:14:59 +0200 Message-Id: <20221006071500.15689-3-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221006071500.15689-1-jgross@suse.com> References: <20221006071500.15689-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1665040535910100001 Content-Type: text/plain; charset="utf-8" With CONFIG_XEN_VIRTIO_FORCE_GRANT set the default backend domid to 0, enabling to use xen_grant_dma_ops for those devices. Signed-off-by: Juergen Gross Acked-by: Stefano Stabellini Reviewed-by: Oleksandr Tyshchenko --- drivers/xen/grant-dma-ops.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/xen/grant-dma-ops.c b/drivers/xen/grant-dma-ops.c index f29759d5301f..a00112235877 100644 --- a/drivers/xen/grant-dma-ops.c +++ b/drivers/xen/grant-dma-ops.c @@ -349,6 +349,9 @@ void xen_grant_setup_dma_ops(struct device *dev) if (dev->of_node) { if (xen_dt_grant_setup_dma_ops(dev, data)) goto err; + } else if (IS_ENABLED(CONFIG_XEN_VIRTIO_FORCE_GRANT)) { + dev_info(dev, "Using dom0 as backend\n"); + data->backend_domid =3D 0; } else { /* XXX ACPI device unsupported for now */ goto err; --=20 2.35.3 From nobody Sun Feb 8 20:25:47 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1665040539; cv=none; d=zohomail.com; s=zohoarc; b=X8tVq2FlCbti7D4zagKXkoF9AlWKB8DU6WC/zcJpNioNWEegOPpiWPRpR2LJMO1CZ+NoQrPLBtjr8SYZjO/V7b9cBPbqCN7dyq49hnXeYgw9HBFX/pv/UedSzmX4yhedR0r4ZPQDEvwlwEg25PHHwfp+ub87JxuXtTuxBFantA8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665040539; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7Ps9KwyB3HzeWHTtk+TkXmbcFpLo/S34tHtBoU7GquI=; b=n8ylPJZaAjsDbsvyGo2JCsNFr4Ca/JMm5NRfiXJwkp9IpaFRITvPANGrF8d32wSAWS3GicWY4DTsyri2JgXZ6lb2h6ynKhbjm8WzFRuri6wOcA5bbCnOW6dKYLShZJ6eGSCIrXRJ8zZIYBUy2u6gOUNne1dIPSSgapFsMOl6904= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 166504053914222.266513148891022; Thu, 6 Oct 2022 00:15:39 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.416628.661296 (Exim 4.92) (envelope-from ) id 1ogL6H-0004xO-TN; Thu, 06 Oct 2022 07:15:21 +0000 Received: by outflank-mailman (output) from mailman id 416628.661296; Thu, 06 Oct 2022 07:15:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ogL6H-0004xF-Q2; Thu, 06 Oct 2022 07:15:21 +0000 Received: by outflank-mailman (input) for mailman id 416628; Thu, 06 Oct 2022 07:15:21 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ogL6H-0004aP-4F for xen-devel@lists.xenproject.org; Thu, 06 Oct 2022 07:15:21 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id a2ef4024-4546-11ed-9377-c1cf23e5d27e; Thu, 06 Oct 2022 09:15:20 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 1BC02219B0; Thu, 6 Oct 2022 07:15:20 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id B51CE1376E; Thu, 6 Oct 2022 07:15:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id MqLUKoeAPmNJEwAAMHmgww (envelope-from ); Thu, 06 Oct 2022 07:15:19 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: a2ef4024-4546-11ed-9377-c1cf23e5d27e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1665040520; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7Ps9KwyB3HzeWHTtk+TkXmbcFpLo/S34tHtBoU7GquI=; b=mqv/aQ0xhf3jHn27YkkjHI6JbMnzF0R/hfiYz+yvCI+4IpL/79Wa0CyW8t1leaae0aWx3m uHS7KHzrKvYdOxsxpiBr+vlF4gxQSdJ2xILjF6blKUTRNxvsgaQNfGLfyfkbRvGFjuUMEd 4QKwMuqh9zjDVwgXZYgeQ0aTcivnjro= From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Juergen Gross , Boris Ostrovsky , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Stefano Stabellini , Oleksandr Tyshchenko , xen-devel@lists.xenproject.org Subject: [PATCH 3/3] xen/virtio: enable grant based virtio on x86 Date: Thu, 6 Oct 2022 09:15:00 +0200 Message-Id: <20221006071500.15689-4-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221006071500.15689-1-jgross@suse.com> References: <20221006071500.15689-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1665040539896100001 Content-Type: text/plain; charset="utf-8" Use an x86-specific virtio_check_mem_acc_cb() for Xen in order to setup the correct DMA ops. Signed-off-by: Juergen Gross --- arch/x86/xen/enlighten_hvm.c | 2 +- arch/x86/xen/enlighten_pv.c | 2 +- drivers/xen/grant-dma-ops.c | 10 ++++++++++ include/xen/xen-ops.h | 1 + 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/arch/x86/xen/enlighten_hvm.c b/arch/x86/xen/enlighten_hvm.c index 1c1ac418484b..c1cd28e915a3 100644 --- a/arch/x86/xen/enlighten_hvm.c +++ b/arch/x86/xen/enlighten_hvm.c @@ -212,7 +212,7 @@ static void __init xen_hvm_guest_init(void) return; =20 if (IS_ENABLED(CONFIG_XEN_VIRTIO_FORCE_GRANT)) - virtio_set_mem_acc_cb(virtio_require_restricted_mem_acc); + virtio_set_mem_acc_cb(xen_virtio_restricted_mem_acc); =20 init_hvm_pv_info(); =20 diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c index 9b1a58dda935..45b24c1b646a 100644 --- a/arch/x86/xen/enlighten_pv.c +++ b/arch/x86/xen/enlighten_pv.c @@ -112,7 +112,7 @@ static void __init xen_pv_init_platform(void) { /* PV guests can't operate virtio devices without grants. */ if (IS_ENABLED(CONFIG_XEN_VIRTIO)) - virtio_set_mem_acc_cb(virtio_require_restricted_mem_acc); + virtio_set_mem_acc_cb(xen_virtio_restricted_mem_acc); =20 populate_extra_pte(fix_to_virt(FIX_PARAVIRT_BOOTMAP)); =20 diff --git a/drivers/xen/grant-dma-ops.c b/drivers/xen/grant-dma-ops.c index a00112235877..60a7acc334ed 100644 --- a/drivers/xen/grant-dma-ops.c +++ b/drivers/xen/grant-dma-ops.c @@ -372,6 +372,16 @@ void xen_grant_setup_dma_ops(struct device *dev) dev_err(dev, "Cannot set up Xen grant DMA ops, retain platform DMA ops\n"= ); } =20 +bool xen_virtio_restricted_mem_acc(struct virtio_device *dev) +{ + bool ret =3D xen_virtio_mem_acc(dev); + + if (ret) + xen_grant_setup_dma_ops(dev->dev.parent); + + return ret; +} + MODULE_DESCRIPTION("Xen grant DMA-mapping layer"); MODULE_AUTHOR("Juergen Gross "); MODULE_LICENSE("GPL"); diff --git a/include/xen/xen-ops.h b/include/xen/xen-ops.h index dae0f350c678..3dd5aa936f1d 100644 --- a/include/xen/xen-ops.h +++ b/include/xen/xen-ops.h @@ -219,6 +219,7 @@ static inline void xen_preemptible_hcall_end(void) { } void xen_grant_setup_dma_ops(struct device *dev); bool xen_is_grant_dma_device(struct device *dev); bool xen_virtio_mem_acc(struct virtio_device *dev); +bool xen_virtio_restricted_mem_acc(struct virtio_device *dev); #else static inline void xen_grant_setup_dma_ops(struct device *dev) { --=20 2.35.3