nouveau.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: "Petr Tesařík" <petr@tesarici.cz>
To: Christoph Hellwig <hch@lst.de>
Cc: "Juergen Gross" <jgross@suse.com>,
	x86@kernel.org, "Stefano Stabellini" <sstabellini@kernel.org>,
	"Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Dave Hansen" <dave.hansen@linux.intel.com>,
	"Marek Marczykowski-Górecki" <marmarek@invisiblethingslab.com>,
	linux-kernel@vger.kernel.org, iommu@lists.linux.dev,
	"Ingo Molnar" <mingo@redhat.com>,
	"Borislav Petkov" <bp@alien8.de>,
	"Ben Skeggs" <bskeggs@redhat.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	nouveau@lists.freedesktop.org, xen-devel@lists.xenproject.org,
	"Thomas Gleixner" <tglx@linutronix.de>
Subject: Re: [Nouveau] [PATCH 2/4] x86: always initialize xen-swiotlb when xen-pcifront is enabling
Date: Mon, 22 May 2023 09:52:36 +0200	[thread overview]
Message-ID: <20230522095236.27460d93@meshulam.tesarici.cz> (raw)
In-Reply-To: <20230520062103.GA1225@lst.de>

Hi Christoph,

On Sat, 20 May 2023 08:21:03 +0200
Christoph Hellwig <hch@lst.de> wrote:

> On Fri, May 19, 2023 at 02:58:57PM +0200, Christoph Hellwig wrote:
> > On Fri, May 19, 2023 at 01:49:46PM +0100, Andrew Cooper wrote:  
> > > > The alternative would be to finally merge swiotlb-xen into swiotlb, in
> > > > which case we might be able to do this later.  Let me see what I can
> > > > do there.  
> > > 
> > > If that is an option, it would be great to reduce the special-cashing.  
> > 
> > I think it's doable, and I've been wanting it for a while.  I just
> > need motivated testers, but it seems like I just found at least two :)  
> 
> So looking at swiotlb-xen it does these off things where it takes a value
> generated originally be xen_phys_to_dma, then only does a dma_to_phys
> to go back and call pfn_valid on the result.  Does this make sense, or
> is it wrong and just works by accident?  I.e. is the patch below correct?
> 
> 
> diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
> index 67aa74d201627d..3396c5766f0dd8 100644
> --- a/drivers/xen/swiotlb-xen.c
> +++ b/drivers/xen/swiotlb-xen.c
> @@ -90,9 +90,7 @@ static inline int range_straddles_page_boundary(phys_addr_t p, size_t size)
>  
>  static int is_xen_swiotlb_buffer(struct device *dev, dma_addr_t dma_addr)
>  {
> -	unsigned long bfn = XEN_PFN_DOWN(dma_to_phys(dev, dma_addr));
> -	unsigned long xen_pfn = bfn_to_local_pfn(bfn);
> -	phys_addr_t paddr = (phys_addr_t)xen_pfn << XEN_PAGE_SHIFT;
> +	phys_addr_t paddr = xen_dma_to_phys(dev, dma_addr);


I'm no big Xen expert, but I think this is wrong. Let's go through it
line by line:

- bfn = XEN_PFN_DOWN(dma_to_phys(dev, dma_addr));

  Take the DMA address (as seen by devices on the bus), convert it to a
  physical address (as seen by the CPU on the bus) and shift it right
  by XEN_PAGE_SHIFT. The result is a Xen machine PFN.

- xen_pfn = bfn_to_local_pfn(bfn);

  Take the machine PFN and converts it to a physical PFN.

- paddr = (phys_addr_t)xen_pfn << XEN_PAGE_SHIFT;

  Convert the physical PFN to a physical address.

The important thing here is that Xen PV does not have auto-translated
physical addresses, so physical address != machine address. Physical
addresses in Xen PV domains are "artificial", used by the kernel to
index the mem_map array, so a PFN can be easily converted to a struct
page pointer and back. However, these addresses are never used by
hardware, not even by CPU. The addresses used by the CPU are called
machine addresses. There is no address translation between VCPUs and
CPUs, because a PV domain runs directly on the CPU. After all, that's
why it is called _para_virtualized.

HTH
Petr T

  reply	other threads:[~2023-06-20 18:21 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-18 13:42 [Nouveau] unexport swiotlb_active Christoph Hellwig
2023-05-18 13:42 ` [Nouveau] [PATCH 1/4] x86: move a check out of pci_xen_swiotlb_init Christoph Hellwig
2023-05-18 13:42 ` [Nouveau] [PATCH 2/4] x86: always initialize xen-swiotlb when xen-pcifront is enabling Christoph Hellwig
2023-05-18 18:18   ` Marek Marczykowski-Górecki
2023-05-19  4:04     ` Christoph Hellwig
2023-05-19 10:10       ` Marek Marczykowski-Górecki
2023-05-19 12:41         ` Christoph Hellwig
2023-05-19 12:49           ` Andrew Cooper
2023-05-19 12:58             ` Christoph Hellwig
2023-05-20  6:21               ` Christoph Hellwig
2023-05-22  7:52                 ` Petr Tesařík [this message]
2023-05-22  7:54         ` Petr Tesařík
2023-05-22  8:37         ` Juergen Gross
2023-06-07 13:12           ` Christoph Hellwig
2023-06-09 15:38             ` Juergen Gross
2023-06-12  6:47               ` Christoph Hellwig
2023-06-12  8:08               ` Juergen Gross
2023-06-12  8:23                 ` Christoph Hellwig
2023-05-18 13:42 ` [Nouveau] [PATCH 3/4] drm/nouveau: stop using is_swiotlb_active Christoph Hellwig
2023-05-18 20:30   ` Lyude Paul
2023-06-07 13:11     ` Christoph Hellwig
2023-05-18 13:42 ` [Nouveau] [PATCH 4/4] swiotlb: unexport is_swiotlb_active Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230522095236.27460d93@meshulam.tesarici.cz \
    --to=petr@tesarici.cz \
    --cc=andrew.cooper3@citrix.com \
    --cc=bp@alien8.de \
    --cc=bskeggs@redhat.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=hch@lst.de \
    --cc=hpa@zytor.com \
    --cc=iommu@lists.linux.dev \
    --cc=jgross@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marmarek@invisiblethingslab.com \
    --cc=mingo@redhat.com \
    --cc=nouveau@lists.freedesktop.org \
    --cc=sstabellini@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).