lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <aMSUww5/oLKWKer6@lizhi-Precision-Tower-5810>
Date: Fri, 12 Sep 2025 17:46:43 -0400
From: Frank Li <Frank.li@....com>
To: ALOK TIWARI <alok.a.tiwari@...cle.com>
Cc: Manivannan Sadhasivam <mani@...nel.org>,
	Krzysztof WilczyƄski <kwilczynski@...nel.org>,
	Kishon Vijay Abraham I <kishon@...nel.org>,
	Bjorn Helgaas <bhelgaas@...gle.com>, Jon Mason <jdmason@...zu.us>,
	Dave Jiang <dave.jiang@...el.com>, Allen Hubbe <allenbh@...il.com>,
	linux-pci@...r.kernel.org, linux-kernel@...r.kernel.org,
	ntb@...ts.linux.dev
Subject: Re: [PATCH 1/2] PCI: endpoint: Enhance pci_epf_alloc_space() and
 rename to pci_epf_set_inbound_space()

On Fri, Aug 29, 2025 at 10:51:56PM +0530, ALOK TIWARI wrote:
>
>
> On 8/16/2025 3:50 AM, Frank Li wrote:
> > +int pci_epf_set_inbound_space(struct pci_epf *epf, size_t size,
> > +			      enum pci_barno bar,
> > +			      const struct pci_epc_features *epc_features,
> > +			      enum pci_epc_interface_type type,
> > +			      bool from_memory,
> > +			      dma_addr_t inbound_addr)
> >   {
> >   	u64 bar_fixed_size = epc_features->bar[bar].fixed_size;
> >   	size_t aligned_size, align = epc_features->align;
> > @@ -270,7 +276,32 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar,
> >   	dma_addr_t phys_addr;
> >   	struct pci_epc *epc;
> >   	struct device *dev;
> > -	void *space;
> > +	void *space = NULL;
> > +	dma_addr_t up;
> > +
> > +	up = inbound_addr + size - 1;
> > +
> > +	/*
> > +	 *  Bits:            15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
> > +	 *  Inbound_addr:    U  U  U  U  U  U  0 X X X X X X X X X
> > +	 *  Up:              U  U  U  U  U  U  1 X X X X X X X X X
> > +	 *
> > +	 *  U means address bits have not change in Range [Inbound_Addr, Up]
> > +	 *  X means bit 0 or 1.
> > +	 *
> > +	 *  Inbound_addr^Up  0  0  0  0  0  0  1 X X X X X X X X X
> > +	 *  Find first bit 1 pos from MSB, 2 ^ pos windows will cover
> > +	 *  [Inbound_Addr, Up] range.
> > +	 */
> > +	if (!from_memory) {
> > +		int pos;
> > +
> > +		for (pos = sizeof(dma_addr_t) - 1; pos > 0; pos--)
> > +			if ((up ^ inbound_addr) & BIT_ULL(pos))
> > +				break;
> > +
>
> sizeof(dma_addr_t) returns bytes, not bits.
> so 7..1 time loop in enough here ?

good find.

Frank
>
> > +		size = 1 << pos;
> > +	}
> >   	if (size < 128)
> >   		size = 128;
> > @@ -283,7 +314,7 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar,
> >   		if (size > bar_fixed_size) {
> >   			dev_err(&epf->dev,
> >   				"requested BAR size is larger than fixed size\n");
> > -			return NULL;
> > +			return -EINVAL;
> >   		}
> >   		size = bar_fixed_size;
> >   	} else {
> > @@ -308,13 +339,25 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar,
> >   	}
> >   	dev = epc->dev.parent;
> > -	space = dma_alloc_coherent(dev, aligned_size, &phys_addr, GFP_KERNEL);
> > -	if (!space) {
> > -		dev_err(dev, "failed to allocate mem space\n");
> > -		return NULL;
> > +
> > +	if (from_memory) {
> > +		space = dma_alloc_coherent(dev, aligned_size,
> > +					   &phys_addr, GFP_KERNEL);
> > +		if (!space) {
> > +			dev_err(dev, "failed to allocate mem space\n");
> > +			return -ENOMEM;
> > +		}
> > +	}
> > +
> > +	epf_bar[bar].phys_addr = from_memory ?
> > +			phys_addr : ALIGN_DOWN(inbound_addr, aligned_size);
> > +
> > +	if (!from_memory && (epf_bar[bar].phys_addr + size < up)) {
> > +		dev_err(&epf->dev,
> > +			"Given bar can't fit required inbound memory region\n");
>
> consider bar -> BAR
>
> > +		return -EINVAL;
> >   	}
>
>
> Thanks,
> Alok

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ