iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Thiago Jung Bauermann <bauerman@linux.ibm.com>
To: linuxppc-dev@lists.ozlabs.org
Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org,
	Alexey Kardashevskiy <aik@ozlabs.ru>,
	Anshuman Khandual <anshuman.linux@gmail.com>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Christoph Hellwig <hch@lst.de>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Mike Anderson <andmike@linux.ibm.com>,
	Paul Mackerras <paulus@samba.org>, Ram Pai <linuxram@us.ibm.com>,
	Anshuman Khandual <khandual@linux.vnet.ibm.com>,
	Thiago Jung Bauermann <bauerman@linux.ibm.com>
Subject: [RFC PATCH 07/11] powerpc/svm: Use shared memory for Debug Trace Log (DTL)
Date: Fri, 24 Aug 2018 13:25:31 -0300	[thread overview]
Message-ID: <20180824162535.22798-8-bauerman@linux.ibm.com> (raw)
In-Reply-To: <20180824162535.22798-1-bauerman@linux.ibm.com>

From: Anshuman Khandual <khandual@linux.vnet.ibm.com>

On Ultravisor platform kmem_cache for DTL buffers must use a constructor
function which converts the underlying buddy allocated SLUB cache pages
into shared memory so that they are accessible to the hypervisor.

Signed-off-by: Anshuman Khandual <khandual@linux.vnet.ibm.com>
Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>
---
 arch/powerpc/include/asm/svm.h         |  1 +
 arch/powerpc/kernel/svm.c              | 30 ++++++++++++++++++++++++++++++
 arch/powerpc/platforms/pseries/setup.c |  5 ++++-
 3 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/include/asm/svm.h b/arch/powerpc/include/asm/svm.h
index 95d69e472e52..e00688761704 100644
--- a/arch/powerpc/include/asm/svm.h
+++ b/arch/powerpc/include/asm/svm.h
@@ -16,6 +16,7 @@ static bool is_svm_platform(void)
 
 extern void mem_convert_shared(unsigned long pfn, unsigned long npages);
 extern void mem_convert_secure(unsigned long pfn, unsigned long npages);
+extern void dtl_cache_ctor(void *addr);
 #else
 static inline bool is_svm_platform(void)
 {
diff --git a/arch/powerpc/kernel/svm.c b/arch/powerpc/kernel/svm.c
index 891db2de8c04..1af5caa955f5 100644
--- a/arch/powerpc/kernel/svm.c
+++ b/arch/powerpc/kernel/svm.c
@@ -66,3 +66,33 @@ int set_memory_decrypted(unsigned long addr, int numpages)
 
 	return 0;
 }
+
+/* There's one dispatch log per CPU. */
+#define NR_DTL_PAGE (DISPATCH_LOG_BYTES * CONFIG_NR_CPUS / PAGE_SIZE)
+
+static struct page *dtl_page_store[NR_DTL_PAGE];
+static long dtl_nr_pages;
+
+static bool is_dtl_page_shared(struct page *page)
+{
+	long i;
+
+	for (i = 0; i < dtl_nr_pages; i++)
+		if (dtl_page_store[i] == page)
+			return true;
+
+	return false;
+}
+
+void dtl_cache_ctor(void *addr)
+{
+	unsigned long pfn = PHYS_PFN(__pa(addr));
+	struct page *page = pfn_to_page(pfn);
+
+	if (!is_dtl_page_shared(page)) {
+		dtl_page_store[dtl_nr_pages] = page;
+		dtl_nr_pages++;
+		WARN_ON(dtl_nr_pages >= NR_DTL_PAGE);
+		mem_convert_shared(pfn, PAGE_SIZE);
+	}
+}
diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index 139f0af6c3d9..50ba77c802d2 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -69,6 +69,7 @@
 #include <asm/kexec.h>
 #include <asm/isa-bridge.h>
 #include <asm/security_features.h>
+#include <asm/svm.h>
 
 #include "pseries.h"
 
@@ -288,8 +289,10 @@ static inline int alloc_dispatch_logs(void)
 
 static int alloc_dispatch_log_kmem_cache(void)
 {
+	void (*ctor)(void *) = is_svm_platform() ? dtl_cache_ctor : NULL;
+
 	dtl_cache = kmem_cache_create("dtl", DISPATCH_LOG_BYTES,
-						DISPATCH_LOG_BYTES, 0, NULL);
+						DISPATCH_LOG_BYTES, 0, ctor);
 	if (!dtl_cache) {
 		pr_warn("Failed to create dispatch trace log buffer cache\n");
 		pr_warn("Stolen time statistics will be unreliable\n");

  parent reply	other threads:[~2018-08-24 16:25 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-24 16:25 [RFC PATCH 00/11] Secure Virtual Machine Enablement Thiago Jung Bauermann
2018-08-24 16:25 ` [RFC PATCH 01/11] powerpc/svm: Detect Secure Virtual Machine (SVM) platform Thiago Jung Bauermann
2018-08-24 16:25 ` [RFC PATCH 02/11] powerpc/svm: Select CONFIG_DMA_DIRECT_OPS and CONFIG_SWIOTLB Thiago Jung Bauermann
2018-08-24 16:25 ` [RFC PATCH 03/11] powerpc/svm: Add memory conversion (shared/secure) helper functions Thiago Jung Bauermann
2018-08-24 16:25 ` [RFC PATCH 04/11] powerpc/svm: Convert SWIOTLB buffers to shared memory Thiago Jung Bauermann
2018-08-24 16:25 ` [RFC PATCH 05/11] powerpc/svm: Don't release SWIOTLB buffers on secure guests Thiago Jung Bauermann
2018-08-24 16:25 ` [RFC PATCH 06/11] powerpc/svm: Use SWIOTLB DMA API for all virtio devices Thiago Jung Bauermann
2018-08-24 16:25 ` Thiago Jung Bauermann [this message]
2018-08-24 16:25 ` [RFC PATCH 08/11] powerpc: Add and use LPPACA_SIZE constant Thiago Jung Bauermann
2018-08-24 16:25 ` [RFC PATCH 09/11] powerpc/svm: Use shared memory for LPPACA structures Thiago Jung Bauermann
2018-08-24 16:25 ` [RFC PATCH 10/11] powerpc/svm: Force the use of bounce buffers Thiago Jung Bauermann
2018-08-24 16:25 ` [RFC PATCH 11/11] powerpc/svm: Increase SWIOTLB buffer size Thiago Jung Bauermann
2018-08-24 17:16   ` Randy Dunlap
     [not found]     ` <45561478-ee75-ee62-52d6-a96d60132669-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2018-08-25  0:38       ` Thiago Jung Bauermann
2018-08-27 18:18   ` Konrad Rzeszutek Wilk
2018-08-24 16:33 ` [RFC PATCH 00/11] Secure Virtual Machine Enablement Christoph Hellwig
2018-08-24 18:16   ` Ram Pai
2019-09-04  2:48 ` Sukadev Bhattiprolu
  -- strict thread matches above, loose matches on Subject: below --
2018-08-24  2:59 Thiago Jung Bauermann
2018-08-24  2:59 ` [RFC PATCH 07/11] powerpc/svm: Use shared memory for Debug Trace Log (DTL) Thiago Jung Bauermann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180824162535.22798-8-bauerman@linux.ibm.com \
    --to=bauerman@linux.ibm.com \
    --cc=aik@ozlabs.ru \
    --cc=andmike@linux.ibm.com \
    --cc=anshuman.linux@gmail.com \
    --cc=benh@kernel.crashing.org \
    --cc=hch@lst.de \
    --cc=iommu@lists.linux-foundation.org \
    --cc=khandual@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=linuxram@us.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=paulus@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).