Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp587644pxa; Wed, 19 Aug 2020 09:24:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw30pjc12BKNNyPSPrKwF9zKh0nzbGng/5jdwGowQQ9Tl4kAnnpin3amwCu3iJScFMqoWHx X-Received: by 2002:a50:954d:: with SMTP id v13mr25773446eda.337.1597854296804; Wed, 19 Aug 2020 09:24:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597854296; cv=none; d=google.com; s=arc-20160816; b=X8zpBO53ifZ0bnpOVzAhyVFqw0ZqjmTjx/OWuVGIH55isaRgOdimL2iuzr8LnZuGf/ AVl9EG+//OLA6N7Tpm0L2ptCM0adZVA/F+TlowLUNTBLF9sSf32Kmd4+9AWeC6NbD3dy 3jmIDRSfyObnyh4hYzOwPySqYXbQT0O+7jxD+RZ6BiH3TDghQHqYr2plVeErAfrGZYNJ exwbJYXZMWzURiCo+by6mZj4Wx8s16QuPxo4gTx6I7VynqULot/CIUYQgFjuYva83FQJ xDGxYcoT6pxU7nZ7geMxQf3eLZib7TqgALhgUST4rNDzvolA0AZVSBcomZdDG5sqOicB e+Xw== 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=6ZXC6je36oLn1mYnJGIyGlD/M949prKxH1odvFRZD8I=; b=K9vEPsP5vQrT9yqvBoikAIrtKtNtXPc6Bh3enxUv2w/NetsuqMRh/t32NX2vmnsAJ4 aj/JbiBLuKUZmF1DSwfl94r6+lA9WgTXg1QLBrztmX8Pn55Gwn82mEzxcnMO76niLs81 xCjBmPpo31AEDs/dRXIe3GIwsSQKsngW43YBoF3jDN8nKbXwgsUhLMn2iLeWA11DbXfp hzepwFpQnkkYhd+3RwtngrWdQUH+Fn7YtvHuBa+rHIOjBLT7ZUHrrvX/stgbo6W7CwAI XHjPTgiHxzrbIt/58YaaaHsXarkPW/P6TIXBc5iE+0PNqIgaHKxIyJIAUO2B1UGpcN6g 8jdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=SIhilIqP; 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 j20si15540698edr.321.2020.08.19.09.24.32; Wed, 19 Aug 2020 09:24:56 -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=SIhilIqP; 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 S1726971AbgHSQXm (ORCPT + 99 others); Wed, 19 Aug 2020 12:23:42 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:28488 "EHLO mx0b-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726578AbgHSQXf (ORCPT ); Wed, 19 Aug 2020 12:23:35 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 07JG6Uh7150306; Wed, 19 Aug 2020 12:23:26 -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=6ZXC6je36oLn1mYnJGIyGlD/M949prKxH1odvFRZD8I=; b=SIhilIqPcIK/aa38dBwqYbgY4nOTXzoymB1voFpIt8xsh3vY5fX/J1XeV4pH0hU8+tpM E2rgqNsNXzTOp8NJ6BnYHOg3ue6eR48aZe309ndWmEzW1L+mz8GUqtCkLYwb+ogYESHI HFDFKAFCcEF+D/YubPgrfqr2vtGCC03oU1xwMSY+vmwFNs8v7K6sR3x4B00d6uiKhZ6b +bvS2CRCFlWsV0m3LZoAlGvZGiSx0FSS5boZP8XtuS3rYv89py3jGVuMVuTxMWYHSpbf xRejIk4ZH7UMzEe4uCUe5b8cmbTdM+LeVy4lxIeqQSYnD+L/CwtNZvZJ8MNnQjxET3t2 1g== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3304sxje3s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Aug 2020 12:23:26 -0400 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 07JG7nkV151688; Wed, 19 Aug 2020 12:23:26 -0400 Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 3304sxje34-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Aug 2020 12:23:25 -0400 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 07JGEmgA014897; Wed, 19 Aug 2020 16:23:24 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma04ams.nl.ibm.com with ESMTP id 3304cc23p5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Aug 2020 16:23:23 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 07JGNLGY23790036 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Aug 2020 16:23:21 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 21C4B5204E; Wed, 19 Aug 2020 16:23:21 +0000 (GMT) Received: from oc3016276355.ibm.com (unknown [9.145.33.131]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 7A80752050; Wed, 19 Aug 2020 16:23:20 +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 v9 1/2] virtio: let arch advertise guest's memory access restrictions Date: Wed, 19 Aug 2020 18:23:17 +0200 Message-Id: <1597854198-2871-2-git-send-email-pmorel@linux.ibm.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1597854198-2871-1-git-send-email-pmorel@linux.ibm.com> References: <1597854198-2871-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-08-19_09:2020-08-19,2020-08-19 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 adultscore=0 mlxscore=0 malwarescore=0 spamscore=0 mlxlogscore=999 lowpriorityscore=0 bulkscore=0 phishscore=0 impostorscore=0 suspectscore=1 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2008190133 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. 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 VIRTIO common code when the architecture restricts memory access from the host. Signed-off-by: Pierre Morel --- drivers/virtio/Kconfig | 6 ++++++ drivers/virtio/virtio.c | 15 +++++++++++++++ include/linux/virtio_config.h | 9 +++++++++ 3 files changed, 30 insertions(+) diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig index 5809e5f5b157..509f3b4d8ba1 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 by any architecture enforcing + 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..57ca41d77b09 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_IOMMU_PLATFORM)) { + dev_warn(&dev->dev, + "device must provide VIRTIO_F_IOMMU_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 bb4cc4910750..e380664642b4 100644 --- a/include/linux/virtio_config.h +++ b/include/linux/virtio_config.h @@ -459,4 +459,13 @@ static inline void virtio_cwrite64(struct virtio_device *vdev, _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.25.1