From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795431936; b=u4z7tDO/kLlZ8PcC88IDK3prqVacaZd3asz0wuXINBwTZi898yVwroF5cx2E0nD4HHDy T3tzRKwoHOhtZA564B/JX+Z04vv8r4tqly+9i9PtE6zWBbjLrwslM1lvVDZ0nVRnadxZ6 ayrPm/KODNn5M6csQwZ5/8z4gMfz2z5ZgvGzvQFoItqY2pv+osUSin/XIyHwDYbYvyuGF S7SIXhxdqXJ6POAa1lENlLbcpR8H0RGVX3WQYrtyurWzTrjWMEboZK9N0s56t4kPOcOyW UZYdiEutbRDXtceqxlmHONdSCb5HlLGy5Cy7B8kbdilyAJOqVMlsfC34S4Ob7A8Tx0g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795431936; h=DMARC-Filter:Received:Received:DKIM-Signature:Date:From:To:Cc: Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; bh=y+pXRncvtOc4nB9TtW4KG6FLyRulzoczl3trVZwKBJI=; b=HwwKIWoYn3QUB81FgioexWHnriWyFNssCRPyly0QN66siWWc4SWXLpXa86//4I25B2Yq coZtnGx8+Lu8NYeZCf89B2Z7VzIMq3TuiOWw7rorVDqVdF0dK9v3ODNnuaF0rme66WEbU 9EEORIOPuqG07VDPXmQ8ct50YT5xIkaIxsTv/BIZ8bQZzw+EH3TLDsv5cD2H5emXNupPT yt2arhY6Dpurmw6i2YVzxEojSn/8JokkQEqoCLj1DiBC7o0eaqvn+/ZZ+peGdRum9zBcT In9aJYcm2NnSJs5mClbBFJyN4NNyBvYRgqfjxJca4gOod9vQr0cOyoSsgLORLuJv1bw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=KvhrT8NK; arc=none smtp.remote-ip=217.140.110.172 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B071D606A31F for ; Mon, 23 Nov 2026 11:05:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B071D606A31F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=KvhrT8NK 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 24EEA1476; Mon, 23 Nov 2026 03:05:32 -0800 (PST) Received: from arm.com (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A83273F882; Mon, 23 Nov 2026 03:05:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1795431935; bh=kCUeWgNlDSox1V+xXIV0FoQklIwe01iQtQShkTSpFns=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=KvhrT8NKkwfUQlN/JVYJ5xdBVy5POFXKjhsTfodMnif/DZoxUXBTRSE+v99DKNllE 5d1fBxUVR51g74P9by/+O7T3jZUmuCzToT2ynvCd+snaLJQPIjfE7jA9gHVgHouzT3 DFYSeENRGheUkSn0CCeE9f0MsFw+W0BZ+uXNA9WQ= Date: Mon, 23 Nov 2026 11:05:23 +0000 From: Catalin Marinas To: "Aneesh Kumar K.V (Arm)" Cc: linux-coco@lists.linux.dev, Andrew Morton , Baoquan He , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Christian =?iso-8859-1?Q?K=F6nig?= , Jason Gunthorpe , Joerg Roedel , Marc Zyngier , Marek Szyprowski , Robin Murphy , Steven Price , Sumit Semwal , Suzuki K Poulose , Thomas Gleixner , Will Deacon , Russell King , Benjamin Gaignard , Brian Starkey , John Stultz , Mark Rutland , Radu Rendec , "T.J. Mercier" , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Ritesh Harjani , Shrikanth Hegde , Alexander Gordeev , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Sven Schnelle , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , Kiryl Shutsemau , Rick Edgecombe , "K . Y . Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Paolo Bonzini , Vitaly Kuznetsov , Andy Lutomirski , Peter Zijlstra , dri-devel@lists.freedesktop.org, iommu@lists.linux.dev, linaro-mm-sig@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org, linux-mm@kvack.org, kvmarm@lists.linux.dev, patches@lists.linux.dev Subject: Re: [PATCH v10 04/13] irqchip/gic-v3-its: Allocate shared tables using CoCo shared memory allocator Message-ID: References: <20261116091137.94252-1-aneesh.kumar@kernel.org> <20261116091137.94252-5-aneesh.kumar@kernel.org> X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261116091137.94252-5-aneesh.kumar@kernel.org> Hi Aneesh, I'm replying on this patch rather than on the one introducing the API. I think it's more obvious here why I think we can make things simpler. On Mon, Nov 16, 2026 at 02:41:27PM +0530, Aneesh Kumar K.V (Arm) wrote: > static struct page *its_alloc_pages_node(int node, gfp_t gfp, > unsigned int order) > { > - struct page *page; > - int ret = 0; > + struct cc_shared_pages mem; > > if (node == NUMA_NO_NODE) > node = numa_mem_id(); > > - page = alloc_pages_node(node, gfp | gfp_flags_quirk, order); > - > - if (!page) > - return NULL; > - > - ret = set_memory_decrypted((unsigned long)page_address(page), > - 1 << order); > - /* > - * If set_memory_decrypted() fails then we don't know what state the > - * page is in, so we can't free it. Instead we leak it. > - * set_memory_decrypted() will already have WARNed. > - */ > - if (ret) > + if (alloc_cc_shared_pages_node(node, gfp | gfp_flags_quirk, > + PAGE_SIZE << order, &mem)) > return NULL; > > - return page; > + return mem.page; This part is mostly fine but I do wonder why not make this alloc function the same as buddy alloc_pages_node() - return a struct page pointer. > static void its_free_pages(void *addr, unsigned int order) > { > - /* > - * If the memory cannot be encrypted again then we must leak the pages. > - * set_memory_encrypted() will already have WARNed. > - */ > - if (set_memory_encrypted((unsigned long)addr, 1 << order)) > + struct cc_shared_layout layout; > + struct cc_shared_pages mem; > + > + if (WARN_ON(cc_shared_calc_layout(PAGE_SIZE << order, &layout))) > return; > - free_pages((unsigned long)addr, order); > + > + mem.page = virt_to_page(addr); > + mem.shared_size = layout.shared_size; > + free_cc_shared_pages(&mem); > } Here it gets weird and I don't see why we can't have just a buddy-like interface. The kernel-doc for alloc says that shared_size must be retained for the corresponding free but without reading the source code, you can't tell that cc_shared_calc_layout() gives you the same shared_size populated by alloc. We have a similar pattern in dma-buf but using the compound page order. What's wrong with a simpler API: struct page *alloc_cc_shared_pages_node(int nid, gfp_t gfp, unsigned int order); struct page *alloc_cc_shared_pages(gfp_t gfp, unsigned int order); void free_cc_shared_pages(struct page *page, unsigned int order); Both alloc and free take the original request order and perform the round up internally without exposing the details to the caller. Alloc shares the whole resulting buddy block and free makes the same block private before releasing it. We can document that free takes the original requested order and releases the whole allocation. Partial frees aren't supported. We can get rid of layout and mem structures (or at least not as part of the API). Of course, this assumes that the shared granule size remains constant for a guest's lifetime but I don't think that's a problem. > @@ -278,7 +267,8 @@ static void *itt_alloc_pool(int node, int size) > if (!page) > break; > > - gen_pool_add(itt_pool, (unsigned long)page_address(page), PAGE_SIZE, node); > + gen_pool_add(itt_pool, (unsigned long)page_address(page), > + cc_shared_granule_size(), node); Here we can introduce: unsigned int cc_shared_page_order(unsigned int order); and just use (PAGE_SIZE << cc_shared_page_order(0)) for gen_pool_add(). Was there a caller you had in mind that needs the common allocator to share less than the whole buddy block? -- Catalin