Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3084644pxk; Mon, 7 Sep 2020 02:43:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwrgtfN5gnOrMliXvEtwqcub8r5qvN3GQ+tpCL+4JHv05hHKozINacOyRijwnwu8Pc5DiF5 X-Received: by 2002:a17:906:480a:: with SMTP id w10mr19805694ejq.372.1599471815838; Mon, 07 Sep 2020 02:43:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599471815; cv=none; d=google.com; s=arc-20160816; b=lk4VY0PiTmzXHi47t9i/ZogIXoTudOdHHufsVxEhfB1ObfRalQcrk6reSHhg6eJgj6 bUXh0o2qtvWo2tM63RDs7h9YKkw7ji8DuetwW+yz+5McgW1e23JYc8sRX1ORYKqUyh2Z NJ7Xa6GcLncFkTLWOmGCl4zAxa9/vSr13iIcTROQSbt0Vmb73DCNmN0NLEvlOvzyBUym 0jH+rCHk4rbBr8ESDmYxC20K6BTMJmE24DaZibQTvJ0XFgF5bLWGVUgY6gN5tZ5koUc8 P0t7+2hP/H979DSdU0llB1EBRHqvnvXfQT9MJepMr8usBsmsSMTb2wkrNGi1fayig33P OyqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=5vVyn/VEe6Gx+GNDMxeR+LiTeTBWESsSZ3pi73AegSs=; b=rv/MiOYYFKU8T25LXjqBXFiai2GespJWG7I6ayO2qlVcxEsi4sG5SfEs/nci7AODM9 vkao2Sk5iqWr9+s2ya25EpkpVXPa56PaSYXoji7marz2dOc4wSb0LnUjFhKi13+iWlDp 98z87/5bdqNICCOQoyoakzQuYJc/n6PXJf1XK/kgTLyG1E043U/EgNLBFw89HXrObIHc v+OwiYNy3A0nuDGfiPSXmWkWOmheBk3ZkyvRkkIMEZE+TXFaG6qMp6SuN9Eo5K7kW9I5 lXC2jvnqJzmMkak4TYucPUDHfqjfYUvBbPHQGkkRbMsKmBIxbus3Iw6WHElsGMqefPzM aRxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=or5Yam2q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e11si9444474edj.448.2020.09.07.02.43.12; Mon, 07 Sep 2020 02:43:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=or5Yam2q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728531AbgIGJjh (ORCPT + 99 others); Mon, 7 Sep 2020 05:39:37 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:4850 "EHLO mx0b-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728333AbgIGJja (ORCPT ); Mon, 7 Sep 2020 05:39:30 -0400 Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0879WP3j162588; Mon, 7 Sep 2020 05:39:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=pp1; bh=5vVyn/VEe6Gx+GNDMxeR+LiTeTBWESsSZ3pi73AegSs=; b=or5Yam2qzYABu+F+Xo1XwJVAVjFKCAiHYupbhgDBVklmpHLTZAYkjwkyzEIHAI7tcLVl 9HT2dR5LwSTOqmGXVxi6SEYjJs6Z8yBzPcoKnRY3S8ruj12Qka1wH9PMgEUP7lBFYcim 9ylpRLNhB7uXoOXQBgWEy0MvlkeQCTtBWCO6aPdTrfW3X4H5m0+mb9V73+NZm7IJpfco ZTCqwb8iaTIIJdGduedhTCrS5pYOEjnOvsDzuT48pP+LcZC9HChKzoTgb0fJ01WBEDRp tg4MFnkqY0FvnUjV/akrBV+lkOMbuIH3LNHrubxDMzKOTOCJ18+fcJgkYIuQM3WNQZTN UA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 33dhnrh857-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 07 Sep 2020 05:39:17 -0400 Received: from m0127361.ppops.net (m0127361.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 0879WZ6n163168; Mon, 7 Sep 2020 05:39:16 -0400 Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com with ESMTP id 33dhnrh848-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 07 Sep 2020 05:39:16 -0400 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 0879bpuO013779; Mon, 7 Sep 2020 09:39:14 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma06ams.nl.ibm.com with ESMTP id 33cyq50ycb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 07 Sep 2020 09:39:14 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0879dBKj38142398 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 7 Sep 2020 09:39:11 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1E150A4066; Mon, 7 Sep 2020 09:39:11 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4D609A4060; Mon, 7 Sep 2020 09:39:10 +0000 (GMT) Received: from oc3016276355.ibm.com (unknown [9.145.86.222]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 7 Sep 2020 09:39:10 +0000 (GMT) From: Pierre Morel To: linux-kernel@vger.kernel.org Cc: pasic@linux.ibm.com, borntraeger@de.ibm.com, frankja@linux.ibm.com, mst@redhat.com, jasowang@redhat.com, cohuck@redhat.com, kvm@vger.kernel.org, linux-s390@vger.kernel.org, virtualization@lists.linux-foundation.org, thomas.lendacky@amd.com, david@gibson.dropbear.id.au, linuxram@us.ibm.com, hca@linux.ibm.com, gor@linux.ibm.com Subject: [PATCH v11 1/2] virtio: let arch advertise guest's memory access restrictions Date: Mon, 7 Sep 2020 11:39:06 +0200 Message-Id: <1599471547-28631-2-git-send-email-pmorel@linux.ibm.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1599471547-28631-1-git-send-email-pmorel@linux.ibm.com> References: <1599471547-28631-1-git-send-email-pmorel@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-09-07_04:2020-09-07,2020-09-07 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 bulkscore=0 mlxlogscore=999 spamscore=0 lowpriorityscore=0 phishscore=0 malwarescore=0 adultscore=0 clxscore=1015 mlxscore=0 suspectscore=1 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009070093 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org An architecture may restrict host access to guest memory, e.g. IBM s390 Secure Execution or AMD SEV. Provide a new Kconfig entry the architecture can select, CONFIG_ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS, when it provides the arch_has_restricted_virtio_memory_access callback to advertise to VIRTIO common code when the architecture restricts memory access from the host. The common code can then fail the probe for any device where VIRTIO_F_ACCESS_PLATFORM is required, but not set. Signed-off-by: Pierre Morel Reviewed-by: Cornelia Huck --- drivers/virtio/Kconfig | 6 ++++++ drivers/virtio/virtio.c | 15 +++++++++++++++ include/linux/virtio_config.h | 10 ++++++++++ 3 files changed, 31 insertions(+) diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig index 5c92e4a50882..3999b411624c 100644 --- a/drivers/virtio/Kconfig +++ b/drivers/virtio/Kconfig @@ -6,6 +6,12 @@ config VIRTIO bus, such as CONFIG_VIRTIO_PCI, CONFIG_VIRTIO_MMIO, CONFIG_RPMSG or CONFIG_S390_GUEST. +config ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS + bool + help + This option is selected if the architecture may need to enforce + VIRTIO_F_IOMMU_PLATFORM. + menuconfig VIRTIO_MENU bool "Virtio drivers" default y diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c index a977e32a88f2..a2b3f12e10a2 100644 --- a/drivers/virtio/virtio.c +++ b/drivers/virtio/virtio.c @@ -176,6 +176,21 @@ int virtio_finalize_features(struct virtio_device *dev) if (ret) return ret; + ret = arch_has_restricted_virtio_memory_access(); + if (ret) { + if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1)) { + dev_warn(&dev->dev, + "device must provide VIRTIO_F_VERSION_1\n"); + return -ENODEV; + } + + if (!virtio_has_feature(dev, VIRTIO_F_ACCESS_PLATFORM)) { + dev_warn(&dev->dev, + "device must provide VIRTIO_F_ACCESS_PLATFORM\n"); + return -ENODEV; + } + } + if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1)) return 0; diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h index 8fe857e27ef3..3f697c8c8205 100644 --- a/include/linux/virtio_config.h +++ b/include/linux/virtio_config.h @@ -540,4 +540,14 @@ static inline void virtio_cwrite64(struct virtio_device *vdev, virtio_cread_le((vdev), structname, member, ptr); \ _r; \ }) + +#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 */ -- 2.17.1