[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 1/2] make ioremap_attr() common


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Thu, 2 Apr 2026 15:46:05 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=JjuCzCu9l3c0FgRD9+k5xTZ56Hp4cgz6aZuEbcUI6e8=; b=hQQTI9k5demWbyfd31HSdCJ8YJRzt7dNHeIKSLnDeLhlC2gP5XRg4EupuZ0+8QKlvHOffWBbQ0pdmrOcuH146j96Ujg7pEgFITLvlzLiYR6T9Kzi71yU81xoEPEwsdn4IuH1boEN6F5uR/FXYORJQzZ7hi35a7BJJ312OD12wZWwE5GzbiAeGjhUqxWqaEVwK3lG1qpMOpa9dNdS/9qfCptcoeEaPPPozgx18THk4vB/HVraG7YKiPfOOoKRiYXsgBfIR0o+H7XeJJMYR/ooN8K8sQtAsUCP/+KMygUMe7qqSi4TtYsHbLAn/qIF/peY0U9xPInR6KAXeMHOrwi3Uw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=h8/UQc8axSA41dqS1CITE6TMp0E6/UDjena30otZAjx4wiJ3g4A1zDBuA7QYcmEGTxRC6KwavOkU24VkD9BzxOSelsFNRV6YXN8MocUN9qw3KnP4jMKn9Oct9eYfdN04g7GzvYmlEj2Mg2neMTF6Gcbc8uecu7iAMakHBU0qO4m4OoUTsI3NXHodINrl2wHZYP0NknVQXWi6lO0O/DHGbqisIa+V3vAOZDfWqHnFM1cVOt5z75ybk91G2peFluDXxeGFaPNgZCBK+z+QcJGtwMk7vDeEv/NfEN5OXwq5+WNb05YF6nNbp+PCQti4hO8is7pyz7T91CJpOSkSXrTJNg==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=citrix.com header.i="@citrix.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Alistair Francis <alistair.francis@xxxxxxx>, Connor Davis <connojdavis@xxxxxxxxx>, Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Volodymyr Babchuk <volodymyr_babchuk@xxxxxxxx>, Timothy Pearson <tpearson@xxxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Thu, 02 Apr 2026 13:46:24 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Thu, Apr 02, 2026 at 02:42:54PM +0200, Jan Beulich wrote:
> On 02.04.2026 14:15, Roger Pau Monné wrote:
> > On Thu, Feb 19, 2026 at 04:51:54PM +0100, Jan Beulich wrote:
> >> --- a/xen/arch/x86/mm.c
> >> +++ b/xen/arch/x86/mm.c
> >> @@ -6166,41 +6166,15 @@ void *__init arch_vmap_virt_end(void)
> >>      return fix_to_virt(__end_of_fixed_addresses);
> >>  }
> >>  
> >> -void __iomem *ioremap(paddr_t pa, size_t len)
> >> +void __iomem *x86_ioremap_attr(paddr_t pa, size_t len, pte_attr_t attr)
> >>  {
> >> -    mfn_t mfn = _mfn(PFN_DOWN(pa));
> >> -    void *va;
> >> -
> >> -    WARN_ON(page_is_ram_type(mfn_x(mfn), RAM_TYPE_CONVENTIONAL));
> >> +    WARN_ON(page_is_ram_type(PFN_DOWN(pa), RAM_TYPE_CONVENTIONAL));
> >>  
> >>      /* The low first Mb is always mapped. */
> >> -    if ( !((pa + len - 1) >> 20) )
> >> -        va = __va(pa);
> >> -    else
> >> -    {
> >> -        unsigned int offs = pa & (PAGE_SIZE - 1);
> >> -        unsigned int nr = PFN_UP(offs + len);
> >> -
> >> -        va = __vmap(&mfn, nr, 1, 1, PAGE_HYPERVISOR_UCMINUS, 
> >> VMAP_DEFAULT);
> >> -        if ( va )
> >> -            va += offs;
> >> -    }
> >> -
> >> -    return (void __force __iomem *)va;
> >> -}
> >> -
> >> -void __iomem *__init ioremap_wc(paddr_t pa, size_t len)
> >> -{
> >> -    mfn_t mfn = _mfn(PFN_DOWN(pa));
> >> -    unsigned int offs = pa & (PAGE_SIZE - 1);
> >> -    unsigned int nr = PFN_UP(offs + len);
> >> -    void *va;
> >> -
> >> -    WARN_ON(page_is_ram_type(mfn_x(mfn), RAM_TYPE_CONVENTIONAL));
> >> -
> >> -    va = __vmap(&mfn, nr, 1, 1, PAGE_HYPERVISOR_WC, VMAP_DEFAULT);
> >> +    if ( !((pa + len - 1) >> 20) && attr == PAGE_HYPERVISOR_UCMINUS )
> >> +        return (void __force __iomem *)__va(pa);
> > 
> > Sorry, I'm possibly a bit lost: I see that on the bootstrap
> > page-tables we map the VGA hole (0xa0000-0xc0000) as UC-, but I'm not
> > seeing this being done to the directmap?
> 
> I'm not changing that aspect here, do I? ioremap() used the direct map
> (apparently assuming the cache attribute is suitable), and so do I now.
> 
> Yet then, to address the point you make anyway, I certainly see use of
> __PAGE_HYPERVISOR_UCMINUS in l1_directmap[].

Yes, sorry, I know you are not adding this here.  Just took a look at
the code, and I couldn't find where the directmap entries for the low
1M get adjusted to use UC-.  I should have made the comment clearer.

> >> --- /dev/null
> >> +++ b/xen/common/ioremap.c
> >> @@ -0,0 +1,42 @@
> >> +/* SPDX-License-Identifier: GPL-2.0-only */
> >> +
> >> +#include <xen/mm.h>
> >> +#include <xen/pfn.h>
> >> +#include <xen/vmap.h>
> >> +
> >> +#include <asm/io.h>
> >> +
> >> +void __iomem *ioremap_attr(paddr_t pa, size_t len, pte_attr_t attr)
> >> +{
> >> +    void __iomem *ptr = NULL;
> >> +    unsigned int offs = PAGE_OFFSET(pa);
> >> +
> >> +#ifdef arch_ioremap_attr
> >> +    ptr = arch_ioremap_attr(pa, len, attr);
> >> +    if ( PAGE_OFFSET(ptr) )
> >> +        return ptr;
> > 
> > IMO it's a bit confusing to deal with the offset addition detached
> > form here, I would rather do:
> > 
> > if ( ptr != NULL )
> > {
> >     ASSERT(PAGE_OFFSET(ptr) == offs);
> >     return PAGE_OFFSET(ptr) ? ptr : ptr + off;
> > }
> > 
> > And get rid of the !ptr check in the if below.  So that when
> > arch_ioremap_attr() succeeds it's all dealt with in the #ifdef
> > protected block.
> 
> Possible, yet I deemed the other variant better.

OK, I'm not going to insist then.  It just took me a bit to notice the
extra !ptr check in the if condition below.

> The assertion you suggest isn't valid anyway (see the last sentence of the
> description and xen/arch/arm/mpu/mm.c:ioremap_attr() prior to Michal's
> "xen/arm: mpu: Fix ioremap_attr region size and return value"). Now that
> that's changing, things may indeed be possible to simplify here.

Oh, I see, right you are.  It should be:

ASSERT(!PAGE_OFFSET(ptr) || PAGE_OFFSET(ptr) == offs);

Thanks, Roger.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.