Received: by 2002:a19:771d:0:0:0:0:0 with SMTP id s29csp1264834lfc; Wed, 1 Jun 2022 13:32:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzyDpGxs5gJ7H2DQNPm6yn5GogacuvajieGZdjdXV3ixzJxhfGx+sRCLDAyycia0894xSmG X-Received: by 2002:a17:902:b58c:b0:163:920c:6164 with SMTP id a12-20020a170902b58c00b00163920c6164mr1268914pls.58.1654115536060; Wed, 01 Jun 2022 13:32:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654115536; cv=none; d=google.com; s=arc-20160816; b=feO+U5Qgt/WGrIV1GwDb7/kPON3ySzEzFxHh2Sn2L/i/QvJWk7YFAIY1WMgazw+iFL eKBRdQ1OiAlepeJfVUDi+3voDAl7urP8hBcOG0V45Hs7+NWORhRUuBN7F5jHmYn7FeL7 OVGbbYYMRMv/LWFzACo9SgvZ01GYRqPUICCq15d9e9ZqPM8HDuULDIU/nQqx1hLYM5Xd 1sUGC1N/ZdGmIKU/6J3s4qOJS98Vkj6dwILLAMoMzb4blHxCBVTch7uae1bl7JxH6KoC Uj+8PPevuEnALB36uUJgq1aez7zEWJxQxDwxEjqzdzfrol+0Ns3ldIf9OF9+92K9O765 xFwQ== 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=lW0Pzr6bA3fYtV1xJl8AeDQlMEnR60yW2//eH29vCxE=; b=GbkJffqTuH2ZU6ESwQvOLGElClOHbBrhJV6CDvrgtZO2iijhTc43p3N8KkuX3Nidc7 FARy8p3ZYGK0ZlCfYiPPXlygSuEy0CmYhVpT0KV9atzx4h1jEfbRrTGcmbdVMEKWoDMH pQjlY9jAl/d6o6zJfF5ROpQSXJ90qehO26xyCwftqH8GmzsZGOUIeTh+NGwzAj2epotj UPlpSCQgHod+ZrD/865W4A50JV4KeLtcfdHkJCP9+qmMrZBPn/5EWDK9H/0/2SiXp7RB o5ohE0QScWjEYDQt1hze246kNUXKzVyUGQRnRepmHC09ish3uxqlgmK5Tj+dHHVQC3o5 Crww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dYVzMiNP; 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 n18-20020a17090aab9200b001e2e762b21csi3103773pjq.20.2022.06.01.13.32.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 13:32: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=dYVzMiNP; 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 858FA1E2271; Wed, 1 Jun 2022 12:42:00 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243252AbiE3VAw (ORCPT + 99 others); Mon, 30 May 2022 17:00:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243200AbiE3VAe (ORCPT ); Mon, 30 May 2022 17:00:34 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C620A91569 for ; Mon, 30 May 2022 14:00:31 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id bf44so2884693lfb.0 for ; Mon, 30 May 2022 14:00:31 -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=lW0Pzr6bA3fYtV1xJl8AeDQlMEnR60yW2//eH29vCxE=; b=dYVzMiNPLwEXkptKECpn5hcp6De3x3lUTo4ciWbKYGPqQkIveiVsSkLh+lm9XNk8OO yAr8NmkDNELrM/63UlINwvrxPLx+QCa8OxL10AORjrhke2k4eDiY7gC3JYaMgp0wo+sO /AFN96MvSkkvfDQ0gZ1vrbdJqZ0qSnbL9PmHpuugdoiwPHT+0SUItW/CwiKf2KGqM069 /DcWc96cbRY1d7tl+GgQ9Dn/NQuhq6hzc0idRTFkuI2ktSQUrk/qbsY6FglCgvJw1aY6 PhLVWMRL9Be3A/jl8PKTry4t7RUU8EE1LoMZWkD1cvciSdy6l4nUZyucDoho0BczJ802 0Vww== 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=lW0Pzr6bA3fYtV1xJl8AeDQlMEnR60yW2//eH29vCxE=; b=uzN+/62r3rmvQ0M3I5WvXqAB+ZuurskQvaq8nyx+uvDXtIQSVGpre+F/BVU8pYLLI2 4sTADBccT2nsjXT6A4KGxsJNq3FkAOrSsX4JSO1bQlO8bCaPpLx0Exa0yO5WTgGrMDTz ZmkCIivkfNz6BI/i/32aweWJ1dTUS05NOq52vvIpYFN9CDc27FAJThLrj9SlJ/HcDExd 72N/F8xLHBFF7vnwhx2AB0LdO4m7auAFGK7NW8ykFAJoDFM0zcqaJ3604Q4hlwRiEQtd ZX5IR8pJSvK4PKN9Q7CNlJxHfBfvKRElMtn58wAnWmj+AKD2/P9Cae0izO0dG3Y8mIZ5 lfjw== X-Gm-Message-State: AOAM533MsU3w9PV6J+PUPMumO36wmYROZwMQJ76C+Y5RKtCQ/6bNyNYC iAY3tfQtoFd2lSLPxitQSUI= X-Received: by 2002:a05:6512:2520:b0:478:7f50:b011 with SMTP id be32-20020a056512252000b004787f50b011mr27488605lfb.72.1653944429968; Mon, 30 May 2022 14:00:29 -0700 (PDT) Received: from otyshchenko.router ([212.22.223.21]) by smtp.gmail.com with ESMTPSA id k21-20020a2ea275000000b0025550e2693asm581541ljm.38.2022.05.30.14.00.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 May 2022 14:00:29 -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 V3 4/8] xen/virtio: Enable restricted memory access using Xen grant mappings Date: Tue, 31 May 2022 00:00:13 +0300 Message-Id: <1653944417-17168-5-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1653944417-17168-1-git-send-email-olekstysh@gmail.com> References: <1653944417-17168-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 --- 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 --- 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