Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1412693pxb; Thu, 28 Jan 2021 16:19:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJytYWWEp7sKUZyIcU2F9RGRXk9lBq4hd0XZp8Ju/k5at/MsrTxqUnuqG0j8ZjmBMV8D6nBv X-Received: by 2002:a17:906:a84a:: with SMTP id dx10mr2082652ejb.13.1611879591056; Thu, 28 Jan 2021 16:19:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611879591; cv=none; d=google.com; s=arc-20160816; b=laXnnFQo/H11e6v7vP7ooBPuhhPPdxoUrXJV1f2NpiyZLhkBVAnLQzmKkbSz0qhmpE RfLW7KqU3VXyJeF/Bl8+axT3F9vXP0f/zUWKCPWlR7PJLBYrPkcOHzxQEq19EZ6JmLdS qsjbi29GXlGxwHc+0Byv9Em2cuixB3AtHYGSUKu+Iw+FtPlciRurhsItT/KODqXUPEaD HqVIsUbJbiq+U3NmifGDHuoqZGw6dzr+FQz/iMuQtgb/U3Pilm88kz0Se9CDwMXse5UU x1hRjjQrqcw8CUvR0u9pOhEHT/bhAf0q6JCrvWmJuWjKlIGw2uFQ5dHvsEgeE4N75yOI vdog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:ironport-sdr:ironport-sdr; bh=O98X5q5aQChpJ+FfKJYDsHwwR0nkVaQqSpVeWcwnrHU=; b=JR/ADDhL9kOT62yEzNuS6RTyVT7GoLUWjjkf/6+p+yKV8myY3ZPkvXvyyVJ5NdatQa M42w5jJQ0XkWuehn83WqH9EwDMP1u8eL4HJ3JLF8s86B9/fwAYmeG+bZoPzvQD4VCXPD PbvqOqkGtWiji28s2JztXeO8EUaxbafx4p/KeClD8gDwYDSkMiFqYLWBvGloZV+IuW5S Za6RFJOxd3gRmO+Qe+7V6c9WFdmVhcUCOJGBMVet9L9EFjOfT79TcaBl7Jo6V+0J4faI 72hWYK3jX52trBhA6H1anRTukmast4bd/1Jp5qo7+HkDc1z38mlmH001G85qXhujFYQS ec7w== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j19si3729941ejb.482.2021.01.28.16.19.23; Thu, 28 Jan 2021 16:19:51 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231277AbhA2APp (ORCPT + 99 others); Thu, 28 Jan 2021 19:15:45 -0500 Received: from mga03.intel.com ([134.134.136.65]:39369 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229866AbhA2APf (ORCPT ); Thu, 28 Jan 2021 19:15:35 -0500 IronPort-SDR: ++vgn3wMrvtcf5RDhxRmVE36GKCbxfDTrS0I73Pk2whwGE9ZELTVYuAe83PNFe8VLFw5ewDIU2 zjPWNgPUNbQw== X-IronPort-AV: E=McAfee;i="6000,8403,9878"; a="180415504" X-IronPort-AV: E=Sophos;i="5.79,384,1602572400"; d="scan'208";a="180415504" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jan 2021 16:15:02 -0800 IronPort-SDR: Fz142BK1BE2AIwrgc5l/F23HbilLEOABGwS6srxjHJWtE6knO29kFVQznmN0ri/rLTrhKAXXdJ uf3aidVq/yvw== X-IronPort-AV: E=Sophos;i="5.79,384,1602572400"; d="scan'208";a="354376609" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.147]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jan 2021 16:15:01 -0800 From: ira.weiny@intel.com To: Jarkko Sakkinen Cc: Ira Weiny , linux-kernel@vger.kernel.org, linux-sgx@vger.kernel.org Subject: [PATCH] x86: Remove unnecessary kmap() from sgx_ioc_enclave_init() Date: Thu, 28 Jan 2021 16:14:59 -0800 Message-Id: <20210129001459.1538805-1-ira.weiny@intel.com> X-Mailer: git-send-email 2.28.0.rc0.12.gb6a658bd00c9 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ira Weiny There is no reason to alloc a page and kmap it to store this temporary data from the user. This is especially true when we are trying to remove kmap usages. Also placing the token pointer 1/2 way into the page is fragile. Replace this allocation with two kzalloc()'s which also removes the need for the memset(). Signed-off-by: Ira Weiny --- arch/x86/kernel/cpu/sgx/ioctl.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/arch/x86/kernel/cpu/sgx/ioctl.c b/arch/x86/kernel/cpu/sgx/ioctl.c index 90a5caf76939..9c9019760585 100644 --- a/arch/x86/kernel/cpu/sgx/ioctl.c +++ b/arch/x86/kernel/cpu/sgx/ioctl.c @@ -604,7 +604,6 @@ static long sgx_ioc_enclave_init(struct sgx_encl *encl, void __user *arg) { struct sgx_sigstruct *sigstruct; struct sgx_enclave_init init_arg; - struct page *initp_page; void *token; int ret; @@ -615,13 +614,15 @@ static long sgx_ioc_enclave_init(struct sgx_encl *encl, void __user *arg) if (copy_from_user(&init_arg, arg, sizeof(init_arg))) return -EFAULT; - initp_page = alloc_page(GFP_KERNEL); - if (!initp_page) + sigstruct = kzalloc(sizeof(*sigstruct), GFP_KERNEL); + if (!sigstruct) return -ENOMEM; - sigstruct = kmap(initp_page); - token = (void *)((unsigned long)sigstruct + PAGE_SIZE / 2); - memset(token, 0, SGX_LAUNCH_TOKEN_SIZE); + token = kzalloc(SGX_LAUNCH_TOKEN_SIZE, GFP_KERNEL); + if (!token) { + ret = -ENOMEM; + goto free_sigstruct; + } if (copy_from_user(sigstruct, (void __user *)init_arg.sigstruct, sizeof(*sigstruct))) { @@ -645,8 +646,9 @@ static long sgx_ioc_enclave_init(struct sgx_encl *encl, void __user *arg) ret = sgx_encl_init(encl, sigstruct, token); out: - kunmap(initp_page); - __free_page(initp_page); + kfree(token); +free_sigstruct: + kfree(sigstruct); return ret; } -- 2.28.0.rc0.12.gb6a658bd00c9