Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp777818ybx; Thu, 7 Nov 2019 02:33:53 -0800 (PST) X-Google-Smtp-Source: APXvYqwngVQQhkbyt9qGrwBlX2htwRfhsOw/MDjoAWnqusxrKS+U2sas9KVLrhxPb1ongSKqTinb X-Received: by 2002:a17:906:351b:: with SMTP id r27mr2281369eja.120.1573122833168; Thu, 07 Nov 2019 02:33:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573122833; cv=none; d=google.com; s=arc-20160816; b=Vi6FWeYi2HJK7Y7lIML3ysivBRKLtzjIw45KFED7rOBVxNnPWL/D2hkzRZtBvRI9k1 liMFH6PDwByQfHi/jPXeuHS283wM449gNDdAbgYQphpUAbR33tOlxmSIEDuX6OHGi//V NaE7RntQrM0gAYtI/Wnf8/QBa2VCGCOXajGRJUdYj/wqF+3vUuWptNjdreuqeNwM9ujm DyBRuPXEE+UjqtA6aCuD4OeGhhtOSFU3M58/NAdn1CELiMcNk9y9cHQ3Y1RWQjfrwuln Lg0VK98ZPxRlvS9/ZlA50UlNXQcfk9jsyys1Kn4WTj9xJzICvDT4HgGqsAJGZFN3AqQB 9h1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=FWx/GSc1ePBsvjVEve9iRFSqSLc6zKS9PLhhNN8+n6k=; b=Qi4f9At3+4U2L/r/1nfEYj8s3HbP23wxJq/px8RdBBU8Zyt+hflgcU/5YHAz/loUN1 O3Lrs1rBPrag50hhc6SrmDfe7hPTOAAYKmCfvaAjTjxftsflZHP6AjDgg6AMvCCiT28H anj9+Yu5mHM/QtIDxsWnEZvFsejAYf9LgQZvnghECqMybTG74jLuXquDUiH0dWwa0CHk soGFKGWMiRxCG/4A6JssmsKHY+wd5/fQjC5s4Xg5X7tN5DTgvpiK7Za+m45Xh86pJYIa 14ncU8+oPwy7O2QoGWbWY1ETI/SxGlTLVnm5x2UUL1xUvlSLWqfkb0q6MkHJkV2vCGAS Zg1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b="Ez26eB0/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q4si1093194ejb.136.2019.11.07.02.33.29; Thu, 07 Nov 2019 02:33:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b="Ez26eB0/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387725AbfKGK36 (ORCPT + 99 others); Thu, 7 Nov 2019 05:29:58 -0500 Received: from bilbo.ozlabs.org ([203.11.71.1]:41817 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726866AbfKGK36 (ORCPT ); Thu, 7 Nov 2019 05:29:58 -0500 Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 47805b3GX7z9sPT; Thu, 7 Nov 2019 21:29:55 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ellerman.id.au; s=201909; t=1573122595; bh=a4m1nWotTG2jewKpNRdw9eW8MeOxKL/KXr8bS4jNwEw=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=Ez26eB0/Hao264oY8mdCEcLSGzesBH8ckKBuWVZsrTh7FwY+3G0FRpQcMW8t07TIL GxNEm5xTZqeXEz/Oge1/J59c/E03qxZuVJKwy5G52tt5n75byMSGD078yUa5X+WFeU jDJXX5hY6t9FhEANapoy+TL4hGXNpYWoe7eiypzProrFH+5clfz5BLdQgJOdh6jWTp uShCQT5qGdJROGj3Yv4OrneWx0IRvISROWJ7LC0GVYLQ/sqZiVa6FkMAFyCIW2DdVN /tk6hZpqkJw9/rPKaKSxObLxRbuQ7EDWVWPouPRR6KrI63QH1o8ucesuGyBhHK//Z0 8Yqlq6lO/s81g== From: Michael Ellerman To: Ram Pai , linuxppc-dev@lists.ozlabs.org Cc: benh@kernel.crashing.org, david@gibson.dropbear.id.au, paulus@ozlabs.org, mdroth@linux.vnet.ibm.com, hch@lst.de, linuxram@us.ibm.com, andmike@us.ibm.com, sukadev@linux.vnet.ibm.com, mst@redhat.com, ram.n.pai@gmail.com, aik@ozlabs.ru, cai@lca.pw, tglx@linutronix.de, bauerman@linux.ibm.com, linux-kernel@vger.kernel.org Subject: Re: [RFC v1 1/2] powerpc/pseries/iommu: Share the per-cpu TCE page with the hypervisor. In-Reply-To: <1572902923-8096-2-git-send-email-linuxram@us.ibm.com> References: <1572902923-8096-1-git-send-email-linuxram@us.ibm.com> <1572902923-8096-2-git-send-email-linuxram@us.ibm.com> Date: Thu, 07 Nov 2019 21:29:54 +1100 Message-ID: <87h83g568t.fsf@mpe.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Ram Pai writes: > The hypervisor needs to access the contents of the page holding the TCE > entries while setting up the TCE entries in the IOMMU's TCE table. For > SecureVMs, since this page is encrypted, the hypervisor cannot access > valid entries. Share the page with the hypervisor. This ensures that the > hypervisor sees the valid entries. Can you please give people some explanation of why this is safe. After all the point of the Ultravisor is to protect the guest from a malicious hypervisor. Giving the hypervisor access to a page of TCEs sounds dangerous, so please explain why it's not. cheers > diff --git a/arch/powerpc/platforms/pseries/iommu.c b/arch/powerpc/platforms/pseries/iommu.c > index 8d9c2b1..07f0847 100644 > --- a/arch/powerpc/platforms/pseries/iommu.c > +++ b/arch/powerpc/platforms/pseries/iommu.c > @@ -37,6 +37,7 @@ > #include > #include > #include > +#include > > #include "pseries.h" > > @@ -179,6 +180,19 @@ static int tce_build_pSeriesLP(struct iommu_table *tbl, long tcenum, > > static DEFINE_PER_CPU(__be64 *, tce_page); > > +/* > + * Allocate a tce page. If secure VM, share the page with the hypervisor. > + */ > +static __be64 *alloc_tce_page(void) > +{ > + __be64 *tcep = (__be64 *)__get_free_page(GFP_ATOMIC); > + > + if (tcep && is_secure_guest()) > + uv_share_page(PHYS_PFN(__pa(tcep)), 1); > + > + return tcep; > +} > + > static int tce_buildmulti_pSeriesLP(struct iommu_table *tbl, long tcenum, > long npages, unsigned long uaddr, > enum dma_data_direction direction, > @@ -206,8 +220,7 @@ static int tce_buildmulti_pSeriesLP(struct iommu_table *tbl, long tcenum, > * from iommu_alloc{,_sg}() > */ > if (!tcep) { > - tcep = (__be64 *)__get_free_page(GFP_ATOMIC); > - /* If allocation fails, fall back to the loop implementation */ > + tcep = alloc_tce_page(); > if (!tcep) { > local_irq_restore(flags); > return tce_build_pSeriesLP(tbl, tcenum, npages, uaddr, > @@ -391,6 +404,7 @@ static int tce_clearrange_multi_pSeriesLP(unsigned long start_pfn, > return rc; > } > > + > static int tce_setrange_multi_pSeriesLP(unsigned long start_pfn, > unsigned long num_pfn, const void *arg) > { > @@ -405,7 +419,7 @@ static int tce_setrange_multi_pSeriesLP(unsigned long start_pfn, > tcep = __this_cpu_read(tce_page); > > if (!tcep) { > - tcep = (__be64 *)__get_free_page(GFP_ATOMIC); > + tcep = alloc_tce_page(); > if (!tcep) { > local_irq_enable(); > return -ENOMEM; > -- > 1.8.3.1