From nobody Sun May 19 01:43:02 2024 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=1651679852; cv=none; d=zohomail.com; s=zohoarc; b=Pamj9qXlo/FmUSLOuAz2DlKd0OSf6L+WL+IuVvtUOCUQ9lRMg27k9V4LF362nciaDsnotsOnds/kmyAZkJzZYuDiTX/hdS8jpYgMydF6s3BoqPpzpLf4zjaTHlTFvLmLqFkglufFR9St8cUhv+lRHU/DcXf/tCfV+3XFR8QagpA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651679852; 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=Nu4FNczpZovRCMLybZ5k5rdDCEUYi3yOv4DX+sivCNc=; b=nJvbVqzbALVKBnfipxoo2B10N3x6JSVVJoUyQBuPSc2UYgrZbYvUx02hIJnwg2jzT4uDGXUvMjdyzC1e47+mZW3wlctdtXYENpmfsd1qdaFC85bB7nU5CFQiYCnpiBLZxbsFYIsgHB8SJQ+UYdzaFF5ZKREfX6A3J8KGeqPSOjc= 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 165167985281050.74208363686728; Wed, 4 May 2022 08:57:32 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.320871.541847 (Exim 4.92) (envelope-from ) id 1nmHNH-0004Cc-DV; Wed, 04 May 2022 15:57:11 +0000 Received: by outflank-mailman (output) from mailman id 320871.541847; Wed, 04 May 2022 15:57:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nmHNH-0004CV-9h; Wed, 04 May 2022 15:57:11 +0000 Received: by outflank-mailman (input) for mailman id 320871; Wed, 04 May 2022 15:57:09 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nmHNF-0003wP-6r for xen-devel@lists.xenproject.org; Wed, 04 May 2022 15:57:09 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d98c4a11-cbc2-11ec-a406-831a346695d4; Wed, 04 May 2022 17:57:07 +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-out1.suse.de (Postfix) with ESMTPS id 641FE210E1; Wed, 4 May 2022 15:57:07 +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 AF262132C4; Wed, 4 May 2022 15:57:06 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id GLt2KVKicmLWPAAAMHmgww (envelope-from ); Wed, 04 May 2022 15:57:06 +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: d98c4a11-cbc2-11ec-a406-831a346695d4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1651679827; 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=Nu4FNczpZovRCMLybZ5k5rdDCEUYi3yOv4DX+sivCNc=; b=YaaUVhSRP5GfOdY2LJNhrw0zcyHIdbiTMz0zj9Uc7X0cg8wRTltA+1tJX8+n+pE3HmN/96 GCQ4MBEVKbCBpzNefZPdi8vvKmVmniACzN6LXAmRJGwENURN4ArHLM2iHP3MAqfwFoO41q WQJiMyj03IXIYJcUR850l7JEgifK4ZA= From: Juergen Gross To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, x86@kernel.org, linux-s390@vger.kernel.org, virtualization@lists.linux-foundation.org Cc: Juergen Gross , Arnd Bergmann , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , "Michael S. Tsirkin" , Jason Wang , Christoph Hellwig , Oleksandr Tyshchenko Subject: [PATCH v3 1/2] kernel: add platform_has() infrastructure Date: Wed, 4 May 2022 17:57:02 +0200 Message-Id: <20220504155703.13336-2-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220504155703.13336-1-jgross@suse.com> References: <20220504155703.13336-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1651679853634100001 Content-Type: text/plain; charset="utf-8" Add a simple infrastructure for setting, resetting and querying platform feature flags. Flags can be either global or architecture specific. Signed-off-by: Juergen Gross Acked-by: Borislav Petkov Reviewed-by: Christoph Hellwig Reviewed-by: Oleksandr Tyshchenko Tested-by: Oleksandr Tyshchenko --- V2: - rename set/reset functions to platform_[set|clear]() (Boris Petkov, Heiko Carstens) - move function implementations to c file (Boris Petkov) --- MAINTAINERS | 8 ++++++++ include/asm-generic/Kbuild | 1 + include/asm-generic/platform-feature.h | 8 ++++++++ include/linux/platform-feature.h | 15 ++++++++++++++ kernel/Makefile | 2 +- kernel/platform-feature.c | 27 ++++++++++++++++++++++++++ 6 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 include/asm-generic/platform-feature.h create mode 100644 include/linux/platform-feature.h create mode 100644 kernel/platform-feature.c diff --git a/MAINTAINERS b/MAINTAINERS index edc96cdb85e8..2749a88d75f2 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -15657,6 +15657,14 @@ S: Maintained F: Documentation/devicetree/bindings/iio/chemical/plantower,pms7003.yaml F: drivers/iio/chemical/pms7003.c =20 +PLATFORM FEATURE INFRASTRUCTURE +M: Juergen Gross +S: Maintained +F: arch/*/include/asm/platform-feature.h +F: include/asm-generic/platform-feature.h +F: include/linux/platform-feature.h +F: kernel/platform-feature.c + PLDMFW LIBRARY M: Jacob Keller S: Maintained diff --git a/include/asm-generic/Kbuild b/include/asm-generic/Kbuild index 302506bbc2a4..8e47d483b524 100644 --- a/include/asm-generic/Kbuild +++ b/include/asm-generic/Kbuild @@ -44,6 +44,7 @@ mandatory-y +=3D msi.h mandatory-y +=3D pci.h mandatory-y +=3D percpu.h mandatory-y +=3D pgalloc.h +mandatory-y +=3D platform-feature.h mandatory-y +=3D preempt.h mandatory-y +=3D rwonce.h mandatory-y +=3D sections.h diff --git a/include/asm-generic/platform-feature.h b/include/asm-generic/p= latform-feature.h new file mode 100644 index 000000000000..4b0af3d51588 --- /dev/null +++ b/include/asm-generic/platform-feature.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_PLATFORM_FEATURE_H +#define _ASM_GENERIC_PLATFORM_FEATURE_H + +/* Number of arch specific feature flags. */ +#define PLATFORM_ARCH_FEAT_N 0 + +#endif /* _ASM_GENERIC_PLATFORM_FEATURE_H */ diff --git a/include/linux/platform-feature.h b/include/linux/platform-feat= ure.h new file mode 100644 index 000000000000..6ed859928b97 --- /dev/null +++ b/include/linux/platform-feature.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _PLATFORM_FEATURE_H +#define _PLATFORM_FEATURE_H + +#include +#include + +/* The platform features are starting with the architecture specific ones.= */ +#define PLATFORM_FEAT_N (0 + PLATFORM_ARCH_FEAT_N) + +void platform_set(unsigned int feature); +void platform_clear(unsigned int feature); +bool platform_has(unsigned int feature); + +#endif /* _PLATFORM_FEATURE_H */ diff --git a/kernel/Makefile b/kernel/Makefile index 847a82bfe0e3..2f412f80110d 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -7,7 +7,7 @@ obj-y =3D fork.o exec_domain.o panic.o \ cpu.o exit.o softirq.o resource.o \ sysctl.o capability.o ptrace.o user.o \ signal.o sys.o umh.o workqueue.o pid.o task_work.o \ - extable.o params.o \ + extable.o params.o platform-feature.o \ kthread.o sys_ni.o nsproxy.o \ notifier.o ksysfs.o cred.o reboot.o \ async.o range.o smpboot.o ucount.o regset.o diff --git a/kernel/platform-feature.c b/kernel/platform-feature.c new file mode 100644 index 000000000000..cb6a6c3e4fed --- /dev/null +++ b/kernel/platform-feature.c @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include + +#define PLATFORM_FEAT_ARRAY_SZ BITS_TO_LONGS(PLATFORM_FEAT_N) +static unsigned long __read_mostly platform_features[PLATFORM_FEAT_ARRAY_S= Z]; + +void platform_set(unsigned int feature) +{ + set_bit(feature, platform_features); +} +EXPORT_SYMBOL_GPL(platform_set); + +void platform_clear(unsigned int feature) +{ + clear_bit(feature, platform_features); +} +EXPORT_SYMBOL_GPL(platform_clear); + +bool platform_has(unsigned int feature) +{ + return test_bit(feature, platform_features); +} +EXPORT_SYMBOL_GPL(platform_has); --=20 2.35.3 From nobody Sun May 19 01:43:02 2024 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=1651679856; cv=none; d=zohomail.com; s=zohoarc; b=mlU+2G3K8/FS+2Lhg61YHIN7kQg6gqc4yPBG/+jm1EQUDT/4k3UjtRIhSJYokF6Y4BeA2DvBtRcoulOQPg6WCs4Gq3SUFZt/8X3YI1f3VwfQXHvm98vgn2ieP+RoMwppivgL4VfTiw76vZdNix+s3Kar81ASpXX8QyRKg1J1wqA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651679856; 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=0lMxpONprAdpQbV0uZskDbB1fEIP7YYHFmYdwzZhDVE=; b=MnaPTd0tJeL4V7vZJ19a8sMTZLRF+Tthn8Yz/XT7OaccNv0WVALS7noMTHVJhDu/GcK3fkQVgd3lvfjqxZEshQhCyWpD0NsbBxkhvRt9AAQHpn6hB596CtCwfVz3t3LE9iAP1HaV0fLOnlxh2Ap0TzUSccZU0mlPLKFMIjKRw4c= 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 1651679856372308.81476053729125; Wed, 4 May 2022 08:57:36 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.320872.541852 (Exim 4.92) (envelope-from ) id 1nmHNH-0004Fu-Pp; Wed, 04 May 2022 15:57:11 +0000 Received: by outflank-mailman (output) from mailman id 320872.541852; Wed, 04 May 2022 15:57:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nmHNH-0004EZ-IY; Wed, 04 May 2022 15:57:11 +0000 Received: by outflank-mailman (input) for mailman id 320872; Wed, 04 May 2022 15:57:10 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nmHNG-0003wP-72 for xen-devel@lists.xenproject.org; Wed, 04 May 2022 15:57:10 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d9ea31e3-cbc2-11ec-a406-831a346695d4; Wed, 04 May 2022 17:57:08 +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 020191F74C; Wed, 4 May 2022 15:57:08 +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 632F013AFD; Wed, 4 May 2022 15:57:07 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id WNXUFlOicmLWPAAAMHmgww (envelope-from ); Wed, 04 May 2022 15:57:07 +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: d9ea31e3-cbc2-11ec-a406-831a346695d4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1651679828; 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=0lMxpONprAdpQbV0uZskDbB1fEIP7YYHFmYdwzZhDVE=; b=FZxi5C4az6xiRDRt5zrq3DDmodZF2oavjNsJxai9hYEooOypl2qGaNwDnpiy9Tx+vC7rtJ 6VsX/43rtog5GY2zI9yxWTXDz0XrgLb2dS1b5YOdmVOPtV5uJQwTW4VSx39BlUI2CPd3R6 9okDcBlH2MvPKcdeiIkPEin/HR4d5xc= From: Juergen Gross To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, x86@kernel.org, linux-s390@vger.kernel.org, virtualization@lists.linux-foundation.org Cc: Juergen Gross , Arnd Bergmann , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , "Michael S. Tsirkin" , Jason Wang , Christoph Hellwig , Oleksandr Tyshchenko Subject: [PATCH v3 2/2] virtio: replace arch_has_restricted_virtio_memory_access() Date: Wed, 4 May 2022 17:57:03 +0200 Message-Id: <20220504155703.13336-3-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220504155703.13336-1-jgross@suse.com> References: <20220504155703.13336-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1651679857570100005 Content-Type: text/plain; charset="utf-8" Instead of using arch_has_restricted_virtio_memory_access() together with CONFIG_ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS, replace those with platform_has() and a new platform feature PLATFORM_VIRTIO_RESTRICTED_MEM_ACCESS. Signed-off-by: Juergen Gross Acked-by: Borislav Petkov Reviewed-by: Christoph Hellwig Reviewed-by: Oleksandr Tyshchenko Tested-by: Oleksandr Tyshchenko --- V2: - move setting of PLATFORM_VIRTIO_RESTRICTED_MEM_ACCESS in SEV case to sev_setup_arch(). V3: - remove Hyper-V chunk (Michael Kelley) - remove include virtio_config.h from mem_encrypt.c (Oleksandr Tyshchenko) - add comment for PLATFORM_VIRTIO_RESTRICTED_MEM_ACCESS (Oleksandr Tyshchen= ko) --- arch/s390/Kconfig | 1 - arch/s390/mm/init.c | 13 +++---------- arch/x86/Kconfig | 1 - arch/x86/mm/mem_encrypt.c | 7 ------- arch/x86/mm/mem_encrypt_amd.c | 4 ++++ drivers/virtio/Kconfig | 6 ------ drivers/virtio/virtio.c | 5 ++--- include/linux/platform-feature.h | 6 +++++- include/linux/virtio_config.h | 9 --------- 9 files changed, 14 insertions(+), 38 deletions(-) diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig index e084c72104f8..f97a22ae69a8 100644 --- a/arch/s390/Kconfig +++ b/arch/s390/Kconfig @@ -772,7 +772,6 @@ menu "Virtualization" config PROTECTED_VIRTUALIZATION_GUEST def_bool n prompt "Protected virtualization guest support" - select ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS help Select this option, if you want to be able to run this kernel as a protected virtualization KVM guest. diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c index 86ffd0d51fd5..2c3b451813ed 100644 --- a/arch/s390/mm/init.c +++ b/arch/s390/mm/init.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -168,22 +169,14 @@ bool force_dma_unencrypted(struct device *dev) return is_prot_virt_guest(); } =20 -#ifdef CONFIG_ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS - -int arch_has_restricted_virtio_memory_access(void) -{ - return is_prot_virt_guest(); -} -EXPORT_SYMBOL(arch_has_restricted_virtio_memory_access); - -#endif - /* protected virtualization */ static void pv_init(void) { if (!is_prot_virt_guest()) return; =20 + platform_set(PLATFORM_VIRTIO_RESTRICTED_MEM_ACCESS); + /* make sure bounce buffers are shared */ swiotlb_force =3D SWIOTLB_FORCE; swiotlb_init(1); diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 4bed3abf444d..eeb7c6c8eec5 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1515,7 +1515,6 @@ config X86_CPA_STATISTICS config X86_MEM_ENCRYPT select ARCH_HAS_FORCE_DMA_UNENCRYPTED select DYNAMIC_PHYSICAL_MASK - select ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS def_bool n =20 config AMD_MEM_ENCRYPT diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c index 50d209939c66..18a55a0f1ca2 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -12,7 +12,6 @@ #include #include #include -#include =20 /* Override for DMA direct allocation check - ARCH_HAS_FORCE_DMA_UNENCRYPT= ED */ bool force_dma_unencrypted(struct device *dev) @@ -76,9 +75,3 @@ void __init mem_encrypt_init(void) =20 print_mem_encrypt_feature_info(); } - -int arch_has_restricted_virtio_memory_access(void) -{ - return cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT); -} -EXPORT_SYMBOL_GPL(arch_has_restricted_virtio_memory_access); diff --git a/arch/x86/mm/mem_encrypt_amd.c b/arch/x86/mm/mem_encrypt_amd.c index 6169053c2854..39b71084d36b 100644 --- a/arch/x86/mm/mem_encrypt_amd.c +++ b/arch/x86/mm/mem_encrypt_amd.c @@ -21,6 +21,7 @@ #include #include #include +#include =20 #include #include @@ -206,6 +207,9 @@ void __init sev_setup_arch(void) size =3D total_mem * 6 / 100; size =3D clamp_val(size, IO_TLB_DEFAULT_SIZE, SZ_1G); swiotlb_adjust_size(size); + + /* Set restricted memory access for virtio. */ + platform_set(PLATFORM_VIRTIO_RESTRICTED_MEM_ACCESS); } =20 static unsigned long pg_level_to_pfn(int level, pte_t *kpte, pgprot_t *ret= _prot) diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig index b5adf6abd241..a6dc8b5846fe 100644 --- a/drivers/virtio/Kconfig +++ b/drivers/virtio/Kconfig @@ -6,12 +6,6 @@ config VIRTIO bus, such as CONFIG_VIRTIO_PCI, CONFIG_VIRTIO_MMIO, CONFIG_RPMSG or CONFIG_S390_GUEST. =20 -config ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS - bool - help - This option is selected if the architecture may need to enforce - VIRTIO_F_ACCESS_PLATFORM - config VIRTIO_PCI_LIB tristate help diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c index 22f15f444f75..371e16b18381 100644 --- a/drivers/virtio/virtio.c +++ b/drivers/virtio/virtio.c @@ -5,6 +5,7 @@ #include #include #include +#include #include =20 /* Unique numbering for virtio devices. */ @@ -170,12 +171,10 @@ EXPORT_SYMBOL_GPL(virtio_add_status); static int virtio_features_ok(struct virtio_device *dev) { unsigned status; - int ret; =20 might_sleep(); =20 - ret =3D arch_has_restricted_virtio_memory_access(); - if (ret) { + if (platform_has(PLATFORM_VIRTIO_RESTRICTED_MEM_ACCESS)) { if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1)) { dev_warn(&dev->dev, "device must provide VIRTIO_F_VERSION_1\n"); diff --git a/include/linux/platform-feature.h b/include/linux/platform-feat= ure.h index 6ed859928b97..b2f48be999fa 100644 --- a/include/linux/platform-feature.h +++ b/include/linux/platform-feature.h @@ -6,7 +6,11 @@ #include =20 /* The platform features are starting with the architecture specific ones.= */ -#define PLATFORM_FEAT_N (0 + PLATFORM_ARCH_FEAT_N) + +/* Used to enable platform specific DMA handling for virtio devices. */ +#define PLATFORM_VIRTIO_RESTRICTED_MEM_ACCESS (0 + PLATFORM_ARCH_FEAT_N) + +#define PLATFORM_FEAT_N (1 + PLATFORM_ARCH_FEAT_N) =20 void platform_set(unsigned int feature); void platform_clear(unsigned int feature); diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h index b341dd62aa4d..79498298519d 100644 --- a/include/linux/virtio_config.h +++ b/include/linux/virtio_config.h @@ -559,13 +559,4 @@ static inline void virtio_cwrite64(struct virtio_devic= e *vdev, _r; \ }) =20 -#ifdef CONFIG_ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS -int arch_has_restricted_virtio_memory_access(void); -#else -static inline int arch_has_restricted_virtio_memory_access(void) -{ - return 0; -} -#endif /* CONFIG_ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS */ - #endif /* _LINUX_VIRTIO_CONFIG_H */ --=20 2.35.3