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 ABA93C48260 for ; Tue, 13 Feb 2024 17:26:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C499D6B0071; Tue, 13 Feb 2024 12:26:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BD1C76B0078; Tue, 13 Feb 2024 12:26:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A4D316B007B; Tue, 13 Feb 2024 12:26:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 8EB836B0071 for ; Tue, 13 Feb 2024 12:26:37 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 52CED406AB for ; Tue, 13 Feb 2024 17:26:37 +0000 (UTC) X-FDA: 81787460034.23.61D48B6 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf14.hostedemail.com (Postfix) with ESMTP id 269BA100010 for ; Tue, 13 Feb 2024 17:26:34 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf14.hostedemail.com: domain of robin.murphy@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=robin.murphy@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707845195; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wnUaiL+S/TCLxGOc7B3fB9mlJyMhPr7D1UGJljdwcjQ=; b=ftunPRptZfXcDGJPPF3W181oj1oy9Vvkhqf08ipF4yLDwp+xZEvdvexplwZ0QnLMH1qKxR IRzjrsrh449RLrgwcSmZ1eN26z8vkuAvjjm3bTFyGDTHW0igGwPdBxwocfD213aDlIknCQ eEYX5Pf2GrOW6vN1+qDj1YSlquKzTWs= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf14.hostedemail.com: domain of robin.murphy@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=robin.murphy@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707845195; a=rsa-sha256; cv=none; b=LS08aUNrZr4bJRngbZEBQDclIR6pN385Dt0yE3EcMZihsgi9TU6W4Jqlvd94wKZ3YgYr4o 6qMofCh3uMuU9H5sk9lQcP2c92QL0IuJnvyvaJRPMxJYvbP5m3mk4vBD88m5YqnTCrf7ef /ho2uO6wjSXcjXOvcjedImfrY+iskTE= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 724E71FB; Tue, 13 Feb 2024 09:27:15 -0800 (PST) Received: from [10.1.196.40] (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 155943F5A1; Tue, 13 Feb 2024 09:26:27 -0800 (PST) Message-ID: Date: Tue, 13 Feb 2024 17:26:26 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 01/10] iommu/vt-d: add wrapper functions for page allocations Content-Language: en-GB To: Pasha Tatashin Cc: akpm@linux-foundation.org, alim.akhtar@samsung.com, alyssa@rosenzweig.io, asahi@lists.linux.dev, baolu.lu@linux.intel.com, bhelgaas@google.com, cgroups@vger.kernel.org, corbet@lwn.net, david@redhat.com, dwmw2@infradead.org, hannes@cmpxchg.org, heiko@sntech.de, iommu@lists.linux.dev, jernej.skrabec@gmail.com, jonathanh@nvidia.com, joro@8bytes.org, krzysztof.kozlowski@linaro.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-rockchip@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, lizefan.x@bytedance.com, marcan@marcan.st, mhiramat@kernel.org, m.szyprowski@samsung.com, paulmck@kernel.org, rdunlap@infradead.org, samuel@sholland.org, suravee.suthikulpanit@amd.com, sven@svenpeter.dev, thierry.reding@gmail.com, tj@kernel.org, tomas.mudrunka@gmail.com, vdumpa@nvidia.com, wens@csie.org, will@kernel.org, yu-cheng.yu@intel.com, rientjes@google.com, bagasdotme@gmail.com, mkoutny@suse.com References: <20240207174102.1486130-1-pasha.tatashin@soleen.com> <20240207174102.1486130-2-pasha.tatashin@soleen.com> <8ce2cd7b-7702-45aa-b4c8-25a01c27ed83@arm.com> From: Robin Murphy In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 269BA100010 X-Stat-Signature: 4spfe6ng37o9txcgsq1be4faf5k5gfdh X-Rspam-User: X-HE-Tag: 1707845194-588243 X-HE-Meta: U2FsdGVkX19syu8JKaC2PslA714AUzwvGPhCek/dcdzSnZ6aU8XwFMOL8lG97QZBgGinSjvxEEaVmT1r36nsMb0HCYueCXZPf03H4y7NUmAlzKi9OsNQCmxaIrbEDljy7c2rqti9TOugBK7vcTOD8X4LJRoY0/CYVeTjlqC0eW0IPlUn+d+0n9YYqMUKZu2RdrwLOOofJRSHncS9H878Ayh7Zl10DMj1ETBpnt2SOLFII9UR3NpRHbkLeqYQ842EEW18Jaoa9xt/W+F5G1yxo0+mjWXAV5hBPMxnv8n6nJz9EuXQMo9YmcFMwrrJtvopE5GHf9mVWYJ8ADxM32nNWJSY5FMmU1GA7JwUBcfTBbjDGdzt8mqohBuooxw42DzkLF/Mqac7KOrQxRLFAAj7tK1f20gV2sgBw+HeKqD5u7IUFoQbw3im0YVICqnFTB5Z5guuIU2HWE95gndXN/Ow0OkNKJ35tW5/7BN1iosztqOEiYIWo8nWYHxsohIbGWN/T3w+YbUzlqHeyeG6bwtuU4722RWCmi+MD7QyPEDCXEAfM+2hh+v6iffWWJYQlSl3NIA4gQRK5rqfhDRYh160ZlUTk/AXp9Gx9TR6isD6wsEmH/CViqiCQXA1sLMEgOwJzcILYeb5cZeClOab8+Y5RXEj2YBKqz1EQgIOh4RTP8rOJiLBIwK0lZbbyHw2ntjW2Sm3BF5MJS9kRnukMCyaJK5rHRStcWiwDlhTLlqjHfsV54lRHtGHxJATs8xSOxfIXrAGhKEL88fKKJH9uRyDYR02kFIHwdu2lIl1zPV+cjgRk84twn36UWYsvzWhtQGkkRdFCLbnJV3ajG+Ae+2I7zu0JLff37SNTezTdaPSWcMDMIubqpboLne7DhMyQOqvBsqxFeM+0F7PPZkwLKqTAptiVBNz9hDDPsDPkq7FEcWdeX947uF9wOLj/16U6tdFwWRxtqf/f4If9QSyeZq MS4CGTMR htJq4AslnWcjB8sX6lMWBDdKQfVfgNoMOMOq0OslCriuxhfv/4kj5JKw6HOq9rRsUYunizGXdyQfgH5+ASaatFP9ba0ruhxqETiPZAv9WkfdnyyTPYFfojhDQPHgp2+l0i46N/mad67rA+PAG/DehEuOtu54NT1ivFr7YOFavFrLRGzBY1k5axyGE0B3TwsDojeN2cJExtCxJ4Mr0bUFHUHHNLlV3M42+jzr6 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: List-Subscribe: List-Unsubscribe: On 10/02/2024 2:21 am, Pasha Tatashin wrote: [...] >>> +/** >>> + * iommu_alloc_pages_node - allocate a zeroed page of a given order from >>> + * specific NUMA node. >>> + * @nid: memory NUMA node id >>> + * @gfp: buddy allocator flags >>> + * @order: page order >>> + * >>> + * returns the virtual address of the allocated page >>> + */ >>> +static inline void *iommu_alloc_pages_node(int nid, gfp_t gfp, int order) >>> +{ >>> + struct page *page = __iommu_alloc_pages_node(nid, gfp, order); >>> + >>> + if (unlikely(!page)) >>> + return NULL; >> >> As a general point I'd prefer to fold these checks into the accounting >> function itself rather than repeat them all over. > > For the free functions this saves a few cycles by not repeating this > check again inside __free_pages(), to keep things symmetrical it makes > sense to keep __iomu_free_account and __iomu_alloc_account the same. > With the other clean-up there are not that many of these checks left. __free_pages() doesn't accept NULL, so __iommu_free_pages() shouldn't need a check; free_pages() does, but correspondingly iommu_free_pages() needs its own check up-front to avoid virt_to_page(NULL); either way it means there are no callers of iommu_free_account() who should be passing NULL. The VA-returning allocators of course need to avoid page_address(NULL), so I clearly made this comment in the wrong place to begin with, oops. In the end I guess that will leave __iommu_alloc_pages() as the only caller of iommu_alloc_account() who doesn't already need to handle their own NULL. OK, I'm convinced, apologies for having to bounce it off you to work it through :) >>> + */ >>> +static inline void *iommu_alloc_page_node(int nid, gfp_t gfp) >>> +{ >>> + return iommu_alloc_pages_node(nid, gfp, 0); >>> +} >> >> TBH I'm not entirely convinced that saving 4 characters per invocation >> times 11 invocations makes this wrapper worthwhile :/ > > Let's keep them. After the clean-up that you suggested, there are > fewer functions left in this file, but I think that it is cleaner to > keep these remaining, as it is beneficial to easily distinguish when > exactly one page is allocated vs when multiple are allocated via code > search. But is it, really? It's not at all obvious to me *why* it would be significantly interesting to distinguish fixed order-0 allocations from higher-order or variable-order (which may still be 0) ones. After all, there's no regular alloc_page_node() wrapper, yet plenty more callers of alloc_pages_node(..., 0) :/ Thanks, Robin.