Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp915998pxk; Thu, 10 Sep 2020 01:55:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynU4F2Aj/Ct/sWRhSvgSsAUo1t0W4uiUjXN8c0mJBTpVsuFllgYNXYmt96ncna95TtUmLe X-Received: by 2002:a50:fc83:: with SMTP id f3mr8497593edq.102.1599728143317; Thu, 10 Sep 2020 01:55:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599728143; cv=none; d=google.com; s=arc-20160816; b=qUyJ97OvxAXnM+QPEVctHS8wjdM/PyaxMd15/sPu/WvRP4T5dnNYd66/eTbItiiRvI xb3I2WPXUcyjDTBandSanGvMDb50CSenE3AJ8nj/wE33gvkHZNSMGKwoB3fPh+fRKeHG zYKyyQcF7+Bvu82Bmq1C6gxizIPpOy2Gim4LPAj0t3hA96TRdLAPbQsg5kbxP62k/KlG FmYQD+UTc5A92OePbexoxItUmatU9QqrITwfTWI61vnQimPb5WHnFpwLDEVzqTEp5iti xwQrRYfWtn8/hJRIFcMLCstfF0/RIUL894PmBzCJHSQDcmMDEoWWi9c4Otl3gMxBe4jF z6pg== 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=sRPpqbahpQqemdeTO4/3zXQoLZgn4dX9e/cX2KkjQXU=; b=P3YRnaebpws0MS82m2awKT+ebx0xjkTGsASKoEHotq4dRA8X4VGLnrtaaLI9oODnfK 5DrNXaETqAhKPsVubKo3tNY/gaD03j5KW31UnjS/DYj/dA6A2o8wAJSAE5apMBBQdlIS oLsokV6CBq3dGy/fY+PllEMFmLfZ51RU7SlTAp7nqT+cndPfOj0cbT6pAirXrfaJEVxA Nd90nmkL2i5pfpEqWCEVxwIbHb18ML/hWTe8cC6AJ42INbAx9CYEps4EOAFIH9kzCErj Dk5mLThenSdJ+n5yhnWsyE+AtlxQ2xs13CwSLD9F+itEh5AEo+2UgsZcoM6iI5ii7Clq Es/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=Wx17EmnA; 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 u10si268036edo.419.2020.09.10.01.55.20; Thu, 10 Sep 2020 01:55:43 -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=Wx17EmnA; 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 S1730157AbgIJIyW (ORCPT + 99 others); Thu, 10 Sep 2020 04:54:22 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:33512 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728709AbgIJIyK (ORCPT ); Thu, 10 Sep 2020 04:54:10 -0400 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 08A8XGmj164198; Thu, 10 Sep 2020 04:53:59 -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=sRPpqbahpQqemdeTO4/3zXQoLZgn4dX9e/cX2KkjQXU=; b=Wx17EmnASg7HC4jesWmzTo7M5hyKs/1rQu5XD9A1z6i5e/iIZkF+L7THzSnvYtyUjY7x iaOgtCqNpCcl6ZaKfAvuaJyiXwJ2JdecgBxjjgQdpL4LCJB75RK+n/7a+aXCJ5C6I8Ls WQIC2pL0qqylSUVZdljh2A2qG5IsqUIK41g2iePUCwvzcu6OXATlhamu6CTUZcP92gMa RibKqFvq0frW+tu9rNStrWI5Xbm9dApe7bexgGF+BdPXgrxkMVFW3YXla4TaDtdHhrL/ ixEdAP1eLlDSLmSQ5NgMZLEtM7yryBdvlqCvRB+T3Ol/3GzXaqMdsf5e/OmG+ZtrhUvz 9Q== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 33fg431x25-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 10 Sep 2020 04:53:59 -0400 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 08A8XMQL164833; Thu, 10 Sep 2020 04:53:58 -0400 Received: from ppma01fra.de.ibm.com (46.49.7a9f.ip4.static.sl-reverse.com [159.122.73.70]) by mx0a-001b2d01.pphosted.com with ESMTP id 33fg431x19-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 10 Sep 2020 04:53:58 -0400 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 08A8q1mR006833; Thu, 10 Sep 2020 08:53:56 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma01fra.de.ibm.com with ESMTP id 33c2a81ab2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 10 Sep 2020 08:53:56 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 08A8rrXG64946530 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 10 Sep 2020 08:53:53 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6CD8711C054; Thu, 10 Sep 2020 08:53:53 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A8A0B11C058; Thu, 10 Sep 2020 08:53:52 +0000 (GMT) Received: from oc3016276355.ibm.com (unknown [9.145.28.144]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 10 Sep 2020 08:53:52 +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 v12 1/2] virtio: let arch advertise guest's memory access restrictions Date: Thu, 10 Sep 2020 10:53:49 +0200 Message-Id: <1599728030-17085-2-git-send-email-pmorel@linux.ibm.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1599728030-17085-1-git-send-email-pmorel@linux.ibm.com> References: <1599728030-17085-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-10_01:2020-09-10,2020-09-10 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=1 bulkscore=0 clxscore=1015 priorityscore=1501 mlxlogscore=999 mlxscore=0 phishscore=0 lowpriorityscore=0 spamscore=0 adultscore=0 malwarescore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009100079 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 Reviewed-by: Halil Pasic --- 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..ef2d49430800 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_ACCESS_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.25.1