From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CEA02C433F5 for ; Sun, 2 Oct 2022 00:46:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 30E7F8D0003; Sat, 1 Oct 2022 20:46:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2BD698D0001; Sat, 1 Oct 2022 20:46:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 184E78D0003; Sat, 1 Oct 2022 20:46:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 0532A8D0001 for ; Sat, 1 Oct 2022 20:46:55 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id BB29C1604D7 for ; Sun, 2 Oct 2022 00:46:54 +0000 (UTC) X-FDA: 79974169548.07.307E0D2 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) by imf16.hostedemail.com (Postfix) with ESMTP id E816A18000F for ; Sun, 2 Oct 2022 00:46:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Gv2YDk3wxAsM+5p/ZBBVyhFLL1BUSQ3HyXzRKnGGrEc=; b=FnKwGfG2xXw4ocWfZMTeVdtmYG 9V8riq5kooZ10uSNGvJEL3wEe+RqTgIQxoM5ERPH32yo0ovp15w2++1q6bdEP78csVtx++ZYT7M70 /XeVtyp2j2u65FyoCUHCHB7bFTvYlSs0iTBcAQj8PPrrsQ+3U/mlEjCO+Grv2PgCu9CBBiix48IoS c6HDlm0FwPqXwKd4558daO9fA62Fy7OuMFV/TbPXD+60s6RzhcsehSfmiv8wSsMs77FxKUszGGmXV 1Y/H1AYgdwOTtHx73zMLJcuVGhXh3xRy7FD2CmvL6xpCef4O8SmycjvdajjIjfzxGX6ecctz8ueGr Dsr7gTEw==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1oen7x-005osN-1u; Sun, 02 Oct 2022 00:46:41 +0000 Date: Sun, 2 Oct 2022 01:46:41 +0100 From: Al Viro To: ira.weiny@intel.com Cc: Jens Wiklander , Sumit Garg , Andrew Morton , "Fabio M. De Francesco" , Christoph Hellwig , Linus Torvalds , op-tee@lists.trustedfirmware.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH 3/4] tee: Remove call to get_kernel_pages() Message-ID: References: <20221002002326.946620-1-ira.weiny@intel.com> <20221002002326.946620-4-ira.weiny@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221002002326.946620-4-ira.weiny@intel.com> ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664671614; a=rsa-sha256; cv=none; b=UiK0oilIIirTaAd4dxNOQYzmqCqBqRGRhZoDWZuhhTLAynSZondKQe2Z6mUVxRcMNAyfKg Diz8Dn8KLJh5QKQjQNp0pWa6yOC1OBKnk/YpQp8tHwV6uFEeaG7Ir8pFE+IET3wJlmrFrN LRPX3YH/4S3VwKrMsCO3BoNzOwis87U= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=linux.org.uk header.s=zeniv-20220401 header.b=FnKwGfG2; spf=none (imf16.hostedemail.com: domain of viro@ftp.linux.org.uk has no SPF policy when checking 62.89.141.173) smtp.mailfrom=viro@ftp.linux.org.uk; dmarc=pass (policy=none) header.from=zeniv.linux.org.uk ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664671614; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Gv2YDk3wxAsM+5p/ZBBVyhFLL1BUSQ3HyXzRKnGGrEc=; b=KUfCkYCQyfDOZS+r5x8RlGWfPPNyG4/nPZE29SAfhiAeICM4AyFLdSd81wjsnLFDG3uHKE C64Ib4Dzs9r1jQIt10MiZvr2JbBfUozrJgrK2tvkvr06pdAs04L1OQssQ3L04xYktiehtf MWEFJs8Ydm1hekF3WnQrOa8SiP2Lik8= X-Stat-Signature: jun1xw4fgw4odu7ukajw8ojo6s9z5a4n X-Rspamd-Queue-Id: E816A18000F Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=linux.org.uk header.s=zeniv-20220401 header.b=FnKwGfG2; spf=none (imf16.hostedemail.com: domain of viro@ftp.linux.org.uk has no SPF policy when checking 62.89.141.173) smtp.mailfrom=viro@ftp.linux.org.uk; dmarc=pass (policy=none) header.from=zeniv.linux.org.uk X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1664671613-256492 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Sat, Oct 01, 2022 at 05:23:25PM -0700, ira.weiny@intel.com wrote: > kiov = kcalloc(page_count, sizeof(*kiov), GFP_KERNEL); > @@ -38,12 +39,12 @@ static int shm_get_kernel_pages(unsigned long start, size_t page_count, > for (n = 0; n < page_count; n++) { > kiov[n].iov_base = (void *)(start + n * PAGE_SIZE); > kiov[n].iov_len = PAGE_SIZE; > + pages[n] = virt_to_page(kiov[n].iov_base); > + get_page(pages[n]); > } > - > - rc = get_kernel_pages(kiov, page_count, 0, pages); > kfree(kiov); IDGI. The only thing in kiov[...] you are every reading is ->iov_base. And you fetch it once, right after the assignment. Why bother with allocating the array at all? pages[n] = virt_to_page((void *)start + n * PAGE_SIZE); would do just as well, not to mention the fact that since you reject vmalloc and kmap, you might simply do page = virt_to_page(start); for (int n = 0; n < page_count; n++) get_page(pages[n] = page + n); instead...