Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp107308iof; Sun, 5 Jun 2022 22:36:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzliMm+FqwLyNtKxfem5o/M5RACGClZbQJQTf1MEWVrTd7xpRRnC6TvRtMA30Ntkz5pQO7o X-Received: by 2002:a17:90a:c981:b0:1e6:75f0:d4f1 with SMTP id w1-20020a17090ac98100b001e675f0d4f1mr25033719pjt.62.1654493776702; Sun, 05 Jun 2022 22:36:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654493776; cv=none; d=google.com; s=arc-20160816; b=v9APfhBKcF2BXZdBmbCYPSEPL5oLsfeDTzZ5BHv/3LDWjw9dyr8atx1JJGEqMune8v aXII80iiE8P+X0X3oCMYZwNxMa4hRZk8tGubNRhWXaaiUuvUkysAuRNPmYb/dnSq1Pld DY9Ks0SeIXs6LeVTriY1CP/QK1/ZvLt4fks1eO36cTje7jnl2OpqZkL462VMvQVzDqaO yBkkrqCTnsK5lqO5tv+JKywkrPVR3XiDUGhaHZDT/htLvOpA/n+RrpGF3uIrt9ELlBOU sV7AG8j7jvTNkh5z0jLXZg9wX0HnAVNh3FsPnU2kkfrp68KQBWEK0swYjZUpcHeoSnjW Geuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=vx2kLvIZS2juZNk5FVfsvDVXqGt8DgrAljecfWnEYWc=; b=ZsmzPofz73WdTH25TUQ4nOFBUvO/n4+wBVi47vVmtF0I4nr1qOyQtCnz0Oubevbg20 D/HgnJjGUBJ/N7Ni8ZpR32LwVomdM8YkOQAk4ViMpUwIyewrk+eEiEknEzSq5Il6QWfz epao0kkZsqaZcRTHay20hkDcsbwN7RXBDQRFIPtSZWmS4r+X+BxryuspwGqFPWgjwg+N aC7MQZv5/cVmabfn4mBCgI29+CboMKUXUgrOHjwm5kxo1ge7TAFWgPHl/xCas3kw11FG 1BfLc1kbT78v6AisltSjyRmLfRGmGbA2ikcZnMAD/hIBcB0kUNQaVSMoZcaUZNn8+5lz Ooew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dJJZFFwM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id z10-20020a170902ccca00b0016413da7b8bsi19960964ple.621.2022.06.05.22.36.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 22:36:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dJJZFFwM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8972D23F7EC; Sun, 5 Jun 2022 21:37:07 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238587AbiFBTYe (ORCPT + 99 others); Thu, 2 Jun 2022 15:24:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238539AbiFBTYX (ORCPT ); Thu, 2 Jun 2022 15:24:23 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54501CE4 for ; Thu, 2 Jun 2022 12:24:22 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id s12so4610515ejx.3 for ; Thu, 02 Jun 2022 12:24:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vx2kLvIZS2juZNk5FVfsvDVXqGt8DgrAljecfWnEYWc=; b=dJJZFFwM4qaW1Hz4dYQgCfKswqdA9aOKawg49H4QWfa1bpfs3bSdZPuAxn/Xlr/1S0 udjnMGecRU2bFne+nBMM8u5UDXRnNfywbI2TyTkY8otdiVk2aQjOq4BQmwbkJSJ3L7S1 jwaMwvMxLCxk8leL7XwK0V5JvtOeksJ0PrbA3kniJymeTZP0TBCUJHLEOGpfIh4ex5Zb znL91zrw0l+8zPhwEWoiplmzqptkYlU8bd4N/Kot4q9ALGcez+a6AsMGXTf/vNe2P9Ip nFE1N1MwvX1kJfSwjfnr1NTJJ7xhp9xOVpXwjExSAy9XIGsJdoe4MxqN5eEv9PvhmaB7 gKMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=vx2kLvIZS2juZNk5FVfsvDVXqGt8DgrAljecfWnEYWc=; b=ecR9rXNVIUTOP0MNLttWlvov2732s1O6DIAudf6xMwpfQb5q44stqNN8tOjIClxaAx 5qk9ngjYaPyjjtp5UC2TmwcLYG0UXbDzAVjcksh9CCs/y51pUxEy6UVP1e30mtKGIwnv qT4hx6g4OhTQGo9dxOeKl1YkBsLXbAOgco8aX7JT+ZFcasYHa44/K0w8aVtNyMh7s17V T7WiOrTm55MZT8iNoCLmyY6VSH9CiGxOXTrwp6iKjaeOO1CihI8cOXPeGdmO/Q919itj C2idPNf173x7D33SlG2TnHDSrfCohJEUoYmWkdKd2vE0fPm2c95RuOaVjsznw+ObH+MK HT+A== X-Gm-Message-State: AOAM532UDRKYIv1pWhgbAmxj4jnKmVhmxkW3sQGuk03vwUfEh9MIEw1l CTrGJzNP6ADvAPgTWkPjeWM= X-Received: by 2002:a17:907:1b24:b0:6ff:235c:2ffd with SMTP id mp36-20020a1709071b2400b006ff235c2ffdmr5887568ejc.116.1654197860794; Thu, 02 Jun 2022 12:24:20 -0700 (PDT) Received: from otyshchenko.router ([212.22.223.21]) by smtp.gmail.com with ESMTPSA id eg13-20020a056402288d00b0042dce73168csm2938301edb.13.2022.06.02.12.24.19 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Jun 2022 12:24:20 -0700 (PDT) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Juergen Gross , Oleksandr Tyshchenko , Stefano Stabellini , Russell King , Boris Ostrovsky , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Julien Grall , "Michael S. Tsirkin" , Christoph Hellwig Subject: [PATCH V4 4/8] xen/virtio: Enable restricted memory access using Xen grant mappings Date: Thu, 2 Jun 2022 22:23:49 +0300 Message-Id: <1654197833-25362-5-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1654197833-25362-1-git-send-email-olekstysh@gmail.com> References: <1654197833-25362-1-git-send-email-olekstysh@gmail.com> X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 From: Juergen Gross In order to support virtio in Xen guests add a config option XEN_VIRTIO enabling the user to specify whether in all Xen guests virtio should be able to access memory via Xen grant mappings only on the host side. Also set PLATFORM_VIRTIO_RESTRICTED_MEM_ACCESS feature from the guest initialization code on Arm and x86 if CONFIG_XEN_VIRTIO is enabled. Signed-off-by: Juergen Gross Signed-off-by: Oleksandr Tyshchenko Reviewed-by: Stefano Stabellini Reviewed-by: Boris Ostrovsky --- Changes V1 -> V2: - new patch, split required changes from commit: "[PATCH V1 3/6] xen/virtio: Add option to restrict memory access under Xen" - rework according to new platform_has() infrastructure Changes V2 -> V3: - add Stefano's R-b Changes V3 -> V4: - add Boris' R-b --- arch/arm/xen/enlighten.c | 2 ++ arch/x86/xen/enlighten_hvm.c | 2 ++ arch/x86/xen/enlighten_pv.c | 2 ++ drivers/xen/Kconfig | 11 +++++++++++ include/xen/xen.h | 8 ++++++++ 5 files changed, 25 insertions(+) diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c index 07eb69f..1f9c3ba 100644 --- a/arch/arm/xen/enlighten.c +++ b/arch/arm/xen/enlighten.c @@ -443,6 +443,8 @@ static int __init xen_guest_init(void) if (!xen_domain()) return 0; + xen_set_restricted_virtio_memory_access(); + if (!acpi_disabled) xen_acpi_guest_init(); else diff --git a/arch/x86/xen/enlighten_hvm.c b/arch/x86/xen/enlighten_hvm.c index 517a9d8..8b71b1d 100644 --- a/arch/x86/xen/enlighten_hvm.c +++ b/arch/x86/xen/enlighten_hvm.c @@ -195,6 +195,8 @@ static void __init xen_hvm_guest_init(void) if (xen_pv_domain()) return; + xen_set_restricted_virtio_memory_access(); + init_hvm_pv_info(); reserve_shared_info(); diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c index ca85d14..30d24fe 100644 --- a/arch/x86/xen/enlighten_pv.c +++ b/arch/x86/xen/enlighten_pv.c @@ -108,6 +108,8 @@ static DEFINE_PER_CPU(struct tls_descs, shadow_tls_desc); static void __init xen_pv_init_platform(void) { + xen_set_restricted_virtio_memory_access(); + populate_extra_pte(fix_to_virt(FIX_PARAVIRT_BOOTMAP)); set_fixmap(FIX_PARAVIRT_BOOTMAP, xen_start_info->shared_info); diff --git a/drivers/xen/Kconfig b/drivers/xen/Kconfig index 313a9127..a7bd8ce 100644 --- a/drivers/xen/Kconfig +++ b/drivers/xen/Kconfig @@ -339,4 +339,15 @@ config XEN_GRANT_DMA_OPS bool select DMA_OPS +config XEN_VIRTIO + bool "Xen virtio support" + depends on VIRTIO + select XEN_GRANT_DMA_OPS + help + Enable virtio support for running as Xen guest. Depending on the + guest type this will require special support on the backend side + (qemu or kernel, depending on the virtio device types used). + + If in doubt, say n. + endmenu diff --git a/include/xen/xen.h b/include/xen/xen.h index a99bab8..0780a81 100644 --- a/include/xen/xen.h +++ b/include/xen/xen.h @@ -52,6 +52,14 @@ bool xen_biovec_phys_mergeable(const struct bio_vec *vec1, extern u64 xen_saved_max_mem_size; #endif +#include + +static inline void xen_set_restricted_virtio_memory_access(void) +{ + if (IS_ENABLED(CONFIG_XEN_VIRTIO) && xen_domain()) + platform_set(PLATFORM_VIRTIO_RESTRICTED_MEM_ACCESS); +} + #ifdef CONFIG_XEN_UNPOPULATED_ALLOC int xen_alloc_unpopulated_pages(unsigned int nr_pages, struct page **pages); void xen_free_unpopulated_pages(unsigned int nr_pages, struct page **pages); -- 2.7.4