Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1444746lqt; Wed, 20 Mar 2024 04:29:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXncYow4imqcRepy1IAJPjsvV/9ylobhrRHVbup/XWudASn+PvNiQRJ3DEjNMeim+JdVJvV7vjOOOAdStkf+tFDdKta8906GY5ltUo6jQ== X-Google-Smtp-Source: AGHT+IFaNqmipdwikkGPyEhUIUSY6OqPHa8ANXK7U2mIDfuwfC2LMBZvN+dbocsgRN2PcnvFvYv5 X-Received: by 2002:a05:6870:c0d0:b0:220:a138:f59f with SMTP id e16-20020a056870c0d000b00220a138f59fmr17564964oad.31.1710934188176; Wed, 20 Mar 2024 04:29:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710934188; cv=pass; d=google.com; s=arc-20160816; b=AOohA+HrsHz26zI3TlOEIljSnEmruBJNh5nTjE1ZihJqkZpIkrZ51EV5l6dtAn1cUY 3VQdq5huLyUN4Su+r574JEzoySFhHEKeUB776JJZS2XodDujR+pVmeSXgUGelMwJX/5e 8sXhe2YYn2r7bIyqVFi1KTiVZF//ll5hb4emF0FqyQWAFzBSwN0L2vo9xLo/qD7gWHOv 989WqM7+iSsSrLnDCNz/kjt7U4IIwUcIsTAklZ7DszSRZBnHP8se47jNGdIEtfuFEaUg 51Dq/xVUTA/IEvwXJ3O3O2lD3ECAtm0fUqMyQ6k84Qfry7yWo5SVKyw2bUfbRmkD2b31 1Vxg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=foBbDOK3qU2e/ouxw1I330bhNf/1gu0pIPvAkw9hmpU=; fh=aYPzE7qHlZyjQhwUbDnfGoP9cag4IEKrdKO8q5yE3A0=; b=PlKaeU9VvZRLgCK26jIyxg2qD9i/1LgSIAkc4UEe7LRt3j4oz3C60/Qd+rbqE0QEN9 zn4jj8M3QZ8nPAcjQl/lSLuyKk2CJewWj+xDVr5sPH6sHR3jBk8LevHlke+4LRZwyhof 32uKuiykvmCAD+fsyxM87isJBegXjaex0vUJ27jyCp/B3vMe44hD09D74a63oBKDx1bz mj9uGlt+3smnsET4gVz14KRYtvJACbjILxKvXWEG3VJlPs0radxzdG7fRFeiSezqQwgm CbMb+jNfKDMiz372bvHdOuHYM+9AkQN9EbLn5c+apOGDg/UFyHntWw6zXKSYAKvUDqWM 4+Mw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OM1DZP7l; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-108856-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108856-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id c25-20020a634e19000000b005dc8ccd36d9si11858954pgb.250.2024.03.20.04.29.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 04:29:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-108856-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OM1DZP7l; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-108856-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108856-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id CDF16281707 for ; Wed, 20 Mar 2024 11:29:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D7D253D995; Wed, 20 Mar 2024 11:29:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="OM1DZP7l" Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1D07B3BBE7 for ; Wed, 20 Mar 2024 11:29:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710934179; cv=none; b=FB2D0wvi7UBuRY1djJ8+EUndUwwSh7r2Eu6LVCbNkSYZ2rnEO0Z3U48aYgHNJsDEcXpj6kuO1rrQW8z+GZpMCITHBXp35F7fpYE7ZcESX6cpZ2QTnvKc9jhyZCSkUSK3dCByFOY0cd0d7Hk2KlAYFJpUYIRUcerdKy5AdS18E2k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710934179; c=relaxed/simple; bh=OcApL4d7Arq8AjBdKl4uQc/K2QcIn0+ghw4HCVX9avY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OinytdB7i1s4o/6bP/9frD0nokTh8vRbs299zwc+ndpZ0g6V3raEo5L8p5pikd8PfUqetqZfhE50ebnoqmydoTBWvgkXN/S4K6zdEe/30EI4bABwmgu71z4vpFuv+6aPcheha/kzDNljQ+Nki8fxB7apa7KRw9q1nBSWb7vgb6c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=OM1DZP7l; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1dddad37712so62419195ad.3 for ; Wed, 20 Mar 2024 04:29:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1710934177; x=1711538977; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=foBbDOK3qU2e/ouxw1I330bhNf/1gu0pIPvAkw9hmpU=; b=OM1DZP7l8KBZ3PAV6zJogydlPftdYiiZfXc+G4Hszc2o4tqepqPGkqjd5tOaxWkhyG 5mNbYhbpaSDwHlsTRA7Vg8PzqMz988qtZ4Z3k5H9zaBwBGm7DzDakqoFqWmCVSFPH4X4 D+/yw0K66NfW+7pXvbmhFiXGk/GdXVXFqZUEKGDNq1yiJ24L7fMq5Q3ZooumgnttMffX fPrJ5dgeL86Pn/iM5V8oO5RKDjnseM17mriNBMuqKYgKOSVMEb7je9oFXgUHPyA57CNW 0nLwknez0vtQ4lmPQZAH3/k1UVx1AyqxOsA6c16puVlLUQNwIKjTWVtWuDo/xGdVH3ZX KeAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710934177; x=1711538977; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=foBbDOK3qU2e/ouxw1I330bhNf/1gu0pIPvAkw9hmpU=; b=tBHjFuRsJjU7ilzfcvNkcPvan125oPrT/vO1/8/OLUE6SbHNxWHXeTmopNQ/z1CTjY WCPxhwAQ1qo9Y4asSaBtvXVqid3NOZXAZOedwn+xW9K5SYRfyFg1J1aJOveSQpyHA/yz yRkHo1abzTdpvLBpEGDOhvR5Lcwerq31vA+IRiBnqE6IuSI72hsjLXS7URXuJlwLQBtj 13vvslQnldN+jq7K8N0ZNIH2I3GP44gcAerVS7SV1NqCmn9071W0vcXMkfguUazO2A8X +xmNnxtRS7m155jopSIW2iPFTBGbnt7cQux2L3rRT8NBdEahACU+PiZFYCKOIMYe95vM HwIQ== X-Forwarded-Encrypted: i=1; AJvYcCUNN65m0UhhokNoPt4b22vB4x6YS4UwMbnpW1+mEFZuPXQfH+MBNsfVoBtJ45S/+akJkVxjUMX3UpIiOu92gJU4cbptVqebgmeqVr4d X-Gm-Message-State: AOJu0Yyf2eyISFZRqzTLueR5Brt3heRGsIdhkizqc3RVALSdhxgSvz4P QYGdlmrnRCdB0poC9Ht45+o52QDLVACXHI43sy8OnoKeFSJeVAe7PYPVJIKJ+Q== X-Received: by 2002:a17:903:187:b0:1de:de58:2a55 with SMTP id z7-20020a170903018700b001dede582a55mr22557653plg.26.1710934177044; Wed, 20 Mar 2024 04:29:37 -0700 (PDT) Received: from thinkpad ([117.207.18.167]) by smtp.gmail.com with ESMTPSA id p20-20020a170902ead400b001db9cb62f7bsm13282507pld.153.2024.03.20.04.29.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 04:29:36 -0700 (PDT) Date: Wed, 20 Mar 2024 16:59:28 +0530 From: Manivannan Sadhasivam To: Kishon Vijay Abraham I Cc: Jingoo Han , Gustavo Pimentel , Lorenzo Pieralisi , Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , Rob Herring , Bjorn Helgaas , Kishon Vijay Abraham I , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] PCI: endpoint: Migrate to Genalloc framework for outbound window memory allocation Message-ID: <20240320112928.GB2525@thinkpad> References: <20240317-pci-ep-genalloc-v1-1-70fe52a3b9be@linaro.org> <37cfa724-f9ed-41ef-bad4-f00246a4ee8a@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <37cfa724-f9ed-41ef-bad4-f00246a4ee8a@amd.com> On Wed, Mar 20, 2024 at 03:26:41PM +0530, Kishon Vijay Abraham I wrote: > Hi Mani, > > On 3/17/2024 11:39 AM, Manivannan Sadhasivam wrote: > > As proposed during the last year 'PCI Endpoint Subsystem Open Items > > Discussion' of Linux Plumbers conference [1], let's migrate to Genalloc > > framework for managing the endpoint outbound window memory allocation. > > > > PCI Endpoint subsystem is using a custom memory allocator in pci-epc-mem > > driver from the start for managing the memory required to map the host > > address space (outbound) in endpoint. Even though it works well, it > > completely defeats the purpose of the 'Genalloc framework', a general > > purpose memory allocator framework created to avoid various custom memory > > allocators in the kernel. > > > > The migration to Genalloc framework is done is such a way that the existing > > API semantics are preserved. So that the callers of the EPC mem APIs do not > > need any modification (apart from the pcie-designware-epc driver that > > queries page size). > > > > Internally, the EPC mem driver now uses Genalloc framework's > > 'gen_pool_first_fit_order_align' algorithm that aligns the allocated memory > > based on the requested size as like the previous allocator. And the > > page size passed during pci_epc_mem_init() API is used as the minimum order > > for the memory allocations. > > > > During the migration, 'struct pci_epc_mem' is removed as it is seems > > redundant and the existing 'struct pci_epc_mem_window' in 'struct pci_epc' > > is now used to hold the address windows of the endpoint controller. > > > > [1] https://lpc.events/event/17/contributions/1419/ > > Thank you for working on this! > > > > Signed-off-by: Manivannan Sadhasivam > > --- > > drivers/pci/controller/dwc/pcie-designware-ep.c | 14 +- > > drivers/pci/endpoint/pci-epc-mem.c | 182 +++++++++--------------- > > include/linux/pci-epc.h | 25 +--- > > 3 files changed, 81 insertions(+), 140 deletions(-) > > > . > . > > diff --git a/drivers/pci/endpoint/pci-epc-mem.c b/drivers/pci/endpoint/pci-epc-mem.c > > index a9c028f58da1..f9e6e1a6aeaa 100644 > > --- a/drivers/pci/endpoint/pci-epc-mem.c > > +++ b/drivers/pci/endpoint/pci-epc-mem.c > > @@ -4,37 +4,18 @@ > > * > > * Copyright (C) 2017 Texas Instruments > > * Author: Kishon Vijay Abraham I > > + * > > + * Copyright (C) 2024 Linaro Ltd. > > + * Author: Manivannan Sadhasivam > > */ > > +#include > > #include > > #include > > #include > > #include > > -/** > > - * pci_epc_mem_get_order() - determine the allocation order of a memory size > > - * @mem: address space of the endpoint controller > > - * @size: the size for which to get the order > > - * > > - * Reimplement get_order() for mem->page_size since the generic get_order > > - * always gets order with a constant PAGE_SIZE. > > - */ > > -static int pci_epc_mem_get_order(struct pci_epc_mem *mem, size_t size) > > -{ > > - int order; > > - unsigned int page_shift = ilog2(mem->window.page_size); > > - > > - size--; > > - size >>= page_shift; > > -#if BITS_PER_LONG == 32 > > - order = fls(size); > > -#else > > - order = fls64(size); > > -#endif > > - return order; > > -} > > - > > /** > > * pci_epc_multi_mem_init() - initialize the pci_epc_mem structure > > * @epc: the EPC device that invoked pci_epc_mem_init > > @@ -48,17 +29,11 @@ int pci_epc_multi_mem_init(struct pci_epc *epc, > > struct pci_epc_mem_window *windows, > > unsigned int num_windows) > > { > > - struct pci_epc_mem *mem = NULL; > > - unsigned long *bitmap = NULL; > > - unsigned int page_shift; > > + struct pci_epc_mem_window *window = NULL; > > size_t page_size; > > - int bitmap_size; > > - int pages; > > int ret; > > int i; > > - epc->num_windows = 0; > > - > > if (!windows || !num_windows) > > return -EINVAL; > > @@ -70,45 +45,51 @@ int pci_epc_multi_mem_init(struct pci_epc *epc, > > page_size = windows[i].page_size; > > if (page_size < PAGE_SIZE) > > page_size = PAGE_SIZE; > > - page_shift = ilog2(page_size); > > - pages = windows[i].size >> page_shift; > > - bitmap_size = BITS_TO_LONGS(pages) * sizeof(long); > > - mem = kzalloc(sizeof(*mem), GFP_KERNEL); > > - if (!mem) { > > + windows[i].pool = gen_pool_create(ilog2(page_size), -1); > > + if (!windows[i].pool) { > > ret = -ENOMEM; > > - i--; > > - goto err_mem; > > + goto err_free_mem; > > + } > > + > > + gen_pool_set_algo(windows[i].pool, gen_pool_first_fit_order_align, > > + NULL); > > + > > + windows[i].virt_base = ioremap(windows[i].phys_base, windows[i].size); > > Do you have to ioremap upfront the entire window? This could be a problem in > 32-bit systems which has limited vmalloc space. I have faced issues before > when trying to map the entire memory window and had to manipulate vmalloc > boot parameter. > > I'd prefer we find a way to do ioremap per allocation as before. > Hmm, thanks for pointing it out. Current genalloc implementation works on the virtual address as opposed to physical address (that might be due to majority of its users managing the virtual address only). That's the reason I did ioremap of the entire window upfront. Let me see if we can somehow avoid this. - Mani -- மணிவண்ணன் சதாசிவம்