From nobody Mon Feb 9 14:38:08 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=1665124947; cv=none; d=zohomail.com; s=zohoarc; b=D2mj3+Xn9KghInkoIlY33UQYPj04Rylh07F901FvEDhmKxk5yYCRm7YCs1xdU4NiPh3joksAZWpUnyxXcpP12qk00Zp1s8V+UuQeLvmNIu0XeQwPuGq0DIeyKWiwu9C9CDXkBzQ0zYBoOFmiCrcE9m9bB2dlRaiW5KSaeN+zS6Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665124947; 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=S7rX4NNfG5xbGtkfHQ3yryrnm26fT7MI5fpGm+XeZVo=; b=IpNy7zBI435Qxw3rGvmaQahyG+SfZMiMsMVQzL90hp1Q34vnApqZuLldaaBoEAoy/kYuVfLgsBBc7RTSIiGFwNyEDYclvq0ciTkuxPilHvo2gcXX7teb73OiLT96+kszOG0C2yi7QLvCFFhV/8A/JwHNm0vX/gprtNZRkKkHrCk= 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 1665124947170617.8799642147134; Thu, 6 Oct 2022 23:42:27 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.417409.662132 (Exim 4.92) (envelope-from ) id 1ogh3d-0002JV-Gc; Fri, 07 Oct 2022 06:42:05 +0000 Received: by outflank-mailman (output) from mailman id 417409.662132; Fri, 07 Oct 2022 06:42:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ogh3d-0002JO-CO; Fri, 07 Oct 2022 06:42:05 +0000 Received: by outflank-mailman (input) for mailman id 417409; Fri, 07 Oct 2022 06:42:04 +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 1ogh3c-0001O7-8Q for xen-devel@lists.xenproject.org; Fri, 07 Oct 2022 06:42:04 +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 2729d57f-460b-11ed-9377-c1cf23e5d27e; Fri, 07 Oct 2022 08:42:03 +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 49B921F8A8; Fri, 7 Oct 2022 06:42:03 +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 BF47A13A3D; Fri, 7 Oct 2022 06:42:02 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id rb3eLDrKP2P+SQAAMHmgww (envelope-from ); Fri, 07 Oct 2022 06:42:02 +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: 2729d57f-460b-11ed-9377-c1cf23e5d27e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1665124923; 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=S7rX4NNfG5xbGtkfHQ3yryrnm26fT7MI5fpGm+XeZVo=; b=StxRIPs7AKtt4D0aOz64z0LpwokqK4ZWIDpbns1hmPaE3IuoSO6t7p30tXIYHDHYMDSIve eSdTcsGlR/qc2tGcmsUYg/Ya6wjb4gLkx9+rmMkxmAEKGMsR80426ZF+eyUYbCclA2gsKE b9KQmEMxe5EKcqEuSNSMSFbWYWlYwRg= 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 v2 3/3] xen/virtio: enable grant based virtio on x86 Date: Fri, 7 Oct 2022 08:41:43 +0200 Message-Id: <20221007064143.10049-4-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221007064143.10049-1-jgross@suse.com> References: <20221007064143.10049-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1665124949420100001 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 Reviewed-by: Boris Ostrovsky Reviewed-by: Oleksandr Tyshchenko #=20 --- V2: - add missing PV check in xen_virtio_mem_acc() (Oleksandr Tyshchenko) - add xen_virtio_restricted_mem_acc() stub (Oleksandr Tyshchenko) --- arch/x86/xen/enlighten_hvm.c | 2 +- arch/x86/xen/enlighten_pv.c | 2 +- drivers/xen/grant-dma-ops.c | 12 +++++++++++- include/xen/xen-ops.h | 6 ++++++ 4 files changed, 19 insertions(+), 3 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 c703b77b33c9..63c3f0dac066 100644 --- a/drivers/xen/grant-dma-ops.c +++ b/drivers/xen/grant-dma-ops.c @@ -297,7 +297,7 @@ bool xen_is_grant_dma_device(struct device *dev) =20 bool xen_virtio_mem_acc(struct virtio_device *dev) { - if (IS_ENABLED(CONFIG_XEN_VIRTIO_FORCE_GRANT)) + if (IS_ENABLED(CONFIG_XEN_VIRTIO_FORCE_GRANT) || xen_pv_domain()) return true; =20 return xen_is_grant_dma_device(dev->dev.parent); @@ -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..a34f4271a2e9 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) { @@ -234,6 +235,11 @@ static inline bool xen_virtio_mem_acc(struct virtio_de= vice *dev) { return false; } + +static inline bool xen_virtio_restricted_mem_acc(struct virtio_device *dev) +{ + return false; +} #endif /* CONFIG_XEN_GRANT_DMA_OPS */ =20 #endif /* INCLUDE_XEN_OPS_H */ --=20 2.35.3