linux-sgx.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: linux-sgx@vger.kernel.org
Cc: sean.j.christopherson@intel.com, serge.ayoun@intel.com,
	shay.katz-zamir@intel.com,
	Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Subject: [PATCH RESEND 10/11] x86/sgx: Free VA slot when the EWB flow fails
Date: Thu, 12 Sep 2019 20:47:19 +0100	[thread overview]
Message-ID: <20190912194720.7107-11-jarkko.sakkinen@linux.intel.com> (raw)
In-Reply-To: <20190912194720.7107-1-jarkko.sakkinen@linux.intel.com>

Call sgx_free_va_slot() when the EWB flow fails. Otherwise, they will
leak in the failure case.

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
 arch/x86/kernel/cpu/sgx/reclaim.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/cpu/sgx/reclaim.c b/arch/x86/kernel/cpu/sgx/reclaim.c
index f96f4c70f4a6..fb41141a28a7 100644
--- a/arch/x86/kernel/cpu/sgx/reclaim.c
+++ b/arch/x86/kernel/cpu/sgx/reclaim.c
@@ -341,12 +341,15 @@ static void sgx_encl_ewb(struct sgx_epc_page *epc_page,
 		}
 	}
 
-	if (ret)
+	if (ret) {
 		if (encls_failed(ret) || encls_returned_code(ret))
 			ENCLS_WARN(ret, "EWB");
 
-	encl_page->desc |= va_offset;
-	encl_page->va_page = va_page;
+		sgx_free_va_slot(va_page, va_offset);
+	} else {
+		encl_page->desc |= va_offset;
+		encl_page->va_page = va_page;
+	}
 }
 
 static void sgx_reclaimer_write(struct sgx_epc_page *epc_page)
-- 
2.20.1


  parent reply	other threads:[~2019-09-12 19:48 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-12 19:47 [PATCH RESEND 00/11] v23 updates Jarkko Sakkinen
2019-09-12 19:47 ` [PATCH RESEND 01/11] selftest/x86/sgx: Remove encl_piggy.h Jarkko Sakkinen
2019-09-12 19:47 ` [PATCH RESEND 02/11] x86/sgx: Clean up internal includes Jarkko Sakkinen
2019-09-12 19:47 ` [PATCH RESEND 03/11] x86/sgx: Write backing storage only if EWB is successful Jarkko Sakkinen
2019-09-12 19:47 ` [PATCH RESEND 04/11] x86/sgx: Rename 'j' as 'cnt' in sgx_reclaim_pages() Jarkko Sakkinen
2019-09-12 19:47 ` [PATCH RESEND 05/11] x86/sgx: Turn encls_failed() as inline function Jarkko Sakkinen
2019-09-12 19:47 ` [PATCH RESEND 06/11] x86/sgx: Move sgx_einit() to encls.c Jarkko Sakkinen
2019-09-12 19:47 ` [PATCH RESEND 07/11] x86/sgx: Remove pages in sgx_reclaimer_write() Jarkko Sakkinen
2019-09-12 19:47 ` [PATCH RESEND 08/11] x86/sgx: Calculate page index " Jarkko Sakkinen
2019-09-12 19:47 ` [PATCH RESEND 09/11] x86/sgx: Move SGX_ENCL_DEAD check to sgx_reclaimer_write() Jarkko Sakkinen
2019-09-12 19:47 ` Jarkko Sakkinen [this message]
2019-09-12 19:47 ` [PATCH RESEND 11/11] x86/sgx: Call sgx_encl_destroy() when the EWB flow fails Jarkko Sakkinen

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=20190912194720.7107-11-jarkko.sakkinen@linux.intel.com \
    --to=jarkko.sakkinen@linux.intel.com \
    --cc=linux-sgx@vger.kernel.org \
    --cc=sean.j.christopherson@intel.com \
    --cc=serge.ayoun@intel.com \
    --cc=shay.katz-zamir@intel.com \
    /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).