Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp5364514iob; Mon, 9 May 2022 14:54:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzg6l9TrfWODikeXWTsY/EKHlGP8K4u4QkdvzUSLGjvIMT6uBQsZZlmi7Np0VdrXHblprCv X-Received: by 2002:a05:6402:4492:b0:428:a206:8912 with SMTP id er18-20020a056402449200b00428a2068912mr6192153edb.279.1652133271907; Mon, 09 May 2022 14:54:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652133271; cv=none; d=google.com; s=arc-20160816; b=yL/NLH/CnO8Omc3oA5cIMkX+JPsfIkUHF2nKGYXKd5USHJCEXU2plVDfNpvlSo9/SY T+oRB1ak8VYVLY4TMuM36z/HlEwcYr5sWa0dgETTju3h4hv9QMndqA0hEbPnSKgvcVWm XRdEZ1MAROXZ/YaAKRVWM09RVq1h8XNwU3RelvNp5V4wiC0BT4Z08r/0n7HyKZb+SLSg LHhBXAzEULdlSj0G6XbF4Rl93BVV+RPsZG9snTdyXRrMb/nGX4dGrAdv+CivxALhyJ8c aqxY6mfolGPiUXdOsjGtPLVAiFN/a9uqVzhnh+LnQndgbvPrP+MWimzkU/rCgHkp5epU ZkMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature; bh=1iJCAn/KCgp7QfJGRe1S3nZC7mY8taIu3PIcqJ13bcg=; b=jOvwQG3g+tRWtgCAVEsWFStuC7M1k/jCiyE8s1P7cgw2bXByX15Tqa3zsxM6CVqsfr D8DkB2mALyOjVVrb2Bjlm3IQScITMvCZ0GxEs0W0MYFo29eDampqSCHZiKDIci1P9+1g 5cmpsdr6b0F61Kw4MwnKfl8EtvW5LjbDHYMhtob4R1jP1lDTNLozua8V9LTwv4uzZK3R KA8HhVShcWNLGpq8y/O5f58bzOamRdt5WOhX7PpNI6njLCZEQPNZbpihWQnPQvONoP3z AEuGt4YKCadBA/IKuXKNkG7vuDrGGRaMacD6Ql+3yCk7RNeXblLPFXImW+QNG6lW4ljQ FPiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Me4tlFG4; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mp15-20020a1709071b0f00b006fa51d2401bsi5252757ejc.174.2022.05.09.14.54.08; Mon, 09 May 2022 14:54:31 -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=@kernel.org header.s=k20201202 header.b=Me4tlFG4; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230109AbiEIVnT (ORCPT + 99 others); Mon, 9 May 2022 17:43:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230079AbiEIVnI (ORCPT ); Mon, 9 May 2022 17:43:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CDBD12EA14 for ; Mon, 9 May 2022 14:39:14 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9A3F16173E for ; Mon, 9 May 2022 21:39:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35EC9C385BA; Mon, 9 May 2022 21:39:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1652132353; bh=H2dwaPwrXL4nxxXBdrMYB4OYXvEzLLPVoM3JTYQ5/l8=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=Me4tlFG4jGnLbuMeyoXfSkn5ct7XSBu3oHjHxskr6Fpm7aFmYoNMlvHM6QLhqvMbc tPpOOo4ntqvnBaahgw60upteBF05PNLgjTAaVZ2BBJHkP+xenkUOZG5P9BVoZqmJ4V 6QXU5VSj2B6uogMr4U+u4JWx4vTnEhF0hoVHBGXueVpLhsyHQj3wTA70E/R0ZcRCCw jWBsrRIBUu6+2LgYxAeipVJBCaiFtAaq9O3LEtz5tnxSAhfRpuUoT4x8BZHKQkamXy ZgZ5DkQWP2ewyhCNgnsUHZxThyGny2cUFN7u3HrvAbNSua7hViTu0JF2ItIrLlX8Ol feJ9kW4H8CUWw== Date: Mon, 9 May 2022 14:39:12 -0700 (PDT) From: Stefano Stabellini X-X-Sender: sstabellini@ubuntu-linux-20-04-desktop To: Oleksandr Tyshchenko cc: xen-devel@lists.xenproject.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, 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: Re: [PATCH V2 4/7] xen/virtio: Enable restricted memory access using Xen grant mappings In-Reply-To: <1651947548-4055-5-git-send-email-olekstysh@gmail.com> Message-ID: References: <1651947548-4055-1-git-send-email-olekstysh@gmail.com> <1651947548-4055-5-git-send-email-olekstysh@gmail.com> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 On Sat, 7 May 2022, Oleksandr Tyshchenko wrote: > 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 The patch looks OK to me 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 > --- > 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 5038edb..fcd5d5d 100644 > --- a/arch/x86/xen/enlighten_pv.c > +++ b/arch/x86/xen/enlighten_pv.c > @@ -109,6 +109,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);