From patchwork Wed Jun 19 12:21:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 11004025 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 65C231986 for ; Wed, 19 Jun 2019 12:21:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5490328767 for ; Wed, 19 Jun 2019 12:21:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4840C2882F; Wed, 19 Jun 2019 12:21:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E5FBB287CC for ; Wed, 19 Jun 2019 12:21:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727244AbfFSMVy (ORCPT ); Wed, 19 Jun 2019 08:21:54 -0400 Received: from mga01.intel.com ([192.55.52.88]:19557 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727134AbfFSMVy (ORCPT ); Wed, 19 Jun 2019 08:21:54 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Jun 2019 05:21:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,392,1557212400"; d="scan'208";a="358597345" Received: from stephanf-mobl2.ger.corp.intel.com (HELO localhost) ([10.252.34.117]) by fmsmga006.fm.intel.com with ESMTP; 19 Jun 2019 05:21:50 -0700 From: Jarkko Sakkinen To: sean.j.christopherson@intel.com Cc: linux-sgx@vger.kernel.org, Jarkko Sakkinen Subject: [PATCH] x86/sgx: rip off the refcount from sgx_encl_add_page flow Date: Wed, 19 Jun 2019 15:21:43 +0300 Message-Id: <20190619122143.12028-1-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-sgx-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sgx@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP With the file bound approach we can flush the work queue when the file is closed. Signed-off-by: Jarkko Sakkinen --- arch/x86/kernel/cpu/sgx/driver/ioctl.c | 3 +-- arch/x86/kernel/cpu/sgx/driver/main.c | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/cpu/sgx/driver/ioctl.c b/arch/x86/kernel/cpu/sgx/driver/ioctl.c index d17c60dca114..f56d3c712dc4 100644 --- a/arch/x86/kernel/cpu/sgx/driver/ioctl.c +++ b/arch/x86/kernel/cpu/sgx/driver/ioctl.c @@ -172,7 +172,7 @@ static void sgx_add_page_worker(struct work_struct *work) next: kfree(req); - } while (!kref_put(&encl->refcount, sgx_encl_release) && !is_empty); + } while (!is_empty); } static u32 sgx_calc_ssaframesize(u32 miscselect, u64 xfrm) @@ -520,7 +520,6 @@ static int __sgx_encl_add_page(struct sgx_encl *encl, req->encl_page = encl_page; req->mrmask = mrmask; empty = list_empty(&encl->add_page_reqs); - kref_get(&encl->refcount); list_add_tail(&req->list, &encl->add_page_reqs); if (empty) queue_work(sgx_encl_wq, &encl->work); diff --git a/arch/x86/kernel/cpu/sgx/driver/main.c b/arch/x86/kernel/cpu/sgx/driver/main.c index 0c831ee5e2de..9ea082372682 100644 --- a/arch/x86/kernel/cpu/sgx/driver/main.c +++ b/arch/x86/kernel/cpu/sgx/driver/main.c @@ -47,6 +47,7 @@ static int sgx_release(struct inode *inode, struct file *file) { struct sgx_encl *encl = file->private_data; + flush_work(&encl->work); kref_put(&encl->refcount, sgx_encl_release); return 0;