Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp579086rwb; Thu, 6 Oct 2022 01:12:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7Fm4zFSgpgiFU2TjXw7bz3yMkhtBB+QzZwoycUpkJmgGpqmaeAE8rYWvj4gxKeVn3dil/x X-Received: by 2002:a17:902:b70a:b0:179:f94b:568d with SMTP id d10-20020a170902b70a00b00179f94b568dmr3470611pls.173.1665043955996; Thu, 06 Oct 2022 01:12:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665043955; cv=none; d=google.com; s=arc-20160816; b=0wZEiA6iLIDDjsXceiTldj4Nf//GTBu4IDjLQ1aQV9vrVJiTZoNXHskkakDzV6bkJr jcyMwEp/B6XR7KvZdN61PIUEc4jlJqE+/d6VLecGCJkH9EK+bBbQh2dZt22IjrRhPRTL D54jZj3P5QQFXExQQQe4r2oBHpZndSyvtOcNWc9lZpdODujbu06NI5yIuHVnHk8Wgngs yQPzFiwvO2+7eJcvYxCMMVikEWVlgXHbExRm5FwN4bTTL8ehh724eUcS8xf2qtOJ5Cp2 j38ly6CrYS4CRyismAKxhcOq0zyoZrVqZjJF07MjoRF69Q/R5lVn0PxruwXZ3lbEv+OL DA4A== 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=7Ps9KwyB3HzeWHTtk+TkXmbcFpLo/S34tHtBoU7GquI=; b=ghWCLVERCPofu+HHNpKpiLsocvNuLAL+ER+rXJhJf8OGtaBBV6N5qqveL7E3O3A/rV MZ6N/isecXy76mkauMMsyHy30pIOPii8muKjn/Eqi4vFkGqboHX/bPmBqyWGmBiKK1rQ 2IzfOmvbdU4/IoBC106g5SK6/Bew8G8ziNe2StoR2nqEOcjspmlpAX5RSeMRQ7LEG/Or NB2U/b6UZmdSWSACXqWyw0ee18dR5JSkM/c+zfXOUkfU/OAS/u/gDHapCAO5FMn8wDlo HO/7c2Yha8CmmtPCfEuK6jtSyQBpcc9Rkic5CJktO30pNlX2xETVX4EkA4K+p1X14p7g wLvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b="mqv/aQ0x"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g7-20020a63e607000000b004403a3d2987si18537682pgh.106.2022.10.06.01.12.24; Thu, 06 Oct 2022 01:12:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b="mqv/aQ0x"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230225AbiJFHP2 (ORCPT + 99 others); Thu, 6 Oct 2022 03:15:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230224AbiJFHPY (ORCPT ); Thu, 6 Oct 2022 03:15:24 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEF5C3DF34 for ; Thu, 6 Oct 2022 00:15:21 -0700 (PDT) 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) 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= 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 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: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS 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 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; 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); init_hvm_pv_info(); 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); populate_extra_pte(fix_to_virt(FIX_PARAVIRT_BOOTMAP)); 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"); } +bool xen_virtio_restricted_mem_acc(struct virtio_device *dev) +{ + bool ret = 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) { -- 2.35.3