Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp3257562pxa; Tue, 18 Aug 2020 10:23:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVzfuKa8DkO76A0gpVo60YhLq/UjbMJpLU407RukGER1f3QTVyUfwF0VUX/jhc4s7r1Odx X-Received: by 2002:a05:6402:1347:: with SMTP id y7mr20923511edw.189.1597771432456; Tue, 18 Aug 2020 10:23:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597771432; cv=none; d=google.com; s=arc-20160816; b=0YCcp4H1DP2GmWSQZtv718kLOXAvelUpf8g4eKpA88CdHSZ39mOYrLWE82kdSWX1Ub 5UzmsB0K3+1aSh0hVvpefxY87aCgSiQB5ak8NjFMs1Zki0QCa9CoHfQJ+yGYLqtgcdlg suBGO8UZaQeNyeIWykEijgTQ26SN4NcLSurtuOdIEwYO5ZnUZ1YMetQmjywMLq+fH90e FAcYbd0A7kHsSVN+9wYvSBsYc1mXtN5MFGXjGsRoY0v0X/D7Cncb11MLc4Yha0YPdRRV x71nrkhAI1SPOi8hD1pv/djkGktUXbcouzqpK3oSO4A3Wd8HyqDd5Pm4BIMAm678BHBY Crcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=R08BwjXqzWFxBJwSN04NiBU/noVfIjB10z++NeMlyQE=; b=ShraCWH5wGIQg5tQZrB4+iUs7dTsE5n8/HmMJdx0kBzvoCT1y7BNun9rGrL6CjoVEV wfDfoYBrV2Qw6Phy2EALMMuzyP0U5dW95+kW8jeX16QmZM5lT+H5cHhTSO8N3J/fmC6U qq+7l9HNZzMHcIggLxrjbyIrC04liaU3XxxhMFhY3ukIC/tc/51+YC474+GxDsZLo1x1 Vr2JSEdosCV3MZXLAKo40Fo8MFgmfrLntu85wiDDAKkKyHs2UM08GemYV+90Q2EFw1Cb H08p8bMEqvcNadyEBOrRo0qP5FbZXxdSrZ3O6sRB+fyJS3453wAZ9JLWV6rJP7SCKRKK sE4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gIRfnPlh; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c12si15616996edn.358.2020.08.18.10.23.28; Tue, 18 Aug 2020 10:23:52 -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=@redhat.com header.s=mimecast20190719 header.b=gIRfnPlh; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728651AbgHRRWu (ORCPT + 99 others); Tue, 18 Aug 2020 13:22:50 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:42565 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728613AbgHRRWr (ORCPT ); Tue, 18 Aug 2020 13:22:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597771366; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=R08BwjXqzWFxBJwSN04NiBU/noVfIjB10z++NeMlyQE=; b=gIRfnPlhvYkZL/mW/SQQ5CoNzCIAew6k+jLnTGdh/CljDTWEp2wnW9tihHbGnLnIcNJw61 lSrxQRzyNvDoNbtwA+Hs7bVqhQohorgz7TiiM74uG3eFf1/LZwvqIoJvBVq8j6n/I1Av8a bANqlw7VYnTuqKZMmIsSKS4FE3j8VYo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-427-Njsv1FvbPQazsJW1j4QtZw-1; Tue, 18 Aug 2020 13:22:43 -0400 X-MC-Unique: Njsv1FvbPQazsJW1j4QtZw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A709310066FF; Tue, 18 Aug 2020 17:22:41 +0000 (UTC) Received: from gondolin (ovpn-112-221.ams2.redhat.com [10.36.112.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id EE2BF5D9DC; Tue, 18 Aug 2020 17:22:35 +0000 (UTC) Date: Tue, 18 Aug 2020 19:22:33 +0200 From: Cornelia Huck To: Pierre Morel Cc: linux-kernel@vger.kernel.org, pasic@linux.ibm.com, borntraeger@de.ibm.com, frankja@linux.ibm.com, mst@redhat.com, jasowang@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: Re: [PATCH v8 2/2] s390: virtio: PV needs VIRTIO I/O device protection Message-ID: <20200818192233.6c80798e.cohuck@redhat.com> In-Reply-To: <1597762711-3550-3-git-send-email-pmorel@linux.ibm.com> References: <1597762711-3550-1-git-send-email-pmorel@linux.ibm.com> <1597762711-3550-3-git-send-email-pmorel@linux.ibm.com> Organization: Red Hat GmbH MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 18 Aug 2020 16:58:31 +0200 Pierre Morel wrote: > If protected virtualization is active on s390, the virtio queues are > not accessible to the host, unless VIRTIO_F_IOMMU_PLATFORM has been > negotiated. > Define CONFIG_ARCH_HAS_RESTRICTED_MEMORY_ACCESS and export > arch_has_restricted_memory_access to fail probe if that's > not the case, preventing a host error on access attempt. > > Signed-off-by: Pierre Morel > --- > arch/s390/Kconfig | 1 + > arch/s390/mm/init.c | 30 ++++++++++++++++++++++++++++++ > 2 files changed, 31 insertions(+) > > diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig > index 9cfd8de907cb..d4a3ef4fa27b 100644 > --- a/arch/s390/Kconfig > +++ b/arch/s390/Kconfig > @@ -820,6 +820,7 @@ menu "Virtualization" > config PROTECTED_VIRTUALIZATION_GUEST > def_bool n > prompt "Protected virtualization guest support" > + select ARCH_HAS_RESTRICTED_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 6dc7c3b60ef6..aec04d7dd089 100644 > --- a/arch/s390/mm/init.c > +++ b/arch/s390/mm/init.c > @@ -45,6 +45,7 @@ > #include > #include > #include > +#include > > pgd_t swapper_pg_dir[PTRS_PER_PGD] __section(.bss..swapper_pg_dir); > > @@ -161,6 +162,35 @@ bool force_dma_unencrypted(struct device *dev) > return is_prot_virt_guest(); > } > > +#ifdef CONFIG_ARCH_HAS_RESTRICTED_MEMORY_ACCESS > +/* > + * arch_has_restricted_memory_access > + * @dev: the VIRTIO device being added > + * > + * Return an error if required features are missing on a guest running > + * with protected virtualization. > + */ > +int arch_has_restricted_memory_access(struct virtio_device *dev) > +{ > + if (!is_prot_virt_guest()) > + return 0; If you just did a return is_prot_virt_guest(); and did the virtio feature stuff in the virtio core, this function would be short and sweet :) > + > + 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; > + } > + > + return 0; > +} > +EXPORT_SYMBOL(arch_has_restricted_memory_access); > +#endif > + > /* protected virtualization */ > static void pv_init(void) > {