LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH] dt: Remove booting-without-of.txt
From: Frank Rowand @ 2020-03-05 22:48 UTC (permalink / raw)
  To: Rob Herring, devicetree
  Cc: Geert Uytterhoeven, linux-kernel, Mauro Carvalho Chehab,
	linuxppc-dev, linux-arm-kernel
In-Reply-To: <20200304184525.7643-1-robh@kernel.org>

On 3/4/20 12:45 PM, Rob Herring wrote:
> Well, not quite removed yet... Mauro is looking at moving this to ReST,
> but I think it would be better to trim or remove it.
> 
> boot-without-of.txt is an ancient document that first outlined
> Flattened DeviceTree. The DT world has evolved a lot in the 15 years
> since and boot-without-of.txt is pretty stale. The name of the document
> itself is confusing if you don't understand the evolution from real
> 'OpenFirmware'. Much of what booting-without-of.txt contains is now in
> the DT specification (which evolved out of the ePAPR).
> 
> This is a first pass of removing everything that has a DT spec
> equivalent or is no longer standard practice (e.g. soc<SoCName> for SoC
> nodes) in order to see what's left. This is what I have:
> 
> TODO
> - Move boot interface details to arch specific docs
> - Document 'serial-number' property in DT spec
> - Document the 'hotpluggable' memory property in DT spec
> - Document the 'sleep' property (PPC only)
> - Document the 'dma-coherent' property in DT spec
> - Need the history of node names and 'name' property?
> - Need how addresses work?

Looks good.  Since this is a first pass, I'm expecting that polishing
(things like updating section numbers) would happen in subsequent
patches after more of the content changes are done, so no need
to do so in this patch.

Reviewed-by: Frank Rowand <frank.rowand@sony.com>

-Frank

> 
> Cc: Frank Rowand <frowand.list@gmail.com>
> Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> Cc: Geert Uytterhoeven <geert+renesas@glider.be>
> Cc: Michael Ellerman <mpe@ellerman.id.au>
> Cc: linuxppc-dev@lists.ozlabs.org
> Signed-off-by: Rob Herring <robh@kernel.org>
> ---
>  .../devicetree/booting-without-of.txt         | 1027 +----------------
>  1 file changed, 1 insertion(+), 1026 deletions(-)
> 
> diff --git a/Documentation/devicetree/booting-without-of.txt b/Documentation/devicetree/booting-without-of.txt
> index 4660ccee35a3..97beee828ba4 100644
> --- a/Documentation/devicetree/booting-without-of.txt
> +++ b/Documentation/devicetree/booting-without-of.txt
> @@ -19,44 +19,17 @@ Table of Contents
>      5) Entry point for arch/sh
>  
>    II - The DT block format
> -    1) Header
>      2) Device tree generalities
> -    3) Device tree "structure" block
> -    4) Device tree "strings" block
>  
>    III - Required content of the device tree
>      1) Note about cells and address representation
> -    2) Note about "compatible" properties
> -    3) Note about "name" properties
> -    4) Note about node and property names and character set
>      5) Required nodes and properties
>        a) The root node
> -      b) The /cpus node
> -      c) The /cpus/* nodes
> -      d) the /memory node(s)
> -      e) The /chosen node
> -      f) the /soc<SOCname> node
> -
> -  IV - "dtc", the device tree compiler
> -
> -  V - Recommendations for a bootloader
> -
> -  VI - System-on-a-chip devices and nodes
> -    1) Defining child nodes of an SOC
> -    2) Representing devices without a current OF specification
> -
> -  VII - Specifying interrupt information for devices
> -    1) interrupts property
> -    2) interrupt-parent property
> -    3) OpenPIC Interrupt Controllers
> -    4) ISA Interrupt Controllers
>  
>    VIII - Specifying device power management information (sleep property)
>  
>    IX - Specifying dma bus information
>  
> -  Appendix A - Sample SOC node for MPC8540
> -
>  
>  Revision Information
>  ====================
> @@ -105,19 +78,6 @@ Revision Information
>  			 - Added chapter VI
>  
>  
> - ToDo:
> -	- Add some definitions of interrupt tree (simple/complex)
> -	- Add some definitions for PCI host bridges
> -	- Add some common address format examples
> -	- Add definitions for standard properties and "compatible"
> -	  names for cells that are not already defined by the existing
> -	  OF spec.
> -	- Compare FSL SOC use of PCI to standard and make sure no new
> -	  node definition required.
> -	- Add more information about node definitions for SOC devices
> -  	  that currently have no standard, like the FSL CPM.
> -
> -
>  I - Introduction
>  ================
>  
> @@ -333,196 +293,17 @@ II - The DT block format
>  ========================
>  
>  
> -This chapter defines the actual format of the flattened device-tree
> -passed to the kernel. The actual content of it and kernel requirements
> -are described later. You can find example of code manipulating that
> -format in various places, including arch/powerpc/kernel/prom_init.c
> -which will generate a flattened device-tree from the Open Firmware
> -representation, or the fs2dt utility which is part of the kexec tools
> -which will generate one from a filesystem representation. It is
> -expected that a bootloader like uboot provides a bit more support,
> -that will be discussed later as well.
> -
>  Note: The block has to be in main memory. It has to be accessible in
>  both real mode and virtual mode with no mapping other than main
>  memory. If you are writing a simple flash bootloader, it should copy
>  the block to RAM before passing it to the kernel.
>  
>  
> -1) Header
> ----------
> -
> -   The kernel is passed the physical address pointing to an area of memory
> -   that is roughly described in include/linux/of_fdt.h by the structure
> -   boot_param_header:
> -
> -struct boot_param_header {
> -        u32     magic;                  /* magic word OF_DT_HEADER */
> -        u32     totalsize;              /* total size of DT block */
> -        u32     off_dt_struct;          /* offset to structure */
> -        u32     off_dt_strings;         /* offset to strings */
> -        u32     off_mem_rsvmap;         /* offset to memory reserve map
> -                                           */
> -        u32     version;                /* format version */
> -        u32     last_comp_version;      /* last compatible version */
> -
> -        /* version 2 fields below */
> -        u32     boot_cpuid_phys;        /* Which physical CPU id we're
> -                                           booting on */
> -        /* version 3 fields below */
> -        u32     size_dt_strings;        /* size of the strings block */
> -
> -        /* version 17 fields below */
> -        u32	size_dt_struct;		/* size of the DT structure block */
> -};
> -
> -   Along with the constants:
> -
> -/* Definitions used by the flattened device tree */
> -#define OF_DT_HEADER            0xd00dfeed      /* 4: version,
> -						   4: total size */
> -#define OF_DT_BEGIN_NODE        0x1             /* Start node: full name
> -						   */
> -#define OF_DT_END_NODE          0x2             /* End node */
> -#define OF_DT_PROP              0x3             /* Property: name off,
> -                                                   size, content */
> -#define OF_DT_END               0x9
> -
> -   All values in this header are in big endian format, the various
> -   fields in this header are defined more precisely below. All
> -   "offset" values are in bytes from the start of the header; that is
> -   from the physical base address of the device tree block.
> -
> -   - magic
> -
> -     This is a magic value that "marks" the beginning of the
> -     device-tree block header. It contains the value 0xd00dfeed and is
> -     defined by the constant OF_DT_HEADER
> -
> -   - totalsize
> -
> -     This is the total size of the DT block including the header. The
> -     "DT" block should enclose all data structures defined in this
> -     chapter (who are pointed to by offsets in this header). That is,
> -     the device-tree structure, strings, and the memory reserve map.
> -
> -   - off_dt_struct
> -
> -     This is an offset from the beginning of the header to the start
> -     of the "structure" part the device tree. (see 2) device tree)
> -
> -   - off_dt_strings
> -
> -     This is an offset from the beginning of the header to the start
> -     of the "strings" part of the device-tree
> -
> -   - off_mem_rsvmap
> -
> -     This is an offset from the beginning of the header to the start
> -     of the reserved memory map. This map is a list of pairs of 64-
> -     bit integers. Each pair is a physical address and a size. The
> -     list is terminated by an entry of size 0. This map provides the
> -     kernel with a list of physical memory areas that are "reserved"
> -     and thus not to be used for memory allocations, especially during
> -     early initialization. The kernel needs to allocate memory during
> -     boot for things like un-flattening the device-tree, allocating an
> -     MMU hash table, etc... Those allocations must be done in such a
> -     way to avoid overriding critical things like, on Open Firmware
> -     capable machines, the RTAS instance, or on some pSeries, the TCE
> -     tables used for the iommu. Typically, the reserve map should
> -     contain _at least_ this DT block itself (header,total_size). If
> -     you are passing an initrd to the kernel, you should reserve it as
> -     well. You do not need to reserve the kernel image itself. The map
> -     should be 64-bit aligned.
> -
> -   - version
> -
> -     This is the version of this structure. Version 1 stops
> -     here. Version 2 adds an additional field boot_cpuid_phys.
> -     Version 3 adds the size of the strings block, allowing the kernel
> -     to reallocate it easily at boot and free up the unused flattened
> -     structure after expansion. Version 16 introduces a new more
> -     "compact" format for the tree itself that is however not backward
> -     compatible. Version 17 adds an additional field, size_dt_struct,
> -     allowing it to be reallocated or moved more easily (this is
> -     particularly useful for bootloaders which need to make
> -     adjustments to a device tree based on probed information). You
> -     should always generate a structure of the highest version defined
> -     at the time of your implementation. Currently that is version 17,
> -     unless you explicitly aim at being backward compatible.
> -
> -   - last_comp_version
> -
> -     Last compatible version. This indicates down to what version of
> -     the DT block you are backward compatible. For example, version 2
> -     is backward compatible with version 1 (that is, a kernel build
> -     for version 1 will be able to boot with a version 2 format). You
> -     should put a 1 in this field if you generate a device tree of
> -     version 1 to 3, or 16 if you generate a tree of version 16 or 17
> -     using the new unit name format.
> -
> -   - boot_cpuid_phys
> -
> -     This field only exist on version 2 headers. It indicate which
> -     physical CPU ID is calling the kernel entry point. This is used,
> -     among others, by kexec. If you are on an SMP system, this value
> -     should match the content of the "reg" property of the CPU node in
> -     the device-tree corresponding to the CPU calling the kernel entry
> -     point (see further chapters for more information on the required
> -     device-tree contents)
> -
> -   - size_dt_strings
> -
> -     This field only exists on version 3 and later headers.  It
> -     gives the size of the "strings" section of the device tree (which
> -     starts at the offset given by off_dt_strings).
> -
> -   - size_dt_struct
> -
> -     This field only exists on version 17 and later headers.  It gives
> -     the size of the "structure" section of the device tree (which
> -     starts at the offset given by off_dt_struct).
> -
> -   So the typical layout of a DT block (though the various parts don't
> -   need to be in that order) looks like this (addresses go from top to
> -   bottom):
> -
> -
> -             ------------------------------
> -     base -> |  struct boot_param_header  |
> -             ------------------------------
> -             |      (alignment gap) (*)   |
> -             ------------------------------
> -             |      memory reserve map    |
> -             ------------------------------
> -             |      (alignment gap)       |
> -             ------------------------------
> -             |                            |
> -             |    device-tree structure   |
> -             |                            |
> -             ------------------------------
> -             |      (alignment gap)       |
> -             ------------------------------
> -             |                            |
> -             |     device-tree strings    |
> -             |                            |
> -      -----> ------------------------------
> -      |
> -      |
> -      --- (base + totalsize)
> -
> -  (*) The alignment gaps are not necessarily present; their presence
> -      and size are dependent on the various alignment requirements of
> -      the individual data blocks.
>  
>  
>  2) Device tree generalities
>  ---------------------------
>  
> -This device-tree itself is separated in two different blocks, a
> -structure block and a strings block. Both need to be aligned to a 4
> -byte boundary.
> -
>  First, let's quickly describe the device-tree concept before detailing
>  the storage format. This chapter does _not_ describe the detail of the
>  required types of nodes & properties for the kernel, this is done
> @@ -574,128 +355,6 @@ is) is also required to have a "compatible" property indicating the
>  specific hardware and an optional list of devices it is fully
>  backwards compatible with.
>  
> -Finally, every node that can be referenced from a property in another
> -node is required to have either a "phandle" or a "linux,phandle"
> -property. Real Open Firmware implementations provide a unique
> -"phandle" value for every node that the "prom_init()" trampoline code
> -turns into "linux,phandle" properties. However, this is made optional
> -if the flattened device tree is used directly. An example of a node
> -referencing another node via "phandle" is when laying out the
> -interrupt tree which will be described in a further version of this
> -document.
> -
> -The "phandle" property is a 32-bit value that uniquely
> -identifies a node. You are free to use whatever values or system of
> -values, internal pointers, or whatever to generate these, the only
> -requirement is that every node for which you provide that property has
> -a unique value for it.
> -
> -Here is an example of a simple device-tree. In this example, an "o"
> -designates a node followed by the node unit name. Properties are
> -presented with their name followed by their content. "content"
> -represents an ASCII string (zero terminated) value, while <content>
> -represents a 32-bit value, specified in decimal or hexadecimal (the
> -latter prefixed 0x). The various nodes in this example will be
> -discussed in a later chapter. At this point, it is only meant to give
> -you a idea of what a device-tree looks like. I have purposefully kept
> -the "name" and "linux,phandle" properties which aren't necessary in
> -order to give you a better idea of what the tree looks like in
> -practice.
> -
> -  / o device-tree
> -      |- name = "device-tree"
> -      |- model = "MyBoardName"
> -      |- compatible = "MyBoardFamilyName"
> -      |- #address-cells = <2>
> -      |- #size-cells = <2>
> -      |- linux,phandle = <0>
> -      |
> -      o cpus
> -      | | - name = "cpus"
> -      | | - linux,phandle = <1>
> -      | | - #address-cells = <1>
> -      | | - #size-cells = <0>
> -      | |
> -      | o PowerPC,970@0
> -      |   |- name = "PowerPC,970"
> -      |   |- device_type = "cpu"
> -      |   |- reg = <0>
> -      |   |- clock-frequency = <0x5f5e1000>
> -      |   |- 64-bit
> -      |   |- linux,phandle = <2>
> -      |
> -      o memory@0
> -      | |- name = "memory"
> -      | |- device_type = "memory"
> -      | |- reg = <0x00000000 0x00000000 0x00000000 0x20000000>
> -      | |- linux,phandle = <3>
> -      |
> -      o chosen
> -        |- name = "chosen"
> -        |- bootargs = "root=/dev/sda2"
> -        |- linux,phandle = <4>
> -
> -This tree is almost a minimal tree. It pretty much contains the
> -minimal set of required nodes and properties to boot a linux kernel;
> -that is, some basic model information at the root, the CPUs, and the
> -physical memory layout.  It also includes misc information passed
> -through /chosen, like in this example, the platform type (mandatory)
> -and the kernel command line arguments (optional).
> -
> -The /cpus/PowerPC,970@0/64-bit property is an example of a
> -property without a value. All other properties have a value. The
> -significance of the #address-cells and #size-cells properties will be
> -explained in chapter IV which defines precisely the required nodes and
> -properties and their content.
> -
> -
> -3) Device tree "structure" block
> -
> -The structure of the device tree is a linearized tree structure. The
> -"OF_DT_BEGIN_NODE" token starts a new node, and the "OF_DT_END_NODE"
> -ends that node definition. Child nodes are simply defined before
> -"OF_DT_END_NODE" (that is nodes within the node). A 'token' is a 32
> -bit value. The tree has to be "finished" with a OF_DT_END token
> -
> -Here's the basic structure of a single node:
> -
> -     * token OF_DT_BEGIN_NODE (that is 0x00000001)
> -     * for version 1 to 3, this is the node full path as a zero
> -       terminated string, starting with "/". For version 16 and later,
> -       this is the node unit name only (or an empty string for the
> -       root node)
> -     * [align gap to next 4 bytes boundary]
> -     * for each property:
> -        * token OF_DT_PROP (that is 0x00000003)
> -        * 32-bit value of property value size in bytes (or 0 if no
> -          value)
> -        * 32-bit value of offset in string block of property name
> -        * property value data if any
> -        * [align gap to next 4 bytes boundary]
> -     * [child nodes if any]
> -     * token OF_DT_END_NODE (that is 0x00000002)
> -
> -So the node content can be summarized as a start token, a full path,
> -a list of properties, a list of child nodes, and an end token. Every
> -child node is a full node structure itself as defined above.
> -
> -NOTE: The above definition requires that all property definitions for
> -a particular node MUST precede any subnode definitions for that node.
> -Although the structure would not be ambiguous if properties and
> -subnodes were intermingled, the kernel parser requires that the
> -properties come first (up until at least 2.6.22).  Any tools
> -manipulating a flattened tree must take care to preserve this
> -constraint.
> -
> -4) Device tree "strings" block
> -
> -In order to save space, property names, which are generally redundant,
> -are stored separately in the "strings" block. This block is simply the
> -whole bunch of zero terminated strings for all property names
> -concatenated together. The device-tree property definitions in the
> -structure block will contain offset values from the beginning of the
> -strings block.
> -
>  
>  III - Required content of the device tree
>  =========================================
> @@ -792,568 +451,14 @@ registers are visible on the parent bus using an identity mapping
>  translation.  In other words, the parent bus address space is the same
>  as the child bus address space.
>  
> -2) Note about "compatible" properties
> --------------------------------------
> -
> -These properties are optional, but recommended in devices and the root
> -node. The format of a "compatible" property is a list of concatenated
> -zero terminated strings. They allow a device to express its
> -compatibility with a family of similar devices, in some cases,
> -allowing a single driver to match against several devices regardless
> -of their actual names.
> -
> -3) Note about "name" properties
> --------------------------------
> -
> -While earlier users of Open Firmware like OldWorld macintoshes tended
> -to use the actual device name for the "name" property, it's nowadays
> -considered a good practice to use a name that is closer to the device
> -class (often equal to device_type). For example, nowadays, Ethernet
> -controllers are named "ethernet", an additional "model" property
> -defining precisely the chip type/model, and "compatible" property
> -defining the family in case a single driver can driver more than one
> -of these chips. However, the kernel doesn't generally put any
> -restriction on the "name" property; it is simply considered good
> -practice to follow the standard and its evolutions as closely as
> -possible.
> -
> -Note also that the new format version 16 makes the "name" property
> -optional. If it's absent for a node, then the node's unit name is then
> -used to reconstruct the name. That is, the part of the unit name
> -before the "@" sign is used (or the entire unit name if no "@" sign
> -is present).
> -
> -4) Note about node and property names and character set
> --------------------------------------------------------
> -
> -While Open Firmware provides more flexible usage of 8859-1, this
> -specification enforces more strict rules. Nodes and properties should
> -be comprised only of ASCII characters 'a' to 'z', '0' to
> -'9', ',', '.', '_', '+', '#', '?', and '-'. Node names additionally
> -allow uppercase characters 'A' to 'Z' (property names should be
> -lowercase. The fact that vendors like Apple don't respect this rule is
> -irrelevant here). Additionally, node and property names should always
> -begin with a character in the range 'a' to 'z' (or 'A' to 'Z' for node
> -names).
> -
> -The maximum number of characters for both nodes and property names
> -is 31. In the case of node names, this is only the leftmost part of
> -a unit name (the pure "name" property), it doesn't include the unit
> -address which can extend beyond that limit.
> -
>  
>  5) Required nodes and properties
>  --------------------------------
> -  These are all that are currently required. However, it is strongly
> -  recommended that you expose PCI host bridges as documented in the
> -  PCI binding to Open Firmware, and your interrupt tree as documented
> -  in OF interrupt tree specification.
> -
> -  a) The root node
> -
> -  The root node requires some properties to be present:
> -
> -    - model : this is your board name/model
> -    - #address-cells : address representation for "root" devices
> -    - #size-cells: the size representation for "root" devices
> -    - compatible : the board "family" generally finds its way here,
> -      for example, if you have 2 board models with a similar layout,
> -      that typically get driven by the same platform code in the
> -      kernel, you would specify the exact board model in the
> -      compatible property followed by an entry that represents the SoC
> -      model.
> -
> -  The root node is also generally where you add additional properties
> -  specific to your board like the serial number if any, that sort of
> -  thing. It is recommended that if you add any "custom" property whose
> -  name may clash with standard defined ones, you prefix them with your
> -  vendor name and a comma.
>  
>    Additional properties for the root node:
>  
>      - serial-number : a string representing the device's serial number
>  
> -  b) The /cpus node
> -
> -  This node is the parent of all individual CPU nodes. It doesn't
> -  have any specific requirements, though it's generally good practice
> -  to have at least:
> -
> -               #address-cells = <00000001>
> -               #size-cells    = <00000000>
> -
> -  This defines that the "address" for a CPU is a single cell, and has
> -  no meaningful size. This is not necessary but the kernel will assume
> -  that format when reading the "reg" properties of a CPU node, see
> -  below
> -
> -  c) The /cpus/* nodes
> -
> -  So under /cpus, you are supposed to create a node for every CPU on
> -  the machine. There is no specific restriction on the name of the
> -  CPU, though it's common to call it <architecture>,<core>. For
> -  example, Apple uses PowerPC,G5 while IBM uses PowerPC,970FX.
> -  However, the Generic Names convention suggests that it would be
> -  better to simply use 'cpu' for each cpu node and use the compatible
> -  property to identify the specific cpu core.
> -
> -  Required properties:
> -
> -    - device_type : has to be "cpu"
> -    - reg : This is the physical CPU number, it's a single 32-bit cell
> -      and is also used as-is as the unit number for constructing the
> -      unit name in the full path. For example, with 2 CPUs, you would
> -      have the full path:
> -        /cpus/PowerPC,970FX@0
> -        /cpus/PowerPC,970FX@1
> -      (unit addresses do not require leading zeroes)
> -    - d-cache-block-size : one cell, L1 data cache block size in bytes (*)
> -    - i-cache-block-size : one cell, L1 instruction cache block size in
> -      bytes
> -    - d-cache-size : one cell, size of L1 data cache in bytes
> -    - i-cache-size : one cell, size of L1 instruction cache in bytes
> -
> -(*) The cache "block" size is the size on which the cache management
> -instructions operate. Historically, this document used the cache
> -"line" size here which is incorrect. The kernel will prefer the cache
> -block size and will fallback to cache line size for backward
> -compatibility.
> -
> -  Recommended properties:
> -
> -    - timebase-frequency : a cell indicating the frequency of the
> -      timebase in Hz. This is not directly used by the generic code,
> -      but you are welcome to copy/paste the pSeries code for setting
> -      the kernel timebase/decrementer calibration based on this
> -      value.
> -    - clock-frequency : a cell indicating the CPU core clock frequency
> -      in Hz. A new property will be defined for 64-bit values, but if
> -      your frequency is < 4Ghz, one cell is enough. Here as well as
> -      for the above, the common code doesn't use that property, but
> -      you are welcome to re-use the pSeries or Maple one. A future
> -      kernel version might provide a common function for this.
> -    - d-cache-line-size : one cell, L1 data cache line size in bytes
> -      if different from the block size
> -    - i-cache-line-size : one cell, L1 instruction cache line size in
> -      bytes if different from the block size
> -
> -  You are welcome to add any property you find relevant to your board,
> -  like some information about the mechanism used to soft-reset the
> -  CPUs. For example, Apple puts the GPIO number for CPU soft reset
> -  lines in there as a "soft-reset" property since they start secondary
> -  CPUs by soft-resetting them.
> -
> -
> -  d) the /memory node(s)
> -
> -  To define the physical memory layout of your board, you should
> -  create one or more memory node(s). You can either create a single
> -  node with all memory ranges in its reg property, or you can create
> -  several nodes, as you wish. The unit address (@ part) used for the
> -  full path is the address of the first range of memory defined by a
> -  given node. If you use a single memory node, this will typically be
> -  @0.
> -
> -  Required properties:
> -
> -    - device_type : has to be "memory"
> -    - reg : This property contains all the physical memory ranges of
> -      your board. It's a list of addresses/sizes concatenated
> -      together, with the number of cells of each defined by the
> -      #address-cells and #size-cells of the root node. For example,
> -      with both of these properties being 2 like in the example given
> -      earlier, a 970 based machine with 6Gb of RAM could typically
> -      have a "reg" property here that looks like:
> -
> -      00000000 00000000 00000000 80000000
> -      00000001 00000000 00000001 00000000
> -
> -      That is a range starting at 0 of 0x80000000 bytes and a range
> -      starting at 0x100000000 and of 0x100000000 bytes. You can see
> -      that there is no memory covering the IO hole between 2Gb and
> -      4Gb. Some vendors prefer splitting those ranges into smaller
> -      segments, but the kernel doesn't care.
> -
> -  Additional properties:
> -
> -    - hotpluggable : The presence of this property provides an explicit
> -      hint to the operating system that this memory may potentially be
> -      removed later. The kernel can take this into consideration when
> -      doing nonmovable allocations and when laying out memory zones.
> -
> -  e) The /chosen node
> -
> -  This node is a bit "special". Normally, that's where Open Firmware
> -  puts some variable environment information, like the arguments, or
> -  the default input/output devices.
> -
> -  This specification makes a few of these mandatory, but also defines
> -  some linux-specific properties that would be normally constructed by
> -  the prom_init() trampoline when booting with an OF client interface,
> -  but that you have to provide yourself when using the flattened format.
> -
> -  Recommended properties:
> -
> -    - bootargs : This zero-terminated string is passed as the kernel
> -      command line
> -    - linux,stdout-path : This is the full path to your standard
> -      console device if any. Typically, if you have serial devices on
> -      your board, you may want to put the full path to the one set as
> -      the default console in the firmware here, for the kernel to pick
> -      it up as its own default console.
> -
> -  Note that u-boot creates and fills in the chosen node for platforms
> -  that use it.
> -
> -  (Note: a practice that is now obsolete was to include a property
> -  under /chosen called interrupt-controller which had a phandle value
> -  that pointed to the main interrupt controller)
> -
> -  f) the /soc<SOCname> node
> -
> -  This node is used to represent a system-on-a-chip (SoC) and must be
> -  present if the processor is a SoC. The top-level soc node contains
> -  information that is global to all devices on the SoC. The node name
> -  should contain a unit address for the SoC, which is the base address
> -  of the memory-mapped register set for the SoC. The name of an SoC
> -  node should start with "soc", and the remainder of the name should
> -  represent the part number for the soc.  For example, the MPC8540's
> -  soc node would be called "soc8540".
> -
> -  Required properties:
> -
> -    - ranges : Should be defined as specified in 1) to describe the
> -      translation of SoC addresses for memory mapped SoC registers.
> -    - bus-frequency: Contains the bus frequency for the SoC node.
> -      Typically, the value of this field is filled in by the boot
> -      loader.
> -    - compatible : Exact model of the SoC
> -
> -
> -  Recommended properties:
> -
> -    - reg : This property defines the address and size of the
> -      memory-mapped registers that are used for the SOC node itself.
> -      It does not include the child device registers - these will be
> -      defined inside each child node.  The address specified in the
> -      "reg" property should match the unit address of the SOC node.
> -    - #address-cells : Address representation for "soc" devices.  The
> -      format of this field may vary depending on whether or not the
> -      device registers are memory mapped.  For memory mapped
> -      registers, this field represents the number of cells needed to
> -      represent the address of the registers.  For SOCs that do not
> -      use MMIO, a special address format should be defined that
> -      contains enough cells to represent the required information.
> -      See 1) above for more details on defining #address-cells.
> -    - #size-cells : Size representation for "soc" devices
> -    - #interrupt-cells : Defines the width of cells used to represent
> -       interrupts.  Typically this value is <2>, which includes a
> -       32-bit number that represents the interrupt number, and a
> -       32-bit number that represents the interrupt sense and level.
> -       This field is only needed if the SOC contains an interrupt
> -       controller.
> -
> -  The SOC node may contain child nodes for each SOC device that the
> -  platform uses.  Nodes should not be created for devices which exist
> -  on the SOC but are not used by a particular platform. See chapter VI
> -  for more information on how to specify devices that are part of a SOC.
> -
> -  Example SOC node for the MPC8540:
> -
> -	soc8540@e0000000 {
> -		#address-cells = <1>;
> -		#size-cells = <1>;
> -		#interrupt-cells = <2>;
> -		device_type = "soc";
> -		ranges = <0x00000000 0xe0000000 0x00100000>
> -		reg = <0xe0000000 0x00003000>;
> -		bus-frequency = <0>;
> -	}
> -
> -
> -
> -IV - "dtc", the device tree compiler
> -====================================
> -
> -
> -dtc source code can be found at
> -<http://git.jdl.com/gitweb/?p=dtc.git>
> -
> -WARNING: This version is still in early development stage; the
> -resulting device-tree "blobs" have not yet been validated with the
> -kernel. The current generated block lacks a useful reserve map (it will
> -be fixed to generate an empty one, it's up to the bootloader to fill
> -it up) among others. The error handling needs work, bugs are lurking,
> -etc...
> -
> -dtc basically takes a device-tree in a given format and outputs a
> -device-tree in another format. The currently supported formats are:
> -
> -  Input formats:
> -  -------------
> -
> -     - "dtb": "blob" format, that is a flattened device-tree block
> -       with
> -        header all in a binary blob.
> -     - "dts": "source" format. This is a text file containing a
> -       "source" for a device-tree. The format is defined later in this
> -        chapter.
> -     - "fs" format. This is a representation equivalent to the
> -        output of /proc/device-tree, that is nodes are directories and
> -	properties are files
> -
> - Output formats:
> - ---------------
> -
> -     - "dtb": "blob" format
> -     - "dts": "source" format
> -     - "asm": assembly language file. This is a file that can be
> -       sourced by gas to generate a device-tree "blob". That file can
> -       then simply be added to your Makefile. Additionally, the
> -       assembly file exports some symbols that can be used.
> -
> -
> -The syntax of the dtc tool is
> -
> -    dtc [-I <input-format>] [-O <output-format>]
> -        [-o output-filename] [-V output_version] input_filename
> -
> -
> -The "output_version" defines what version of the "blob" format will be
> -generated. Supported versions are 1,2,3 and 16. The default is
> -currently version 3 but that may change in the future to version 16.
> -
> -Additionally, dtc performs various sanity checks on the tree, like the
> -uniqueness of linux, phandle properties, validity of strings, etc...
> -
> -The format of the .dts "source" file is "C" like, supports C and C++
> -style comments.
> -
> -/ {
> -}
> -
> -The above is the "device-tree" definition. It's the only statement
> -supported currently at the toplevel.
> -
> -/ {
> -  property1 = "string_value";	/* define a property containing a 0
> -                                 * terminated string
> -				 */
> -
> -  property2 = <0x1234abcd>;	/* define a property containing a
> -                                 * numerical 32-bit value (hexadecimal)
> -				 */
> -
> -  property3 = <0x12345678 0x12345678 0xdeadbeef>;
> -                                /* define a property containing 3
> -                                 * numerical 32-bit values (cells) in
> -                                 * hexadecimal
> -				 */
> -  property4 = [0x0a 0x0b 0x0c 0x0d 0xde 0xea 0xad 0xbe 0xef];
> -                                /* define a property whose content is
> -                                 * an arbitrary array of bytes
> -                                 */
> -
> -  childnode@address {	/* define a child node named "childnode"
> -                                 * whose unit name is "childnode at
> -				 * address"
> -                                 */
> -
> -    childprop = "hello\n";      /* define a property "childprop" of
> -                                 * childnode (in this case, a string)
> -                                 */
> -  };
> -};
> -
> -Nodes can contain other nodes etc... thus defining the hierarchical
> -structure of the tree.
> -
> -Strings support common escape sequences from C: "\n", "\t", "\r",
> -"\(octal value)", "\x(hex value)".
> -
> -It is also suggested that you pipe your source file through cpp (gcc
> -preprocessor) so you can use #include's, #define for constants, etc...
> -
> -Finally, various options are planned but not yet implemented, like
> -automatic generation of phandles, labels (exported to the asm file so
> -you can point to a property content and change it easily from whatever
> -you link the device-tree with), label or path instead of numeric value
> -in some cells to "point" to a node (replaced by a phandle at compile
> -time), export of reserve map address to the asm file, ability to
> -specify reserve map content at compile time, etc...
> -
> -We may provide a .h include file with common definitions of that
> -proves useful for some properties (like building PCI properties or
> -interrupt maps) though it may be better to add a notion of struct
> -definitions to the compiler...
> -
> -
> -V - Recommendations for a bootloader
> -====================================
> -
> -
> -Here are some various ideas/recommendations that have been proposed
> -while all this has been defined and implemented.
> -
> -  - The bootloader may want to be able to use the device-tree itself
> -    and may want to manipulate it (to add/edit some properties,
> -    like physical memory size or kernel arguments). At this point, 2
> -    choices can be made. Either the bootloader works directly on the
> -    flattened format, or the bootloader has its own internal tree
> -    representation with pointers (similar to the kernel one) and
> -    re-flattens the tree when booting the kernel. The former is a bit
> -    more difficult to edit/modify, the later requires probably a bit
> -    more code to handle the tree structure. Note that the structure
> -    format has been designed so it's relatively easy to "insert"
> -    properties or nodes or delete them by just memmoving things
> -    around. It contains no internal offsets or pointers for this
> -    purpose.
> -
> -  - An example of code for iterating nodes & retrieving properties
> -    directly from the flattened tree format can be found in the kernel
> -    file drivers/of/fdt.c.  Look at the of_scan_flat_dt() function,
> -    its usage in early_init_devtree(), and the corresponding various
> -    early_init_dt_scan_*() callbacks. That code can be re-used in a
> -    GPL bootloader, and as the author of that code, I would be happy
> -    to discuss possible free licensing to any vendor who wishes to
> -    integrate all or part of this code into a non-GPL bootloader.
> -    (reference needed; who is 'I' here? ---gcl Jan 31, 2011)
> -
> -
> -
> -VI - System-on-a-chip devices and nodes
> -=======================================
> -
> -Many companies are now starting to develop system-on-a-chip
> -processors, where the processor core (CPU) and many peripheral devices
> -exist on a single piece of silicon.  For these SOCs, an SOC node
> -should be used that defines child nodes for the devices that make
> -up the SOC. While platforms are not required to use this model in
> -order to boot the kernel, it is highly encouraged that all SOC
> -implementations define as complete a flat-device-tree as possible to
> -describe the devices on the SOC.  This will allow for the
> -genericization of much of the kernel code.
> -
> -
> -1) Defining child nodes of an SOC
> ----------------------------------
> -
> -Each device that is part of an SOC may have its own node entry inside
> -the SOC node.  For each device that is included in the SOC, the unit
> -address property represents the address offset for this device's
> -memory-mapped registers in the parent's address space.  The parent's
> -address space is defined by the "ranges" property in the top-level soc
> -node. The "reg" property for each node that exists directly under the
> -SOC node should contain the address mapping from the child address space
> -to the parent SOC address space and the size of the device's
> -memory-mapped register file.
> -
> -For many devices that may exist inside an SOC, there are predefined
> -specifications for the format of the device tree node.  All SOC child
> -nodes should follow these specifications, except where noted in this
> -document.
> -
> -See appendix A for an example partial SOC node definition for the
> -MPC8540.
> -
> -
> -2) Representing devices without a current OF specification
> -----------------------------------------------------------
> -
> -Currently, there are many devices on SoCs that do not have a standard
> -representation defined as part of the Open Firmware specifications,
> -mainly because the boards that contain these SoCs are not currently
> -booted using Open Firmware.  Binding documentation for new devices
> -should be added to the Documentation/devicetree/bindings directory.
> -That directory will expand as device tree support is added to more and
> -more SoCs.
> -
> -
> -VII - Specifying interrupt information for devices
> -===================================================
> -
> -The device tree represents the buses and devices of a hardware
> -system in a form similar to the physical bus topology of the
> -hardware.
> -
> -In addition, a logical 'interrupt tree' exists which represents the
> -hierarchy and routing of interrupts in the hardware.
> -
> -The interrupt tree model is fully described in the
> -document "Open Firmware Recommended Practice: Interrupt
> -Mapping Version 0.9".  The document is available at:
> -<http://www.devicetree.org/open-firmware/practice/>
> -
> -1) interrupts property
> -----------------------
> -
> -Devices that generate interrupts to a single interrupt controller
> -should use the conventional OF representation described in the
> -OF interrupt mapping documentation.
> -
> -Each device which generates interrupts must have an 'interrupt'
> -property.  The interrupt property value is an arbitrary number of
> -of 'interrupt specifier' values which describe the interrupt or
> -interrupts for the device.
> -
> -The encoding of an interrupt specifier is determined by the
> -interrupt domain in which the device is located in the
> -interrupt tree.  The root of an interrupt domain specifies in
> -its #interrupt-cells property the number of 32-bit cells
> -required to encode an interrupt specifier.  See the OF interrupt
> -mapping documentation for a detailed description of domains.
> -
> -For example, the binding for the OpenPIC interrupt controller
> -specifies  an #interrupt-cells value of 2 to encode the interrupt
> -number and level/sense information. All interrupt children in an
> -OpenPIC interrupt domain use 2 cells per interrupt in their interrupts
> -property.
> -
> -The PCI bus binding specifies a #interrupt-cells value of 1 to encode
> -which interrupt pin (INTA,INTB,INTC,INTD) is used.
> -
> -2) interrupt-parent property
> -----------------------------
> -
> -The interrupt-parent property is specified to define an explicit
> -link between a device node and its interrupt parent in
> -the interrupt tree.  The value of interrupt-parent is the
> -phandle of the parent node.
> -
> -If the interrupt-parent property is not defined for a node, its
> -interrupt parent is assumed to be an ancestor in the node's
> -_device tree_ hierarchy.
> -
> -3) OpenPIC Interrupt Controllers
> ---------------------------------
> -
> -OpenPIC interrupt controllers require 2 cells to encode
> -interrupt information.  The first cell defines the interrupt
> -number.  The second cell defines the sense and level
> -information.
> -
> -Sense and level information should be encoded as follows:
> -
> -	0 = low to high edge sensitive type enabled
> -	1 = active low level sensitive type enabled
> -	2 = active high level sensitive type enabled
> -	3 = high to low edge sensitive type enabled
> -
> -4) ISA Interrupt Controllers
> -----------------------------
> -
> -ISA PIC interrupt controllers require 2 cells to encode
> -interrupt information.  The first cell defines the interrupt
> -number.  The second cell defines the sense and level
> -information.
> -
> -ISA PIC interrupt controllers should adhere to the ISA PIC
> -encodings listed below:
> -
> -	0 =  active low level sensitive type enabled
> -	1 =  active high level sensitive type enabled
> -	2 =  high to low edge sensitive type enabled
> -	3 =  low to high edge sensitive type enabled
>  
>  VIII - Specifying Device Power Management Information (sleep property)
>  ===================================================================
> @@ -1386,6 +491,7 @@ reasonably grouped in this manner, then create a virtual sleep controller
>  (similar to an interrupt nexus, except that defining a standardized
>  sleep-map should wait until its necessity is demonstrated).
>  
> +
>  IX - Specifying dma bus information
>  
>  Some devices may have DMA memory range shifted relatively to the beginning of
> @@ -1420,134 +526,3 @@ Optional property:
>  - dma-ranges: <empty> value. if present - It means that DMA addresses
>  	translation has to be enabled for this device.
>  - dma-coherent: Present if dma operations are coherent
> -
> -Example:
> -soc {
> -		compatible = "ti,keystone","simple-bus";
> -		ranges = <0x0 0x0 0x0 0xc0000000>;
> -		dma-ranges = <0x80000000 0x8 0x00000000 0x80000000>;
> -
> -		[...]
> -
> -		usb: usb@2680000 {
> -			compatible = "ti,keystone-dwc3";
> -
> -			[...]
> -			dma-coherent;
> -		};
> -};
> -
> -Appendix A - Sample SOC node for MPC8540
> -========================================
> -
> -	soc@e0000000 {
> -		#address-cells = <1>;
> -		#size-cells = <1>;
> -		compatible = "fsl,mpc8540-ccsr", "simple-bus";
> -		device_type = "soc";
> -		ranges = <0x00000000 0xe0000000 0x00100000>
> -		bus-frequency = <0>;
> -		interrupt-parent = <&pic>;
> -
> -		ethernet@24000 {
> -			#address-cells = <1>;
> -			#size-cells = <1>;
> -			device_type = "network";
> -			model = "TSEC";
> -			compatible = "gianfar", "simple-bus";
> -			reg = <0x24000 0x1000>;
> -			local-mac-address = [ 0x00 0xE0 0x0C 0x00 0x73 0x00 ];
> -			interrupts = <0x29 2 0x30 2 0x34 2>;
> -			phy-handle = <&phy0>;
> -			sleep = <&pmc 0x00000080>;
> -			ranges;
> -
> -			mdio@24520 {
> -				reg = <0x24520 0x20>;
> -				compatible = "fsl,gianfar-mdio";
> -
> -				phy0: ethernet-phy@0 {
> -					interrupts = <5 1>;
> -					reg = <0>;
> -				};
> -
> -				phy1: ethernet-phy@1 {
> -					interrupts = <5 1>;
> -					reg = <1>;
> -				};
> -
> -				phy3: ethernet-phy@3 {
> -					interrupts = <7 1>;
> -					reg = <3>;
> -				};
> -			};
> -		};
> -
> -		ethernet@25000 {
> -			device_type = "network";
> -			model = "TSEC";
> -			compatible = "gianfar";
> -			reg = <0x25000 0x1000>;
> -			local-mac-address = [ 0x00 0xE0 0x0C 0x00 0x73 0x01 ];
> -			interrupts = <0x13 2 0x14 2 0x18 2>;
> -			phy-handle = <&phy1>;
> -			sleep = <&pmc 0x00000040>;
> -		};
> -
> -		ethernet@26000 {
> -			device_type = "network";
> -			model = "FEC";
> -			compatible = "gianfar";
> -			reg = <0x26000 0x1000>;
> -			local-mac-address = [ 0x00 0xE0 0x0C 0x00 0x73 0x02 ];
> -			interrupts = <0x41 2>;
> -			phy-handle = <&phy3>;
> -			sleep = <&pmc 0x00000020>;
> -		};
> -
> -		serial@4500 {
> -			#address-cells = <1>;
> -			#size-cells = <1>;
> -			compatible = "fsl,mpc8540-duart", "simple-bus";
> -			sleep = <&pmc 0x00000002>;
> -			ranges;
> -
> -			serial@4500 {
> -				device_type = "serial";
> -				compatible = "ns16550";
> -				reg = <0x4500 0x100>;
> -				clock-frequency = <0>;
> -				interrupts = <0x42 2>;
> -			};
> -
> -			serial@4600 {
> -				device_type = "serial";
> -				compatible = "ns16550";
> -				reg = <0x4600 0x100>;
> -				clock-frequency = <0>;
> -				interrupts = <0x42 2>;
> -			};
> -		};
> -
> -		pic: pic@40000 {
> -			interrupt-controller;
> -			#address-cells = <0>;
> -			#interrupt-cells = <2>;
> -			reg = <0x40000 0x40000>;
> -			compatible = "chrp,open-pic";
> -			device_type = "open-pic";
> -		};
> -
> -		i2c@3000 {
> -			interrupts = <0x43 2>;
> -			reg = <0x3000 0x100>;
> -			compatible  = "fsl-i2c";
> -			dfsrr;
> -			sleep = <&pmc 0x00000004>;
> -		};
> -
> -		pmc: power@e0070 {
> -			compatible = "fsl,mpc8540-pmc", "fsl,mpc8548-pmc";
> -			reg = <0xe0070 0x20>;
> -		};
> -	};
> 


^ permalink raw reply

* [PATCH] powerpc/32: Stop printing the virtual memory layout
From: Arvind Sankar @ 2020-03-05 15:08 UTC (permalink / raw)
  To: Kees Cook
  Cc: Tycho Andersen, kernel-hardening, linux-kernel, Paul Mackerras,
	linuxppc-dev, Tobin C . Harding
In-Reply-To: <202003021038.8F0369D907@keescook>

For security, don't display the kernel's virtual memory layout.

Kees Cook points out:
"These have been entirely removed on other architectures, so let's
just do the same for ia32 and remove it unconditionally."

071929dbdd86 ("arm64: Stop printing the virtual memory layout")
1c31d4e96b8c ("ARM: 8820/1: mm: Stop printing the virtual memory layout")
31833332f798 ("m68k/mm: Stop printing the virtual memory layout")
fd8d0ca25631 ("parisc: Hide virtual kernel memory layout")
adb1fe9ae2ee ("mm/page_alloc: Remove kernel address exposure in free_reserved_area()")

Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
---
 arch/powerpc/mm/mem.c | 17 -----------------
 1 file changed, 17 deletions(-)

diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index ef7b1119b2e2..df2c143b6bf7 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -331,23 +331,6 @@ void __init mem_init(void)
 #endif
 
 	mem_init_print_info(NULL);
-#ifdef CONFIG_PPC32
-	pr_info("Kernel virtual memory layout:\n");
-#ifdef CONFIG_KASAN
-	pr_info("  * 0x%08lx..0x%08lx  : kasan shadow mem\n",
-		KASAN_SHADOW_START, KASAN_SHADOW_END);
-#endif
-	pr_info("  * 0x%08lx..0x%08lx  : fixmap\n", FIXADDR_START, FIXADDR_TOP);
-#ifdef CONFIG_HIGHMEM
-	pr_info("  * 0x%08lx..0x%08lx  : highmem PTEs\n",
-		PKMAP_BASE, PKMAP_ADDR(LAST_PKMAP));
-#endif /* CONFIG_HIGHMEM */
-	if (ioremap_bot != IOREMAP_TOP)
-		pr_info("  * 0x%08lx..0x%08lx  : early ioremap\n",
-			ioremap_bot, IOREMAP_TOP);
-	pr_info("  * 0x%08lx..0x%08lx  : vmalloc & ioremap\n",
-		VMALLOC_START, VMALLOC_END);
-#endif /* CONFIG_PPC32 */
 }
 
 void free_initmem(void)
-- 
2.24.1


^ permalink raw reply related

* Re: [PATCH] powerpc/32: Stop printing the virtual memory layout
From: Tycho Andersen @ 2020-03-05 20:50 UTC (permalink / raw)
  To: Arvind Sankar
  Cc: Kees Cook, kernel-hardening, linux-kernel, Paul Mackerras,
	linuxppc-dev, Tobin C . Harding
In-Reply-To: <20200305150837.835083-1-nivedita@alum.mit.edu>

On Thu, Mar 05, 2020 at 10:08:37AM -0500, Arvind Sankar wrote:
> For security, don't display the kernel's virtual memory layout.
> 
> Kees Cook points out:
> "These have been entirely removed on other architectures, so let's
> just do the same for ia32 and remove it unconditionally."
> 
> 071929dbdd86 ("arm64: Stop printing the virtual memory layout")
> 1c31d4e96b8c ("ARM: 8820/1: mm: Stop printing the virtual memory layout")
> 31833332f798 ("m68k/mm: Stop printing the virtual memory layout")
> fd8d0ca25631 ("parisc: Hide virtual kernel memory layout")
> adb1fe9ae2ee ("mm/page_alloc: Remove kernel address exposure in free_reserved_area()")
> 
> Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>

Acked-by: Tycho Andersen <tycho@tycho.ws>

^ permalink raw reply

* linux-next: manual merge of the net-next tree with the powerpc tree
From: Stephen Rothwell @ 2020-03-05 23:21 UTC (permalink / raw)
  To: David Miller, Networking, Michael Ellerman, PowerPC
  Cc: Christian Brauner, Linux Next Mailing List,
	Linux Kernel Mailing List, Sourabh Jain

[-- Attachment #1: Type: text/plain, Size: 3920 bytes --]

Hi all,

Today's linux-next merge of the net-next tree got a conflict in:

  fs/sysfs/group.c

between commit:

  9255782f7061 ("sysfs: Wrap __compat_only_sysfs_link_entry_to_kobj function to change the symlink name")

from the powerpc tree and commit:

  303a42769c4c ("sysfs: add sysfs_group{s}_change_owner()")

from the net-next tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

-- 
Cheers,
Stephen Rothwell

diff --cc fs/sysfs/group.c
index 1e2a096057bc,5afe0e7ff7cd..000000000000
--- a/fs/sysfs/group.c
+++ b/fs/sysfs/group.c
@@@ -478,4 -457,118 +479,118 @@@ int compat_only_sysfs_link_entry_to_kob
  	kernfs_put(target);
  	return PTR_ERR_OR_ZERO(link);
  }
 -EXPORT_SYMBOL_GPL(__compat_only_sysfs_link_entry_to_kobj);
 +EXPORT_SYMBOL_GPL(compat_only_sysfs_link_entry_to_kobj);
+ 
+ static int sysfs_group_attrs_change_owner(struct kernfs_node *grp_kn,
+ 					  const struct attribute_group *grp,
+ 					  struct iattr *newattrs)
+ {
+ 	struct kernfs_node *kn;
+ 	int error;
+ 
+ 	if (grp->attrs) {
+ 		struct attribute *const *attr;
+ 
+ 		for (attr = grp->attrs; *attr; attr++) {
+ 			kn = kernfs_find_and_get(grp_kn, (*attr)->name);
+ 			if (!kn)
+ 				return -ENOENT;
+ 
+ 			error = kernfs_setattr(kn, newattrs);
+ 			kernfs_put(kn);
+ 			if (error)
+ 				return error;
+ 		}
+ 	}
+ 
+ 	if (grp->bin_attrs) {
+ 		struct bin_attribute *const *bin_attr;
+ 
+ 		for (bin_attr = grp->bin_attrs; *bin_attr; bin_attr++) {
+ 			kn = kernfs_find_and_get(grp_kn, (*bin_attr)->attr.name);
+ 			if (!kn)
+ 				return -ENOENT;
+ 
+ 			error = kernfs_setattr(kn, newattrs);
+ 			kernfs_put(kn);
+ 			if (error)
+ 				return error;
+ 		}
+ 	}
+ 
+ 	return 0;
+ }
+ 
+ /**
+  * sysfs_group_change_owner - change owner of an attribute group.
+  * @kobj:	The kobject containing the group.
+  * @grp:	The attribute group.
+  * @kuid:	new owner's kuid
+  * @kgid:	new owner's kgid
+  *
+  * Returns 0 on success or error code on failure.
+  */
+ int sysfs_group_change_owner(struct kobject *kobj,
+ 			     const struct attribute_group *grp, kuid_t kuid,
+ 			     kgid_t kgid)
+ {
+ 	struct kernfs_node *grp_kn;
+ 	int error;
+ 	struct iattr newattrs = {
+ 		.ia_valid = ATTR_UID | ATTR_GID,
+ 		.ia_uid = kuid,
+ 		.ia_gid = kgid,
+ 	};
+ 
+ 	if (!kobj->state_in_sysfs)
+ 		return -EINVAL;
+ 
+ 	if (grp->name) {
+ 		grp_kn = kernfs_find_and_get(kobj->sd, grp->name);
+ 	} else {
+ 		kernfs_get(kobj->sd);
+ 		grp_kn = kobj->sd;
+ 	}
+ 	if (!grp_kn)
+ 		return -ENOENT;
+ 
+ 	error = kernfs_setattr(grp_kn, &newattrs);
+ 	if (!error)
+ 		error = sysfs_group_attrs_change_owner(grp_kn, grp, &newattrs);
+ 
+ 	kernfs_put(grp_kn);
+ 
+ 	return error;
+ }
+ EXPORT_SYMBOL_GPL(sysfs_group_change_owner);
+ 
+ /**
+  * sysfs_groups_change_owner - change owner of a set of attribute groups.
+  * @kobj:	The kobject containing the groups.
+  * @groups:	The attribute groups.
+  * @kuid:	new owner's kuid
+  * @kgid:	new owner's kgid
+  *
+  * Returns 0 on success or error code on failure.
+  */
+ int sysfs_groups_change_owner(struct kobject *kobj,
+ 			      const struct attribute_group **groups,
+ 			      kuid_t kuid, kgid_t kgid)
+ {
+ 	int error = 0, i;
+ 
+ 	if (!kobj->state_in_sysfs)
+ 		return -EINVAL;
+ 
+ 	if (!groups)
+ 		return 0;
+ 
+ 	for (i = 0; groups[i]; i++) {
+ 		error = sysfs_group_change_owner(kobj, groups[i], kuid, kgid);
+ 		if (error)
+ 			break;
+ 	}
+ 
+ 	return error;
+ }
+ EXPORT_SYMBOL_GPL(sysfs_groups_change_owner);

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply

* [RFC PATCH v2 1/1] powerpc/kernel: Enables memory hot-remove after reboot on pseries guests
From: Leonardo Bras @ 2020-03-05 23:32 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
	Allison Randal, Greg Kroah-Hartman, Leonardo Bras,
	Nathan Fontenot, Thomas Gleixner, Michael Anderson, Mike Rapoport,
	Claudio Carvalho, Hari Bathini, Christophe Leroy, bharata.rao
  Cc: linuxppc-dev, linux-kernel

While providing guests, it's desirable to resize it's memory on demand.

By now, it's possible to do so by creating a guest with a small base
memory, hot-plugging all the rest, and using 'movable_node' kernel
command-line parameter, which puts all hot-plugged memory in
ZONE_MOVABLE, allowing it to be removed whenever needed.

But there is an issue regarding guest reboot:
If memory is hot-plugged, and then the guest is rebooted, all hot-plugged
memory goes to ZONE_NORMAL, which offers no guaranteed hot-removal.
It usually prevents this memory to be hot-removed from the guest.

It's possible to use device-tree information to fix that behavior, as
it stores flags for LMB ranges on ibm,dynamic-memory-vN.
It involves marking each memblock with the correct flags as hotpluggable
memory, which mm/memblock.c puts in ZONE_MOVABLE during boot if
'movable_node' is passed.

For carrying such information, the new flag DRCONF_MEM_HOTPLUGGED is
proposed, which should be true if memory was hot-plugged on guest, and
false if it's base memory.

During boot, guest kernel reads the device-tree, early_init_drmem_lmb()
is called for every added LMBs. Here, checking for this new flag and
marking memblocks as hotplugable memory is enough to get the desirable
behavior.

This should cause no change if 'movable_node' parameter is not passed
in kernel command-line.

Signed-off-by: Leonardo Bras <leonardo@linux.ibm.com>

---
The new flag was already proposed on Power Architecture documentation,
and it's waiting for approval.

I would like to get your comments on this change, but it's still not
ready for being merged.

I will send the matching qemu change as a reply later.

Changes since v1:
- Adds new flag, so PowerVM is compatible with the change.
- Fixes mistakes in code
---
 arch/powerpc/include/asm/drmem.h | 1 +
 arch/powerpc/kernel/prom.c       | 9 +++++++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/include/asm/drmem.h b/arch/powerpc/include/asm/drmem.h
index 3d76e1c388c2..92083b4565f6 100644
--- a/arch/powerpc/include/asm/drmem.h
+++ b/arch/powerpc/include/asm/drmem.h
@@ -65,6 +65,7 @@ struct of_drconf_cell_v2 {
 #define DRCONF_MEM_ASSIGNED	0x00000008
 #define DRCONF_MEM_AI_INVALID	0x00000040
 #define DRCONF_MEM_RESERVED	0x00000080
+#define DRCONF_MEM_HOTPLUGGED	0x00000100
 
 static inline u32 drmem_lmb_size(void)
 {
diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
index 6620f37abe73..9c5cb2e8049e 100644
--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -515,9 +515,14 @@ static void __init early_init_drmem_lmb(struct drmem_lmb *lmb,
 				size = 0x80000000ul - base;
 		}
 
+		if (!validate_mem_limit(base, &size))
+			continue;
+
 		DBG("Adding: %llx -> %llx\n", base, size);
-		if (validate_mem_limit(base, &size))
-			memblock_add(base, size);
+		memblock_add(base, size);
+
+		if (lmb->flags & DRCONF_MEM_HOTPLUGGED)
+			memblock_mark_hotplug(base, size);
 	} while (--rngs);
 }
 #endif /* CONFIG_PPC_PSERIES */
-- 
2.24.1


^ permalink raw reply related

* Re: [PATCH v3 18/27] powerpc/powernv/pmem: Add controller dump IOCTLs
From: Alastair D'Silva @ 2020-03-05 23:37 UTC (permalink / raw)
  To: Frederic Barrat
  Cc: Madhavan Srinivasan, Alexey Kardashevskiy, Masahiro Yamada,
	Oliver O'Halloran, Mauro Carvalho Chehab, Ira Weiny,
	Thomas Gleixner, Rob Herring, Dave Jiang, linux-nvdimm,
	Aneesh Kumar K . V, Krzysztof Kozlowski, Anju T Sudhakar,
	Mahesh Salgaonkar, Andrew Donnellan, Arnd Bergmann, Greg Kurz,
	Nicholas Piggin, Cédric Le Goater, Dan Williams,
	Hari Bathini, linux-mm, Greg Kroah-Hartman, linux-kernel,
	Vishal Verma, Paul Mackerras, Andrew Morton, linuxppc-dev,
	David S. Miller
In-Reply-To: <6d1f28bc-334c-e85b-9974-71cf88a1ad20@linux.ibm.com>

On Tue, 2020-03-03 at 19:04 +0100, Frederic Barrat wrote:
> 
> Le 21/02/2020 à 04:27, Alastair D'Silva a écrit :
> > From: Alastair D'Silva <alastair@d-silva.org>
> > 
> > This patch adds IOCTLs to allow userspace to request & fetch dumps
> > of the internal controller state.
> > 
> > This is useful during debugging or when a fatal error on the
> > controller
> > has occurred.
> > 
> > Signed-off-by: Alastair D'Silva <alastair@d-silva.org>
> > ---
> >   arch/powerpc/platforms/powernv/pmem/ocxl.c | 132
> > +++++++++++++++++++++
> >   include/uapi/nvdimm/ocxl-pmem.h            |  15 +++
> >   2 files changed, 147 insertions(+)
> > 
> > diff --git a/arch/powerpc/platforms/powernv/pmem/ocxl.c
> > b/arch/powerpc/platforms/powernv/pmem/ocxl.c
> > index 2b64504f9129..2cabafe1fc58 100644
> > --- a/arch/powerpc/platforms/powernv/pmem/ocxl.c
> > +++ b/arch/powerpc/platforms/powernv/pmem/ocxl.c
> > @@ -640,6 +640,124 @@ static int ioctl_error_log(struct ocxlpmem
> > *ocxlpmem,
> >   	return 0;
> >   }
> >   
> > +static int ioctl_controller_dump_data(struct ocxlpmem *ocxlpmem,
> > +		struct ioctl_ocxl_pmem_controller_dump_data __user
> > *uarg)
> > +{
> > +	struct ioctl_ocxl_pmem_controller_dump_data args;
> > +	u16 i;
> > +	u64 val;
> > +	int rc;
> > +
> > +	if (copy_from_user(&args, uarg, sizeof(args)))
> > +		return -EFAULT;
> > +
> > +	if (args.buf_size % 8)
> > +		return -EINVAL;
> > +
> > +	if (args.buf_size > ocxlpmem->admin_command.data_size)
> > +		return -EINVAL;
> > +
> > +	mutex_lock(&ocxlpmem->admin_command.lock);
> > +
> > +	rc = admin_command_request(ocxlpmem,
> > ADMIN_COMMAND_CONTROLLER_DUMP);
> > +	if (rc)
> > +		goto out;
> > +
> > +	val = ((u64)args.offset) << 32;
> > +	val |= args.buf_size;
> > +	rc = ocxl_global_mmio_write64(ocxlpmem->ocxl_afu,
> > +				      ocxlpmem-
> > >admin_command.request_offset + 0x08,
> > +				      OCXL_LITTLE_ENDIAN, val);
> > +	if (rc)
> > +		goto out;
> > +
> > +	rc = admin_command_execute(ocxlpmem);
> > +	if (rc)
> > +		goto out;
> > +
> > +	rc = admin_command_complete_timeout(ocxlpmem,
> > +					    ADMIN_COMMAND_CONTROLLER_DU
> > MP);
> > +	if (rc < 0) {
> > +		dev_warn(&ocxlpmem->dev, "Controller dump timed
> > out\n");
> > +		goto out;
> > +	}
> > +
> > +	rc = admin_response(ocxlpmem);
> > +	if (rc < 0)
> > +		goto out;
> > +	if (rc != STATUS_SUCCESS) {
> > +		warn_status(ocxlpmem,
> > +			    "Unexpected status from retrieve error
> > log",
> > +			    rc);
> > +		goto out;
> > +	}
> 
> 
> It would help if there was a comment indicating how the 3 ioctls are 
> used. My understanding is that the userland is:
> - requesting the controller to prepare a state dump
> - then one or more ioctls to fetch the data. The number of calls 
> required to get the full state really depends on the size of the
> buffer 
> passed by user
> - a last ioctl to tell the controller that we're done, presumably to
> let 
> it free some resources.
> 

Ok, will add it to the blurb.
> 
> > +
> > +	for (i = 0; i < args.buf_size; i += 8) {
> > +		u64 val;
> > +
> > +		rc = ocxl_global_mmio_read64(ocxlpmem->ocxl_afu,
> > +					     ocxlpmem-
> > >admin_command.data_offset + i,
> > +					     OCXL_HOST_ENDIAN, &val);
> > +		if (rc)
> > +			goto out;
> > +
> > +		if (copy_to_user(&args.buf[i], &val, sizeof(u64))) {
> > +			rc = -EFAULT;
> > +			goto out;
> > +		}
> > +	}
> > +
> > +	if (copy_to_user(uarg, &args, sizeof(args))) {
> > +		rc = -EFAULT;
> > +		goto out;
> > +	}
> > +
> > +	rc = admin_response_handled(ocxlpmem);
> > +	if (rc)
> > +		goto out;
> > +
> > +out:
> > +	mutex_unlock(&ocxlpmem->admin_command.lock);
> > +	return rc;
> > +}
> > +
> > +int request_controller_dump(struct ocxlpmem *ocxlpmem)
> > +{
> > +	int rc;
> > +	u64 busy = 1;
> > +
> > +	rc = ocxl_global_mmio_set64(ocxlpmem->ocxl_afu,
> > GLOBAL_MMIO_CHIC,
> > +				    OCXL_LITTLE_ENDIAN,
> > +				    GLOBAL_MMIO_CHI_CDA);
> > +
> 
> rc is not checked here.

Whoops

> 
> 
> > +
> > +	rc = ocxl_global_mmio_set64(ocxlpmem->ocxl_afu,
> > GLOBAL_MMIO_HCI,
> > +				    OCXL_LITTLE_ENDIAN,
> > +				    GLOBAL_MMIO_HCI_CONTROLLER_DUMP);
> > +	if (rc)
> > +		return rc;
> > +
> > +	while (busy) {
> > +		rc = ocxl_global_mmio_read64(ocxlpmem->ocxl_afu,
> > +					     GLOBAL_MMIO_HCI,
> > +					     OCXL_LITTLE_ENDIAN,
> > &busy);
> > +		if (rc)
> > +			return rc;
> > +
> > +		busy &= GLOBAL_MMIO_HCI_CONTROLLER_DUMP;
> 
> Setting 'busy' doesn't hurt, but it's not really useful, is it?
> 
> We should add some kind of timeout so that if the controller hits an 
> issue, we don't spin in kernel space endlessly.
> 
> 

Here we are polling the controller dump bit of the HCI register until
the controller clears it - that line is masking off the bits we don't
care about.

I'll talk to the firmware team about adding a timeout for that to the
spec so we know how long to wait for before giving up.

> 
> > +		cond_resched();
> > +	}
> > +
> > +	return 0;
> > +}

> > +
> > +static int ioctl_controller_dump_complete(struct ocxlpmem
> > *ocxlpmem)
> > +{
> > +	return ocxl_global_mmio_set64(ocxlpmem->ocxl_afu,
> > GLOBAL_MMIO_HCI,
> > +				    OCXL_LITTLE_ENDIAN,
> > +				    GLOBAL_MMIO_HCI_CONTROLLER_DUMP_COL
> > LECTED);
> > +}
> > +
> >   static long file_ioctl(struct file *file, unsigned int cmd,
> > unsigned long args)
> >   {
> >   	struct ocxlpmem *ocxlpmem = file->private_data;
> > @@ -650,7 +768,21 @@ static long file_ioctl(struct file *file,
> > unsigned int cmd, unsigned long args)
> >   		rc = ioctl_error_log(ocxlpmem,
> >   				     (struct ioctl_ocxl_pmem_error_log
> > __user *)args);
> >   		break;
> > +
> > +	case IOCTL_OCXL_PMEM_CONTROLLER_DUMP:
> > +		rc = request_controller_dump(ocxlpmem);
> > +		break;
> > +
> > +	case IOCTL_OCXL_PMEM_CONTROLLER_DUMP_DATA:
> > +		rc = ioctl_controller_dump_data(ocxlpmem,
> > +						(struct
> > ioctl_ocxl_pmem_controller_dump_data __user *)args);
> > +		break;
> > +
> > +	case IOCTL_OCXL_PMEM_CONTROLLER_DUMP_COMPLETE:
> > +		rc = ioctl_controller_dump_complete(ocxlpmem);
> > +		break;
> >   	}
> > +
> >   	return rc;
> >   }
> >   
> > diff --git a/include/uapi/nvdimm/ocxl-pmem.h
> > b/include/uapi/nvdimm/ocxl-pmem.h
> > index b10f8ac0c20f..d4d8512d03f7 100644
> > --- a/include/uapi/nvdimm/ocxl-pmem.h
> > +++ b/include/uapi/nvdimm/ocxl-pmem.h
> > @@ -38,9 +38,24 @@ struct ioctl_ocxl_pmem_error_log {
> >   	__u8 *buf; /* pointer to output buffer */
> >   };
> >   
> > +struct ioctl_ocxl_pmem_controller_dump_data {
> > +	__u8 *buf; /* pointer to output buffer */
> 
> We only support 64-bit user app on powerpc, but using a pointer type
> in 
> a kernel ABI is unusual. We should use a know size like __u64.
> (also applies to buf pointer in struct ioctl_ocxl_pmem_error_log
> from 
> previous patch too)
> 
> The rest of the structure will also be padded by the compiler, which
> we 
> should avoid.
> 
>     Fred
> 

Ok, I'll co-erce the pointers into a __u64.

> 
> 
> > +	__u16 buf_size; /* in/out, buffer size provided/required.
> > +			 * If required is greater than provided, the
> > buffer
> > +			 * will be truncated to the amount provided. If
> > its
> > +			 * less, then only the required bytes will be
> > populated.
> > +			 * If it is 0, then there is no more dump data
> > available.
> > +			 */
> > +	__u32 offset; /* in, Offset within the dump */
> > +	__u64 reserved[8];
> > +};
> > +
> >   /* ioctl numbers */
> >   #define OCXL_PMEM_MAGIC 0x5C
> >   /* SCM devices */
> >   #define IOCTL_OCXL_PMEM_ERROR_LOG			_IOWR(OCXL_PMEM
> > _MAGIC, 0x01, struct ioctl_ocxl_pmem_error_log)
> > +#define IOCTL_OCXL_PMEM_CONTROLLER_DUMP			_IO(OCX
> > L_PMEM_MAGIC, 0x02)
> > +#define IOCTL_OCXL_PMEM_CONTROLLER_DUMP_DATA		_IOWR(O
> > CXL_PMEM_MAGIC, 0x03, struct ioctl_ocxl_pmem_controller_dump_data)
> > +#define IOCTL_OCXL_PMEM_CONTROLLER_DUMP_COMPLETE	_IO(OCXL_PMEM_M
> > AGIC, 0x04)
> >   
> >   #endif /* _UAPI_OCXL_SCM_H */
> > 
-- 
Alastair D'Silva
Open Source Developer
Linux Technology Centre, IBM Australia
mob: 0423 762 819


^ permalink raw reply

* [PATCH V15] mm/debug: Add tests validating architecture page table helpers
From: Anshuman Khandual @ 2020-03-05 23:57 UTC (permalink / raw)
  To: linux-mm
  Cc: Heiko Carstens, Paul Mackerras, H. Peter Anvin, linux-riscv,
	Will Deacon, linux-arch, linux-s390, x86, Mike Rapoport,
	Christian Borntraeger, Ingo Molnar, Catalin Marinas,
	linux-snps-arc, Vasily Gorbik, Anshuman Khandual, Borislav Petkov,
	Paul Walmsley, Kirill A . Shutemov, Thomas Gleixner,
	linux-arm-kernel, Vineet Gupta, linux-kernel, Palmer Dabbelt,
	Qian Cai, Andrew Morton, linuxppc-dev

This adds tests which will validate architecture page table helpers and
other accessors in their compliance with expected generic MM semantics.
This will help various architectures in validating changes to existing
page table helpers or addition of new ones.

This test covers basic page table entry transformations including but not
limited to old, young, dirty, clean, write, write protect etc at various
level along with populating intermediate entries with next page table page
and validating them.

Test page table pages are allocated from system memory with required size
and alignments. The mapped pfns at page table levels are derived from a
real pfn representing a valid kernel text symbol. This test gets called
inside kernel_init() right after async_synchronize_full().

This test gets built and run when CONFIG_DEBUG_VM_PGTABLE is selected. Any
architecture, which is willing to subscribe this test will need to select
ARCH_HAS_DEBUG_VM_PGTABLE. For now this is limited to arc, arm64, x86, s390
and ppc32 platforms where the test is known to build and run successfully.
Going forward, other architectures too can subscribe the test after fixing
any build or runtime problems with their page table helpers. Meanwhile for
better platform coverage, the test can also be enabled with CONFIG_EXPERT
even without ARCH_HAS_DEBUG_VM_PGTABLE.

Folks interested in making sure that a given platform's page table helpers
conform to expected generic MM semantics should enable the above config
which will just trigger this test during boot. Any non conformity here will
be reported as an warning which would need to be fixed. This test will help
catch any changes to the agreed upon semantics expected from generic MM and
enable platforms to accommodate it thereafter.

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Mike Rapoport <rppt@linux.ibm.com>
Cc: Vineet Gupta <vgupta@synopsys.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Kirill A. Shutemov <kirill@shutemov.name>
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: linux-snps-arc@lists.infradead.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-s390@vger.kernel.org
Cc: linux-riscv@lists.infradead.org
Cc: x86@kernel.org
Cc: linux-arch@vger.kernel.org
Cc: linux-kernel@vger.kernel.org

Suggested-by: Catalin Marinas <catalin.marinas@arm.com>
Reviewed-by: Ingo Molnar <mingo@kernel.org>
Tested-by: Gerald Schaefer <gerald.schaefer@de.ibm.com>	# s390
Tested-by: Christophe Leroy <christophe.leroy@c-s.fr>	# ppc32
Signed-off-by: Qian Cai <cai@lca.pw>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
This adds a test validation for architecture exported page table helpers.
Patch adds basic transformation tests at various levels of the page table.

This test was originally suggested by Catalin during arm64 THP migration
RFC discussion earlier. Going forward it can include more specific tests
with respect to various generic MM functions like THP, HugeTLB etc and
platform specific tests.

https://lore.kernel.org/linux-mm/20190628102003.GA56463@arrakis.emea.arm.com/

Needs to be applied on linux V5.6-rc4

Changes in V15:

- Replaced __pa() with __pa_symbol() (https://patchwork.kernel.org/patch/11407715/) 
- Replaced pte_alloc_map() with pte_alloc_map_lock() per Qian
- Replaced pte_unmap() with pte_unmap_unlock() per Qian
- Added address to pte_clear_tests() and passed it down till pte_clear() per Qian

Changes in V14: (https://patchwork.kernel.org/project/linux-mm/list/?series=242305)

- Disabled DEBUG_VM_PGTABLE for IA64 and ARM (32 Bit) per Andrew and Christophe
- Updated DEBUG_VM_PGTABLE documentation wrt EXPERT and disabled platforms
- Updated RANDOM_[OR|NZ]VALUE open encodings with GENMASK() per Catalin
- Updated s390 constraint bits from 12 to 4 (S390_MASK_BITS) per Gerald
- Updated in-code documentation for RANDOM_ORVALUE per Gerald
- Updated pxx_basic_tests() to use invert functions first per Catalin
- Dropped ARCH_HAS_4LEVEL_HACK check from pud_basic_tests()
- Replaced __ARCH_HAS_[4|5]LEVEL_HACK with __PAGETABLE_[PUD|P4D]_FOLDED per Catalin
- Trimmed the CC list on the commit message per Catalin

Changes in V13: (https://patchwork.kernel.org/project/linux-mm/list/?series=237125)

- Subscribed s390 platform and updated debug-vm-pgtable/arch-support.txt per Gerald
- Dropped keyword 'extern' from debug_vm_pgtable() declaration per Christophe
- Moved debug_vm_pgtable() declarations to <linux/mmdebug.h> per Christophe
- Moved debug_vm_pgtable() call site into kernel_init() per Christophe
- Changed CONFIG_DEBUG_VM_PGTABLE rules per Christophe
- Updated commit to include new supported platforms and changed config selection

Changes in V12: (https://patchwork.kernel.org/project/linux-mm/list/?series=233905)

- Replaced __mmdrop() with mmdrop()
- Enable ARCH_HAS_DEBUG_VM_PGTABLE on X86 for non CONFIG_X86_PAE platforms as the
  test procedure interfere with pre-allocated PMDs attached to the PGD resulting
  in runtime failures with VM_BUG_ON()

Changes in V11: (https://patchwork.kernel.org/project/linux-mm/list/?series=221135)

- Rebased the patch on V5.4

Changes in V10: (https://patchwork.kernel.org/project/linux-mm/list/?series=205529)

- Always enable DEBUG_VM_PGTABLE when DEBUG_VM is enabled per Ingo
- Added tags from Ingo

Changes in V9: (https://patchwork.kernel.org/project/linux-mm/list/?series=201429)

- Changed feature support enumeration for powerpc platforms per Christophe
- Changed config wrapper for basic_[pmd|pud]_tests() to enable ARC platform
- Enabled the test on ARC platform

Changes in V8: (https://patchwork.kernel.org/project/linux-mm/list/?series=194297)

- Enabled ARCH_HAS_DEBUG_VM_PGTABLE on PPC32 platform per Christophe
- Updated feature documentation as DEBUG_VM_PGTABLE is now enabled on PPC32 platform
- Moved ARCH_HAS_DEBUG_VM_PGTABLE earlier to indent it with DEBUG_VM per Christophe
- Added an information message in debug_vm_pgtable() per Christophe
- Dropped random_vaddr boundary condition checks per Christophe and Qian
- Replaced virt_addr_valid() check with pfn_valid() check in debug_vm_pgtable()
- Slightly changed pr_fmt(fmt) information

Changes in V7: (https://patchwork.kernel.org/project/linux-mm/list/?series=193051)

- Memory allocation and free routines for mapped pages have been droped
- Mapped pfns are derived from standard kernel text symbol per Matthew
- Moved debug_vm_pgtaable() after page_alloc_init_late() per Michal and Qian 
- Updated the commit message per Michal
- Updated W=1 GCC warning problem on x86 per Qian Cai
- Addition of new alloc_contig_pages() helper has been submitted separately

Changes in V6: (https://patchwork.kernel.org/project/linux-mm/list/?series=187589)

- Moved alloc_gigantic_page_order() into mm/page_alloc.c per Michal
- Moved alloc_gigantic_page_order() within CONFIG_CONTIG_ALLOC in the test
- Folded Andrew's include/asm-generic/pgtable.h fix into the test patch 2/2

Changes in V5: (https://patchwork.kernel.org/project/linux-mm/list/?series=185991)

- Redefined and moved X86 mm_p4d_folded() into a different header per Kirill/Ingo
- Updated the config option comment per Ingo and dropped 'kernel module' reference
- Updated the commit message and dropped 'kernel module' reference
- Changed DEBUG_ARCH_PGTABLE_TEST into DEBUG_VM_PGTABLE per Ingo
- Moved config option from mm/Kconfig.debug into lib/Kconfig.debug
- Renamed core test function arch_pgtable_tests() as debug_vm_pgtable()
- Renamed mm/arch_pgtable_test.c as mm/debug_vm_pgtable.c
- debug_vm_pgtable() gets called from kernel_init_freeable() after init_mm_internals()
- Added an entry in Documentation/features/debug/ per Ingo
- Enabled the test on arm64 and x86 platforms for now

Changes in V4: (https://patchwork.kernel.org/project/linux-mm/list/?series=183465)

- Disable DEBUG_ARCH_PGTABLE_TEST for ARM and IA64 platforms

Changes in V3: (https://lore.kernel.org/patchwork/project/lkml/list/?series=411216)

- Changed test trigger from module format into late_initcall()
- Marked all functions with __init to be freed after completion
- Changed all __PGTABLE_PXX_FOLDED checks as mm_pxx_folded()
- Folded in PPC32 fixes from Christophe

Changes in V2:

https://lore.kernel.org/linux-mm/1568268173-31302-1-git-send-email-anshuman.khandual@arm.com/T/#t

- Fixed small typo error in MODULE_DESCRIPTION()
- Fixed m64k build problems for lvalue concerns in pmd_xxx_tests()
- Fixed dynamic page table level folding problems on x86 as per Kirril
- Fixed second pointers during pxx_populate_tests() per Kirill and Gerald
- Allocate and free pte table with pte_alloc_one/pte_free per Kirill
- Modified pxx_clear_tests() to accommodate s390 lower 12 bits situation
- Changed RANDOM_NZVALUE value from 0xbe to 0xff
- Changed allocation, usage, free sequence for saved_ptep
- Renamed VMA_FLAGS as VMFLAGS
- Implemented a new method for random vaddr generation
- Implemented some other cleanups
- Dropped extern reference to mm_alloc()
- Created and exported new alloc_gigantic_page_order()
- Dropped the custom allocator and used new alloc_gigantic_page_order()

Changes in V1:

https://lore.kernel.org/linux-mm/1567497706-8649-1-git-send-email-anshuman.khandual@arm.com/

- Added fallback mechanism for PMD aligned memory allocation failure

Changes in RFC V2:

https://lore.kernel.org/linux-mm/1565335998-22553-1-git-send-email-anshuman.khandual@arm.com/T/#u

- Moved test module and it's config from lib/ to mm/
- Renamed config TEST_ARCH_PGTABLE as DEBUG_ARCH_PGTABLE_TEST
- Renamed file from test_arch_pgtable.c to arch_pgtable_test.c
- Added relevant MODULE_DESCRIPTION() and MODULE_AUTHOR() details
- Dropped loadable module config option
- Basic tests now use memory blocks with required size and alignment
- PUD aligned memory block gets allocated with alloc_contig_range()
- If PUD aligned memory could not be allocated it falls back on PMD aligned
  memory block from page allocator and pud_* tests are skipped
- Clear and populate tests now operate on real in memory page table entries
- Dummy mm_struct gets allocated with mm_alloc()
- Dummy page table entries get allocated with [pud|pmd|pte]_alloc_[map]()
- Simplified [p4d|pgd]_basic_tests(), now has random values in the entries

Original RFC V1:

https://lore.kernel.org/linux-mm/1564037723-26676-1-git-send-email-anshuman.khandual@arm.com/

 .../debug/debug-vm-pgtable/arch-support.txt        |  35 ++
 arch/arc/Kconfig                                   |   1 +
 arch/arm64/Kconfig                                 |   1 +
 arch/powerpc/Kconfig                               |   1 +
 arch/s390/Kconfig                                  |   1 +
 arch/x86/Kconfig                                   |   1 +
 arch/x86/include/asm/pgtable_64.h                  |   6 +
 include/linux/mmdebug.h                            |   5 +
 init/main.c                                        |   2 +
 lib/Kconfig.debug                                  |  26 ++
 mm/Makefile                                        |   1 +
 mm/debug_vm_pgtable.c                              | 391 +++++++++++++++++++++
 12 files changed, 471 insertions(+)
 create mode 100644 Documentation/features/debug/debug-vm-pgtable/arch-support.txt
 create mode 100644 mm/debug_vm_pgtable.c

diff --git a/Documentation/features/debug/debug-vm-pgtable/arch-support.txt b/Documentation/features/debug/debug-vm-pgtable/arch-support.txt
new file mode 100644
index 0000000..64d0f9b
--- /dev/null
+++ b/Documentation/features/debug/debug-vm-pgtable/arch-support.txt
@@ -0,0 +1,35 @@
+#
+# Feature name:          debug-vm-pgtable
+#         Kconfig:       ARCH_HAS_DEBUG_VM_PGTABLE
+#         description:   arch supports pgtable tests for semantics compliance
+#
+    -----------------------
+    |         arch |status|
+    -----------------------
+    |       alpha: | TODO |
+    |         arc: |  ok  |
+    |         arm: | TODO |
+    |       arm64: |  ok  |
+    |         c6x: | TODO |
+    |        csky: | TODO |
+    |       h8300: | TODO |
+    |     hexagon: | TODO |
+    |        ia64: | TODO |
+    |        m68k: | TODO |
+    |  microblaze: | TODO |
+    |        mips: | TODO |
+    |       nds32: | TODO |
+    |       nios2: | TODO |
+    |    openrisc: | TODO |
+    |      parisc: | TODO |
+    |  powerpc/32: |  ok  |
+    |  powerpc/64: | TODO |
+    |       riscv: | TODO |
+    |        s390: |  ok  |
+    |          sh: | TODO |
+    |       sparc: | TODO |
+    |          um: | TODO |
+    |   unicore32: | TODO |
+    |         x86: |  ok  |
+    |      xtensa: | TODO |
+    -----------------------
diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig
index ff2a393..3e72e6c 100644
--- a/arch/arc/Kconfig
+++ b/arch/arc/Kconfig
@@ -6,6 +6,7 @@
 config ARC
 	def_bool y
 	select ARC_TIMERS
+	select ARCH_HAS_DEBUG_VM_PGTABLE
 	select ARCH_HAS_DMA_PREP_COHERENT
 	select ARCH_HAS_PTE_SPECIAL
 	select ARCH_HAS_SETUP_DMA_OPS
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 0b30e88..aaf8ba4 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -11,6 +11,7 @@ config ARM64
 	select ACPI_PPTT if ACPI
 	select ARCH_CLOCKSOURCE_DATA
 	select ARCH_HAS_DEBUG_VIRTUAL
+	select ARCH_HAS_DEBUG_VM_PGTABLE
 	select ARCH_HAS_DEVMEM_IS_ALLOWED
 	select ARCH_HAS_DMA_PREP_COHERENT
 	select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 497b7d0b..8d5ae14 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -116,6 +116,7 @@ config PPC
 	#
 	select ARCH_32BIT_OFF_T if PPC32
 	select ARCH_HAS_DEBUG_VIRTUAL
+	select ARCH_HAS_DEBUG_VM_PGTABLE if PPC32
 	select ARCH_HAS_DEVMEM_IS_ALLOWED
 	select ARCH_HAS_ELF_RANDOMIZE
 	select ARCH_HAS_FORTIFY_SOURCE
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index 8abe775..af284db 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -59,6 +59,7 @@ config KASAN_SHADOW_OFFSET
 config S390
 	def_bool y
 	select ARCH_BINFMT_ELF_STATE
+	select ARCH_HAS_DEBUG_VM_PGTABLE
 	select ARCH_HAS_DEVMEM_IS_ALLOWED
 	select ARCH_HAS_ELF_RANDOMIZE
 	select ARCH_HAS_FORTIFY_SOURCE
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index beea770..df8a19e5 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -61,6 +61,7 @@ config X86
 	select ARCH_CLOCKSOURCE_INIT
 	select ARCH_HAS_ACPI_TABLE_UPGRADE	if ACPI
 	select ARCH_HAS_DEBUG_VIRTUAL
+	select ARCH_HAS_DEBUG_VM_PGTABLE	if !X86_PAE
 	select ARCH_HAS_DEVMEM_IS_ALLOWED
 	select ARCH_HAS_ELF_RANDOMIZE
 	select ARCH_HAS_FAST_MULTIPLIER
diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
index 0b6c4042..fb0e76d 100644
--- a/arch/x86/include/asm/pgtable_64.h
+++ b/arch/x86/include/asm/pgtable_64.h
@@ -53,6 +53,12 @@ static inline void sync_initial_page_table(void) { }
 
 struct mm_struct;
 
+#define mm_p4d_folded mm_p4d_folded
+static inline bool mm_p4d_folded(struct mm_struct *mm)
+{
+	return !pgtable_l5_enabled();
+}
+
 void set_pte_vaddr_p4d(p4d_t *p4d_page, unsigned long vaddr, pte_t new_pte);
 void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte);
 
diff --git a/include/linux/mmdebug.h b/include/linux/mmdebug.h
index 2ad72d2c8..5339aa1 100644
--- a/include/linux/mmdebug.h
+++ b/include/linux/mmdebug.h
@@ -64,4 +64,9 @@ void dump_mm(const struct mm_struct *mm);
 #define VM_BUG_ON_PGFLAGS(cond, page) BUILD_BUG_ON_INVALID(cond)
 #endif
 
+#ifdef CONFIG_DEBUG_VM_PGTABLE
+void debug_vm_pgtable(void);
+#else
+static inline void debug_vm_pgtable(void) { }
+#endif
 #endif
diff --git a/init/main.c b/init/main.c
index ee4947a..19cd790 100644
--- a/init/main.c
+++ b/init/main.c
@@ -94,6 +94,7 @@
 #include <linux/rodata_test.h>
 #include <linux/jump_label.h>
 #include <linux/mem_encrypt.h>
+#include <linux/mmdebug.h>
 
 #include <asm/io.h>
 #include <asm/bugs.h>
@@ -1352,6 +1353,7 @@ static int __ref kernel_init(void *unused)
 	kernel_init_freeable();
 	/* need to finish all async __init code before freeing the memory */
 	async_synchronize_full();
+	debug_vm_pgtable();
 	ftrace_free_init_mem();
 	free_initmem();
 	mark_readonly();
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 69def4a..1b5bd9f 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -653,6 +653,12 @@ config SCHED_STACK_END_CHECK
 	  data corruption or a sporadic crash at a later stage once the region
 	  is examined. The runtime overhead introduced is minimal.
 
+config ARCH_HAS_DEBUG_VM_PGTABLE
+	bool
+	help
+	  An architecture should select this when it can successfully
+	  build and run DEBUG_VM_PGTABLE.
+
 config DEBUG_VM
 	bool "Debug VM"
 	depends on DEBUG_KERNEL
@@ -688,6 +694,26 @@ config DEBUG_VM_PGFLAGS
 
 	  If unsure, say N.
 
+config DEBUG_VM_PGTABLE
+	bool "Debug arch page table for semantics compliance"
+	depends on MMU
+	depends on !IA64 && !ARM
+	depends on ARCH_HAS_DEBUG_VM_PGTABLE || EXPERT
+	default n if !ARCH_HAS_DEBUG_VM_PGTABLE
+	default y if DEBUG_VM
+	help
+	  This option provides a debug method which can be used to test
+	  architecture page table helper functions on various platforms in
+	  verifying if they comply with expected generic MM semantics. This
+	  will help architecture code in making sure that any changes or
+	  new additions of these helpers still conform to expected
+	  semantics of the generic MM. Platforms will have to opt in for
+	  this through ARCH_HAS_DEBUG_VM_PGTABLE. Although it can also be
+	  enabled through EXPERT without requiring code change. This test
+	  is disabled on IA64 and ARM platforms where it fails to build.
+
+	  If unsure, say N.
+
 config ARCH_HAS_DEBUG_VIRTUAL
 	bool
 
diff --git a/mm/Makefile b/mm/Makefile
index 272e660..b0692e6 100644
--- a/mm/Makefile
+++ b/mm/Makefile
@@ -87,6 +87,7 @@ obj-$(CONFIG_HWPOISON_INJECT) += hwpoison-inject.o
 obj-$(CONFIG_DEBUG_KMEMLEAK) += kmemleak.o
 obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak-test.o
 obj-$(CONFIG_DEBUG_RODATA_TEST) += rodata_test.o
+obj-$(CONFIG_DEBUG_VM_PGTABLE) += debug_vm_pgtable.o
 obj-$(CONFIG_PAGE_OWNER) += page_owner.o
 obj-$(CONFIG_CLEANCACHE) += cleancache.o
 obj-$(CONFIG_MEMORY_ISOLATION) += page_isolation.o
diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c
new file mode 100644
index 0000000..96a91bd
--- /dev/null
+++ b/mm/debug_vm_pgtable.c
@@ -0,0 +1,391 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * This kernel test validates architecture page table helpers and
+ * accessors and helps in verifying their continued compliance with
+ * expected generic MM semantics.
+ *
+ * Copyright (C) 2019 ARM Ltd.
+ *
+ * Author: Anshuman Khandual <anshuman.khandual@arm.com>
+ */
+#define pr_fmt(fmt) "debug_vm_pgtable: %s: " fmt, __func__
+
+#include <linux/gfp.h>
+#include <linux/highmem.h>
+#include <linux/hugetlb.h>
+#include <linux/kernel.h>
+#include <linux/kconfig.h>
+#include <linux/mm.h>
+#include <linux/mman.h>
+#include <linux/mm_types.h>
+#include <linux/module.h>
+#include <linux/pfn_t.h>
+#include <linux/printk.h>
+#include <linux/random.h>
+#include <linux/spinlock.h>
+#include <linux/swap.h>
+#include <linux/swapops.h>
+#include <linux/start_kernel.h>
+#include <linux/sched/mm.h>
+#include <asm/pgalloc.h>
+#include <asm/pgtable.h>
+
+/*
+ * Basic operations
+ *
+ * mkold(entry)			= An old and not a young entry
+ * mkyoung(entry)		= A young and not an old entry
+ * mkdirty(entry)		= A dirty and not a clean entry
+ * mkclean(entry)		= A clean and not a dirty entry
+ * mkwrite(entry)		= A write and not a write protected entry
+ * wrprotect(entry)		= A write protected and not a write entry
+ * pxx_bad(entry)		= A mapped and non-table entry
+ * pxx_same(entry1, entry2)	= Both entries hold the exact same value
+ */
+#define VMFLAGS	(VM_READ|VM_WRITE|VM_EXEC)
+
+/*
+ * On s390 platform, the lower 4 bits are used to identify given page table
+ * entry type. But these bits might affect the ability to clear entries with
+ * pxx_clear() because of how dynamic page table folding works on s390. So
+ * while loading up the entries do not change the lower 4 bits. It does not
+ * have affect any other platform.
+ */
+#define S390_MASK_BITS	4
+#define RANDOM_ORVALUE	GENMASK(BITS_PER_LONG - 1, S390_MASK_BITS)
+#define RANDOM_NZVALUE	GENMASK(7, 0)
+
+static void __init pte_basic_tests(unsigned long pfn, pgprot_t prot)
+{
+	pte_t pte = pfn_pte(pfn, prot);
+
+	WARN_ON(!pte_same(pte, pte));
+	WARN_ON(!pte_young(pte_mkyoung(pte_mkold(pte))));
+	WARN_ON(!pte_dirty(pte_mkdirty(pte_mkclean(pte))));
+	WARN_ON(!pte_write(pte_mkwrite(pte_wrprotect(pte))));
+	WARN_ON(pte_young(pte_mkold(pte_mkyoung(pte))));
+	WARN_ON(pte_dirty(pte_mkclean(pte_mkdirty(pte))));
+	WARN_ON(pte_write(pte_wrprotect(pte_mkwrite(pte))));
+}
+
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+static void __init pmd_basic_tests(unsigned long pfn, pgprot_t prot)
+{
+	pmd_t pmd = pfn_pmd(pfn, prot);
+
+	WARN_ON(!pmd_same(pmd, pmd));
+	WARN_ON(!pmd_young(pmd_mkyoung(pmd_mkold(pmd))));
+	WARN_ON(!pmd_dirty(pmd_mkdirty(pmd_mkclean(pmd))));
+	WARN_ON(!pmd_write(pmd_mkwrite(pmd_wrprotect(pmd))));
+	WARN_ON(pmd_young(pmd_mkold(pmd_mkyoung(pmd))));
+	WARN_ON(pmd_dirty(pmd_mkclean(pmd_mkdirty(pmd))));
+	WARN_ON(pmd_write(pmd_wrprotect(pmd_mkwrite(pmd))));
+	/*
+	 * A huge page does not point to next level page table
+	 * entry. Hence this must qualify as pmd_bad().
+	 */
+	WARN_ON(!pmd_bad(pmd_mkhuge(pmd)));
+}
+
+#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD
+static void __init pud_basic_tests(unsigned long pfn, pgprot_t prot)
+{
+	pud_t pud = pfn_pud(pfn, prot);
+
+	WARN_ON(!pud_same(pud, pud));
+	WARN_ON(!pud_young(pud_mkyoung(pud_mkold(pud))));
+	WARN_ON(!pud_write(pud_mkwrite(pud_wrprotect(pud))));
+	WARN_ON(pud_write(pud_wrprotect(pud_mkwrite(pud))));
+	WARN_ON(pud_young(pud_mkold(pud_mkyoung(pud))));
+
+	if (mm_pmd_folded(mm))
+		return;
+
+	/*
+	 * A huge page does not point to next level page table
+	 * entry. Hence this must qualify as pud_bad().
+	 */
+	WARN_ON(!pud_bad(pud_mkhuge(pud)));
+}
+#else
+static void __init pud_basic_tests(unsigned long pfn, pgprot_t prot) { }
+#endif
+#else
+static void __init pmd_basic_tests(unsigned long pfn, pgprot_t prot) { }
+static void __init pud_basic_tests(unsigned long pfn, pgprot_t prot) { }
+#endif
+
+static void __init p4d_basic_tests(unsigned long pfn, pgprot_t prot)
+{
+	p4d_t p4d;
+
+	memset(&p4d, RANDOM_NZVALUE, sizeof(p4d_t));
+	WARN_ON(!p4d_same(p4d, p4d));
+}
+
+static void __init pgd_basic_tests(unsigned long pfn, pgprot_t prot)
+{
+	pgd_t pgd;
+
+	memset(&pgd, RANDOM_NZVALUE, sizeof(pgd_t));
+	WARN_ON(!pgd_same(pgd, pgd));
+}
+
+#ifndef __PAGETABLE_PUD_FOLDED
+static void __init pud_clear_tests(struct mm_struct *mm, pud_t *pudp)
+{
+	pud_t pud = READ_ONCE(*pudp);
+
+	if (mm_pmd_folded(mm))
+		return;
+
+	pud = __pud(pud_val(pud) | RANDOM_ORVALUE);
+	WRITE_ONCE(*pudp, pud);
+	pud_clear(pudp);
+	pud = READ_ONCE(*pudp);
+	WARN_ON(!pud_none(pud));
+}
+
+static void __init pud_populate_tests(struct mm_struct *mm, pud_t *pudp,
+				      pmd_t *pmdp)
+{
+	pud_t pud;
+
+	if (mm_pmd_folded(mm))
+		return;
+	/*
+	 * This entry points to next level page table page.
+	 * Hence this must not qualify as pud_bad().
+	 */
+	pmd_clear(pmdp);
+	pud_clear(pudp);
+	pud_populate(mm, pudp, pmdp);
+	pud = READ_ONCE(*pudp);
+	WARN_ON(pud_bad(pud));
+}
+#else
+static void __init pud_clear_tests(struct mm_struct *mm, pud_t *pudp) { }
+static void __init pud_populate_tests(struct mm_struct *mm, pud_t *pudp,
+				      pmd_t *pmdp)
+{
+}
+#endif
+
+#ifndef __PAGETABLE_P4D_FOLDED
+static void __init p4d_clear_tests(struct mm_struct *mm, p4d_t *p4dp)
+{
+	p4d_t p4d = READ_ONCE(*p4dp);
+
+	if (mm_pud_folded(mm))
+		return;
+
+	p4d = __p4d(p4d_val(p4d) | RANDOM_ORVALUE);
+	WRITE_ONCE(*p4dp, p4d);
+	p4d_clear(p4dp);
+	p4d = READ_ONCE(*p4dp);
+	WARN_ON(!p4d_none(p4d));
+}
+
+static void __init p4d_populate_tests(struct mm_struct *mm, p4d_t *p4dp,
+				      pud_t *pudp)
+{
+	p4d_t p4d;
+
+	if (mm_pud_folded(mm))
+		return;
+
+	/*
+	 * This entry points to next level page table page.
+	 * Hence this must not qualify as p4d_bad().
+	 */
+	pud_clear(pudp);
+	p4d_clear(p4dp);
+	p4d_populate(mm, p4dp, pudp);
+	p4d = READ_ONCE(*p4dp);
+	WARN_ON(p4d_bad(p4d));
+}
+
+static void __init pgd_clear_tests(struct mm_struct *mm, pgd_t *pgdp)
+{
+	pgd_t pgd = READ_ONCE(*pgdp);
+
+	if (mm_p4d_folded(mm))
+		return;
+
+	pgd = __pgd(pgd_val(pgd) | RANDOM_ORVALUE);
+	WRITE_ONCE(*pgdp, pgd);
+	pgd_clear(pgdp);
+	pgd = READ_ONCE(*pgdp);
+	WARN_ON(!pgd_none(pgd));
+}
+
+static void __init pgd_populate_tests(struct mm_struct *mm, pgd_t *pgdp,
+				      p4d_t *p4dp)
+{
+	pgd_t pgd;
+
+	if (mm_p4d_folded(mm))
+		return;
+
+	/*
+	 * This entry points to next level page table page.
+	 * Hence this must not qualify as pgd_bad().
+	 */
+	p4d_clear(p4dp);
+	pgd_clear(pgdp);
+	pgd_populate(mm, pgdp, p4dp);
+	pgd = READ_ONCE(*pgdp);
+	WARN_ON(pgd_bad(pgd));
+}
+#else
+static void __init p4d_clear_tests(struct mm_struct *mm, p4d_t *p4dp) { }
+static void __init pgd_clear_tests(struct mm_struct *mm, pgd_t *pgdp) { }
+static void __init p4d_populate_tests(struct mm_struct *mm, p4d_t *p4dp,
+				      pud_t *pudp)
+{
+}
+static void __init pgd_populate_tests(struct mm_struct *mm, pgd_t *pgdp,
+				      p4d_t *p4dp)
+{
+}
+#endif
+
+static void __init pte_clear_tests(struct mm_struct *mm, pte_t *ptep,
+				   unsigned long vaddr)
+{
+	pte_t pte = READ_ONCE(*ptep);
+
+	pte = __pte(pte_val(pte) | RANDOM_ORVALUE);
+	WRITE_ONCE(*ptep, pte);
+	pte_clear(mm, vaddr, ptep);
+	pte = READ_ONCE(*ptep);
+	WARN_ON(!pte_none(pte));
+}
+
+static void __init pmd_clear_tests(struct mm_struct *mm, pmd_t *pmdp)
+{
+	pmd_t pmd = READ_ONCE(*pmdp);
+
+	pmd = __pmd(pmd_val(pmd) | RANDOM_ORVALUE);
+	WRITE_ONCE(*pmdp, pmd);
+	pmd_clear(pmdp);
+	pmd = READ_ONCE(*pmdp);
+	WARN_ON(!pmd_none(pmd));
+}
+
+static void __init pmd_populate_tests(struct mm_struct *mm, pmd_t *pmdp,
+				      pgtable_t pgtable)
+{
+	pmd_t pmd;
+
+	/*
+	 * This entry points to next level page table page.
+	 * Hence this must not qualify as pmd_bad().
+	 */
+	pmd_clear(pmdp);
+	pmd_populate(mm, pmdp, pgtable);
+	pmd = READ_ONCE(*pmdp);
+	WARN_ON(pmd_bad(pmd));
+}
+
+static unsigned long __init get_random_vaddr(void)
+{
+	unsigned long random_vaddr, random_pages, total_user_pages;
+
+	total_user_pages = (TASK_SIZE - FIRST_USER_ADDRESS) / PAGE_SIZE;
+
+	random_pages = get_random_long() % total_user_pages;
+	random_vaddr = FIRST_USER_ADDRESS + random_pages * PAGE_SIZE;
+
+	return random_vaddr;
+}
+
+void __init debug_vm_pgtable(void)
+{
+	struct mm_struct *mm;
+	pgd_t *pgdp;
+	p4d_t *p4dp, *saved_p4dp;
+	pud_t *pudp, *saved_pudp;
+	pmd_t *pmdp, *saved_pmdp, pmd;
+	pte_t *ptep;
+	pgtable_t saved_ptep;
+	pgprot_t prot;
+	phys_addr_t paddr;
+	unsigned long vaddr, pte_aligned, pmd_aligned;
+	unsigned long pud_aligned, p4d_aligned, pgd_aligned;
+	spinlock_t *uninitialized_var(ptl);
+
+	pr_info("Validating architecture page table helpers\n");
+	prot = vm_get_page_prot(VMFLAGS);
+	vaddr = get_random_vaddr();
+	mm = mm_alloc();
+	if (!mm) {
+		pr_err("mm_struct allocation failed\n");
+		return;
+	}
+
+	/*
+	 * PFN for mapping at PTE level is determined from a standard kernel
+	 * text symbol. But pfns for higher page table levels are derived by
+	 * masking lower bits of this real pfn. These derived pfns might not
+	 * exist on the platform but that does not really matter as pfn_pxx()
+	 * helpers will still create appropriate entries for the test. This
+	 * helps avoid large memory block allocations to be used for mapping
+	 * at higher page table levels.
+	 */
+	paddr = __pa_symbol(&start_kernel);
+
+	pte_aligned = (paddr & PAGE_MASK) >> PAGE_SHIFT;
+	pmd_aligned = (paddr & PMD_MASK) >> PAGE_SHIFT;
+	pud_aligned = (paddr & PUD_MASK) >> PAGE_SHIFT;
+	p4d_aligned = (paddr & P4D_MASK) >> PAGE_SHIFT;
+	pgd_aligned = (paddr & PGDIR_MASK) >> PAGE_SHIFT;
+	WARN_ON(!pfn_valid(pte_aligned));
+
+	pgdp = pgd_offset(mm, vaddr);
+	p4dp = p4d_alloc(mm, pgdp, vaddr);
+	pudp = pud_alloc(mm, p4dp, vaddr);
+	pmdp = pmd_alloc(mm, pudp, vaddr);
+	ptep = pte_alloc_map_lock(mm, pmdp, vaddr, &ptl);
+
+	/*
+	 * Save all the page table page addresses as the page table
+	 * entries will be used for testing with random or garbage
+	 * values. These saved addresses will be used for freeing
+	 * page table pages.
+	 */
+	pmd = READ_ONCE(*pmdp);
+	saved_p4dp = p4d_offset(pgdp, 0UL);
+	saved_pudp = pud_offset(p4dp, 0UL);
+	saved_pmdp = pmd_offset(pudp, 0UL);
+	saved_ptep = pmd_pgtable(pmd);
+
+	pte_basic_tests(pte_aligned, prot);
+	pmd_basic_tests(pmd_aligned, prot);
+	pud_basic_tests(pud_aligned, prot);
+	p4d_basic_tests(p4d_aligned, prot);
+	pgd_basic_tests(pgd_aligned, prot);
+
+	pte_clear_tests(mm, ptep, vaddr);
+	pmd_clear_tests(mm, pmdp);
+	pud_clear_tests(mm, pudp);
+	p4d_clear_tests(mm, p4dp);
+	pgd_clear_tests(mm, pgdp);
+
+	pte_unmap_unlock(ptep, ptl);
+
+	pmd_populate_tests(mm, pmdp, saved_ptep);
+	pud_populate_tests(mm, pudp, saved_pmdp);
+	p4d_populate_tests(mm, p4dp, saved_pudp);
+	pgd_populate_tests(mm, pgdp, saved_p4dp);
+
+	p4d_free(mm, saved_p4dp);
+	pud_free(mm, saved_pudp);
+	pmd_free(mm, saved_pmdp);
+	pte_free(mm, saved_ptep);
+
+	mm_dec_nr_puds(mm);
+	mm_dec_nr_pmds(mm);
+	mm_dec_nr_ptes(mm);
+	mmdrop(mm);
+}
-- 
2.7.4


^ permalink raw reply related

* Re: [Bug 206695] kmemleak reports leaks in drivers/macintosh/windfarm
From: Michael Ellerman @ 2020-03-06  0:01 UTC (permalink / raw)
  To: bugzilla-daemon, linuxppc-dev
In-Reply-To: <bug-206695-206035-HRb322afyL@https.bugzilla.kernel.org/>

bugzilla-daemon@bugzilla.kernel.org writes:
> https://bugzilla.kernel.org/show_bug.cgi?id=206695
>
> --- Comment #4 from Erhard F. (erhard_f@mailbox.org) ---
> (In reply to mpe from comment #3)
>> Can you try this patch?
>
> Applied your patch on top of 5.6-rc4 +
> https://patchwork.ozlabs.org/patch/1248350/ and let the G5 do a few hours
> compiling.
>
> Only getting those nice memleaks from bug #206203 but no windfarm_pm112 memleak
> any longer. So your patch works well it seems. Thanks!

Thanks.

Can you try this one instead, it changes the order of operations to make
the code flow a bit nicer.

cheers

diff --git a/drivers/macintosh/windfarm_pm112.c b/drivers/macintosh/windfarm_pm112.c
index 4150301a89a5..e8377ce0a95a 100644
--- a/drivers/macintosh/windfarm_pm112.c
+++ b/drivers/macintosh/windfarm_pm112.c
@@ -132,14 +132,6 @@ static int create_cpu_loop(int cpu)
 	s32 tmax;
 	int fmin;
 
-	/* Get PID params from the appropriate SAT */
-	hdr = smu_sat_get_sdb_partition(chip, 0xC8 + core, NULL);
-	if (hdr == NULL) {
-		printk(KERN_WARNING"windfarm: can't get CPU PID fan config\n");
-		return -EINVAL;
-	}
-	piddata = (struct smu_sdbp_cpupiddata *)&hdr[1];
-
 	/* Get FVT params to get Tmax; if not found, assume default */
 	hdr = smu_sat_get_sdb_partition(chip, 0xC4 + core, NULL);
 	if (hdr) {
@@ -152,6 +144,16 @@ static int create_cpu_loop(int cpu)
 	if (tmax < cpu_all_tmax)
 		cpu_all_tmax = tmax;
 
+	kfree(hdr);
+
+	/* Get PID params from the appropriate SAT */
+	hdr = smu_sat_get_sdb_partition(chip, 0xC8 + core, NULL);
+	if (hdr == NULL) {
+		printk(KERN_WARNING"windfarm: can't get CPU PID fan config\n");
+		return -EINVAL;
+	}
+	piddata = (struct smu_sdbp_cpupiddata *)&hdr[1];
+
 	/*
 	 * Darwin has a minimum fan speed of 1000 rpm for the 4-way and
 	 * 515 for the 2-way.  That appears to be overkill, so for now,
@@ -174,6 +176,9 @@ static int create_cpu_loop(int cpu)
 		pid.min = fmin;
 
 	wf_cpu_pid_init(&cpu_pid[cpu], &pid);
+
+	kfree(hdr);
+
 	return 0;
 }
 


^ permalink raw reply related

* [Bug 206695] kmemleak reports leaks in drivers/macintosh/windfarm
From: bugzilla-daemon @ 2020-03-06  0:01 UTC (permalink / raw)
  To: linuxppc-dev
In-Reply-To: <bug-206695-206035@https.bugzilla.kernel.org/>

https://bugzilla.kernel.org/show_bug.cgi?id=206695

--- Comment #5 from mpe@ellerman.id.au ---
bugzilla-daemon@bugzilla.kernel.org writes:
> https://bugzilla.kernel.org/show_bug.cgi?id=206695
>
> --- Comment #4 from Erhard F. (erhard_f@mailbox.org) ---
> (In reply to mpe from comment #3)
>> Can you try this patch?
>
> Applied your patch on top of 5.6-rc4 +
> https://patchwork.ozlabs.org/patch/1248350/ and let the G5 do a few hours
> compiling.
>
> Only getting those nice memleaks from bug #206203 but no windfarm_pm112
> memleak
> any longer. So your patch works well it seems. Thanks!

Thanks.

Can you try this one instead, it changes the order of operations to make
the code flow a bit nicer.

cheers

diff --git a/drivers/macintosh/windfarm_pm112.c
b/drivers/macintosh/windfarm_pm112.c
index 4150301a89a5..e8377ce0a95a 100644
--- a/drivers/macintosh/windfarm_pm112.c
+++ b/drivers/macintosh/windfarm_pm112.c
@@ -132,14 +132,6 @@ static int create_cpu_loop(int cpu)
        s32 tmax;
        int fmin;

-       /* Get PID params from the appropriate SAT */
-       hdr = smu_sat_get_sdb_partition(chip, 0xC8 + core, NULL);
-       if (hdr == NULL) {
-               printk(KERN_WARNING"windfarm: can't get CPU PID fan config\n");
-               return -EINVAL;
-       }
-       piddata = (struct smu_sdbp_cpupiddata *)&hdr[1];
-
        /* Get FVT params to get Tmax; if not found, assume default */
        hdr = smu_sat_get_sdb_partition(chip, 0xC4 + core, NULL);
        if (hdr) {
@@ -152,6 +144,16 @@ static int create_cpu_loop(int cpu)
        if (tmax < cpu_all_tmax)
                cpu_all_tmax = tmax;

+       kfree(hdr);
+
+       /* Get PID params from the appropriate SAT */
+       hdr = smu_sat_get_sdb_partition(chip, 0xC8 + core, NULL);
+       if (hdr == NULL) {
+               printk(KERN_WARNING"windfarm: can't get CPU PID fan config\n");
+               return -EINVAL;
+       }
+       piddata = (struct smu_sdbp_cpupiddata *)&hdr[1];
+
        /*
         * Darwin has a minimum fan speed of 1000 rpm for the 4-way and
         * 515 for the 2-way.  That appears to be overkill, so for now,
@@ -174,6 +176,9 @@ static int create_cpu_loop(int cpu)
                pid.min = fmin;

        wf_cpu_pid_init(&cpu_pid[cpu], &pid);
+
+       kfree(hdr);
+
        return 0;
 }

-- 
You are receiving this mail because:
You are watching the assignee of the bug.

^ permalink raw reply related

* Re: [PATCH, v2] powerpc: fix hardware PMU exception bug on PowerVM compatibility mode systems
From: Michael Ellerman @ 2020-03-06  0:11 UTC (permalink / raw)
  To: Desnes A. Nunes do Rosario, linuxppc-dev; +Cc: leonardo, desnesn, gromero
In-Reply-To: <20200227134715.9715-1-desnesn@linux.ibm.com>

On Thu, 2020-02-27 at 13:47:15 UTC, "Desnes A. Nunes do Rosario" wrote:
> PowerVM systems running compatibility mode on a few Power8 revisions are
> still vulnerable to the hardware defect that loses PMU exceptions arriving
> prior to a context switch.
> 
> The software fix for this issue is enabled through the CPU_FTR_PMAO_BUG
> cpu_feature bit, nevertheless this bit also needs to be set for PowerVM
> compatibility mode systems.
> 
> Fixes: 68f2f0d431d9ea4 ("powerpc: Add a cpu feature CPU_FTR_PMAO_BUG")
> Signed-off-by: Desnes A. Nunes do Rosario <desnesn@linux.ibm.com>

Applied to powerpc fixes, thanks.

https://git.kernel.org/powerpc/c/fc37a1632d40c80c067eb1bc235139f5867a2667

cheers

^ permalink raw reply

* Re: [PATCH v2] powerpc/mm: Fix missing KUAP disable in flush_coherent_icache()
From: Michael Ellerman @ 2020-03-06  0:11 UTC (permalink / raw)
  To: Michael Ellerman, linuxppc-dev
In-Reply-To: <20200303235708.26004-1-mpe@ellerman.id.au>

On Tue, 2020-03-03 at 23:57:08 UTC, Michael Ellerman wrote:
> We received a report of strange kernel faults which turned out to be
> due to a missing KUAP disable in flush_coherent_icache() called
> from flush_icache_range().
> 
> The fault looks like:
> 
>   Kernel attempted to access user page (7fffc30d9c00) - exploit attempt? (uid: 1009)
>   BUG: Unable to handle kernel data access on read at 0x7fffc30d9c00
>   Faulting instruction address: 0xc00000000007232c
>   Oops: Kernel access of bad area, sig: 11 [#1]
>   LE PAGE_SIZE=64K MMU=Radix SMP NR_CPUS=2048 NUMA PowerNV
>   CPU: 35 PID: 5886 Comm: sigtramp Not tainted 5.6.0-rc2-gcc-8.2.0-00003-gfc37a1632d40 #79
>   NIP:  c00000000007232c LR: c00000000003b7fc CTR: 0000000000000000
>   REGS: c000001e11093940 TRAP: 0300   Not tainted  (5.6.0-rc2-gcc-8.2.0-00003-gfc37a1632d40)
>   MSR:  900000000280b033 <SF,HV,VEC,VSX,EE,FP,ME,IR,DR,RI,LE>  CR: 28000884  XER: 00000000
>   CFAR: c0000000000722fc DAR: 00007fffc30d9c00 DSISR: 08000000 IRQMASK: 0
>   GPR00: c00000000003b7fc c000001e11093bd0 c0000000023ac200 00007fffc30d9c00
>   GPR04: 00007fffc30d9c18 0000000000000000 c000001e11093bd4 0000000000000000
>   GPR08: 0000000000000000 0000000000000001 0000000000000000 c000001e1104ed80
>   GPR12: 0000000000000000 c000001fff6ab380 c0000000016be2d0 4000000000000000
>   GPR16: c000000000000000 bfffffffffffffff 0000000000000000 0000000000000000
>   GPR20: 00007fffc30d9c00 00007fffc30d8f58 00007fffc30d9c18 00007fffc30d9c20
>   GPR24: 00007fffc30d9c18 0000000000000000 c000001e11093d90 c000001e1104ed80
>   GPR28: c000001e11093e90 0000000000000000 c0000000023d9d18 00007fffc30d9c00
>   NIP flush_icache_range+0x5c/0x80
>   LR  handle_rt_signal64+0x95c/0xc2c
>   Call Trace:
>     0xc000001e11093d90 (unreliable)
>     handle_rt_signal64+0x93c/0xc2c
>     do_notify_resume+0x310/0x430
>     ret_from_except_lite+0x70/0x74
>   Instruction dump:
>   409e002c 7c0802a6 3c62ff31 3863f6a0 f8010080 48195fed 60000000 48fe4c8d
>   60000000 e8010080 7c0803a6 7c0004ac <7c00ffac> 7c0004ac 4c00012c 38210070
> 
> This path through handle_rt_signal64() to setup_trampoline() and
> flush_icache_range() is only triggered by 64-bit processes that have
> unmapped their VDSO, which is rare.
> 
> flush_icache_range() takes a range of addresses to flush. In
> flush_coherent_icache() we implement an optimisation for CPUs where we
> know we don't actually have to flush the whole range, we just need to
> do a single icbi.
> 
> However we still execute the icbi on the user address of the start of
> the range we're flushing. On CPUs that also implement KUAP (Power9)
> that leads to the spurious fault above.
> 
> We should be able to pass any address, including a kernel address, to
> the icbi on these CPUs, which would avoid any interaction with KUAP.
> But I don't want to make that change in a bug fix, just in case it
> surfaces some strange behaviour on some CPU.
> 
> So for now just disable KUAP around the icbi. Note the icbi is treated
> as a load, so we allow read access, not write as you'd expect.
> 
> Fixes: 890274c2dc4c ("powerpc/64s: Implement KUAP for Radix MMU")
> Cc: stable@vger.kernel.org # v5.2+
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

Applied to powerpc fixes.

https://git.kernel.org/powerpc/c/59bee45b9712c759ea4d3dcc4eff1752f3a66558

cheers

^ permalink raw reply

* Re: [RFC PATCH v2 1/1] powerpc/kernel: Enables memory hot-remove after reboot on pseries guests
From: Leonardo Bras @ 2020-03-06  0:24 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
	Allison Randal, Greg Kroah-Hartman, Nathan Fontenot,
	Thomas Gleixner, Michael Anderson, Mike Rapoport,
	Claudio Carvalho, Hari Bathini, Christophe Leroy, bharata.rao
  Cc: linuxppc-dev, linux-kernel
In-Reply-To: <20200305233231.174082-1-leonardo@linux.ibm.com>

[-- Attachment #1: Type: text/plain, Size: 161 bytes --]

On Thu, 2020-03-05 at 20:32 -0300, Leonardo Bras wrote:
> I will send the matching qemu change as a reply later.

http://patchwork.ozlabs.org/patch/1249931/

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply

* Re: [PATCH v6 1/6] Documentation/ABI: add ABI documentation for /sys/kernel/fadump_*
From: Michael Ellerman @ 2020-03-06  0:27 UTC (permalink / raw)
  To: Sourabh Jain
  Cc: linux-doc, mahesh, corbet, linux-kernel, Sourabh Jain,
	linuxppc-dev, gregkh, hbathini
In-Reply-To: <20191211160910.21656-2-sourabhjain@linux.ibm.com>

On Wed, 2019-12-11 at 16:09:05 UTC, Sourabh Jain wrote:
> Add missing ABI documentation for existing FADump sysfs files.
> 
> Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com>

Series applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/f52153ab383f04a45c38d8a7f55a4249477b20df

cheers

^ permalink raw reply

* Re: [PATCH kernel v3] powerpc/book3s64: Fix error handling in mm_iommu_do_alloc()
From: Michael Ellerman @ 2020-03-06  0:27 UTC (permalink / raw)
  To: Alexey Kardashevskiy, linuxppc-dev
  Cc: Alexey Kardashevskiy, Jan Kara, kvm-ppc, David Gibson
In-Reply-To: <20191223060351.26359-1-aik@ozlabs.ru>

On Mon, 2019-12-23 at 06:03:51 UTC, Alexey Kardashevskiy wrote:
> The last jump to free_exit in mm_iommu_do_alloc() happens after page
> pointers in struct mm_iommu_table_group_mem_t were already converted to
> physical addresses. Thus calling put_page() on these physical addresses
> will likely crash.
> 
> This moves the loop which calculates the pageshift and converts page
> struct pointers to physical addresses later after the point when
> we cannot fail; thus eliminating the need to convert pointers back.
> 
> Fixes: eb9d7a62c386 ("powerpc/mm_iommu: Fix potential deadlock")
> Reported-by: Jan Kara <jack@suse.cz>
> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/c4b78169e3667413184c9a20e11b5832288a109f

cheers

^ permalink raw reply

* Re: [PATCH] powerpc/32: don't restore r0, r6-r8 on exception entry path after trace_hardirqs_off()
From: Michael Ellerman @ 2020-03-06  0:27 UTC (permalink / raw)
  To: Christophe Leroy, Benjamin Herrenschmidt, Paul Mackerras
  Cc: linuxppc-dev, linux-kernel
In-Reply-To: <d2c6dc65d27e83964eb05f16a126161ab6455eea.1578388585.git.christophe.leroy@c-s.fr>

On Tue, 2020-01-07 at 09:16:40 UTC, Christophe Leroy wrote:
> Since commit b86fb88855ea ("powerpc/32: implement fast entry for
> syscalls on non BOOKE") and commit 1a4b739bbb4f ("powerpc/32:
> implement fast entry for syscalls on BOOKE"), syscalls don't
> use the exception entry path anymore. It is therefore pointless
> to restore r0 and r6-r8 after calling trace_hardirqs_off().
> 
> In the meantime, drop the '2:' label which is unused and misleading.
> 
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/05642cf7289c5562e5939d2ee8a0529d310010b8

cheers

^ permalink raw reply

* Re: [PATCH v3 1/2] powerpc/32: refactor pmd_offset(pud_offset(pgd_offset...
From: Michael Ellerman @ 2020-03-06  0:27 UTC (permalink / raw)
  To: Christophe Leroy, Benjamin Herrenschmidt, Paul Mackerras,
	Mike Rapoport
  Cc: linuxppc-dev, linux-kernel
In-Reply-To: <7b065c5be35726af4066cab238ee35cabceda1fa.1578558199.git.christophe.leroy@c-s.fr>

On Thu, 2020-01-09 at 08:25:25 UTC, Christophe Leroy wrote:
> At several places pmd pointer is retrieved through the same action:
> 
> 	pmd = pmd_offset(pud_offset(pgd_offset(mm, addr), addr), addr);
> 
> or
> 
> 	pmd = pmd_offset(pud_offset(pgd_offset_k(addr), addr), addr);
> 
> Refactor this by implementing two helpers pmd_ptr() and pmd_ptr_k()
> 
> This will help when adding the p4d level.
> 
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>

Series applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/0b1c524caaae2428b20e714297243e5551251eb5

cheers

^ permalink raw reply

* Re: [PATCH v4] powerpc/smp: Use nid as fallback for package_id
From: Michael Ellerman @ 2020-03-06  0:27 UTC (permalink / raw)
  To: Srikar Dronamraju
  Cc: Vasant Hegde, Vaidyanathan Srinivasan, linuxppc-dev,
	Srikar Dronamraju
In-Reply-To: <20200129135121.24617-1-srikar@linux.vnet.ibm.com>

On Wed, 2020-01-29 at 13:51:21 UTC, Srikar Dronamraju wrote:
> Package_id is to find out all cores that are part of the same chip. On
> PowerNV machines, package_id defaults to chip_id. However ibm,chip_id
> property is not present in device-tree of PowerVM Lpars. Hence lscpu
> output shows one core per socket and multiple cores.
> 
> To overcome this, use nid as the package_id on PowerVM Lpars.
> 
> Before the patch.
> ---------------
> Architecture:        ppc64le
> Byte Order:          Little Endian
> CPU(s):              128
> On-line CPU(s) list: 0-127
> Thread(s) per core:  8
> Core(s) per socket:  1                           <----------------------
> Socket(s):           16                          <----------------------
> NUMA node(s):        2
> Model:               2.2 (pvr 004e 0202)
> Model name:          POWER9 (architected), altivec supported
> Hypervisor vendor:   pHyp
> Virtualization type: para
> L1d cache:           32K
> L1i cache:           32K
> L2 cache:            512K
> L3 cache:            10240K
> NUMA node0 CPU(s):   0-63
> NUMA node1 CPU(s):   64-127
>  #
>  # cat /sys/devices/system/cpu/cpu0/topology/physical_package_id
>  -1
>  #
> 
> After the patch
> ---------------
> Architecture:        ppc64le
> Byte Order:          Little Endian
> CPU(s):              128
> On-line CPU(s) list: 0-127
> Thread(s) per core:  8			<------------------------------
> Core(s) per socket:  8			<------------------------------
> Socket(s):           2
> NUMA node(s):        2
> Model:               2.2 (pvr 004e 0202)
> Model name:          POWER9 (architected), altivec supported
> Hypervisor vendor:   pHyp
> Virtualization type: para
> L1d cache:           32K
> L1i cache:           32K
> L2 cache:            512K
> L3 cache:            10240K
> NUMA node0 CPU(s):   0-63
> NUMA node1 CPU(s):   64-127
>  #
>  # cat /sys/devices/system/cpu/cpu0/topology/physical_package_id
>  0
>  #
> Now lscpu output is more in line with the system configuration.
> 
> Signed-off-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
> Cc: linuxppc-dev@lists.ozlabs.org
> Cc: Michael Ellerman <mpe@ellerman.id.au>
> Cc: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
> Cc: Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/a05f0e5be4e81e4977d3f92aaf7688ee0cb7d5db

cheers

^ permalink raw reply

* Re: [PATCH v6 1/5] powerpc/vphn: Check for error from hcall_vphn
From: Michael Ellerman @ 2020-03-06  0:27 UTC (permalink / raw)
  To: Srikar Dronamraju
  Cc: Nathan Lynch, Srikar Dronamraju, Nicholas Piggin, Abdul Haleem,
	Satheesh Rajendran, linuxppc-dev
In-Reply-To: <20200129135301.24739-2-srikar@linux.vnet.ibm.com>

On Wed, 2020-01-29 at 13:52:57 UTC, Srikar Dronamraju wrote:
> There is no value in unpacking associativity, if
> H_HOME_NODE_ASSOCIATIVITY hcall has returned an error.
> 
> Signed-off-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
> Cc: Michael Ellerman <mpe@ellerman.id.au>
> Cc: Nicholas Piggin <npiggin@gmail.com>
> Cc: Nathan Lynch <nathanl@linux.ibm.com>
> Cc: linuxppc-dev@lists.ozlabs.org
> Cc: Abdul Haleem <abdhalee@linux.vnet.ibm.com>
> Cc: Satheesh Rajendran <sathnaga@linux.vnet.ibm.com>
> Reported-by: Abdul Haleem <abdhalee@linux.vnet.ibm.com>
> Reviewed-by: Nathan Lynch <nathanl@linux.ibm.com>

Series applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/e7214ae9d85aa325c9f3cb34bf4fad7f112861d7

cheers

^ permalink raw reply

* Re: [PATCH] powerpc/process: Remove unneccessary #ifdef CONFIG_PPC64 in copy_thread_tls()
From: Michael Ellerman @ 2020-03-06  0:27 UTC (permalink / raw)
  To: Christophe Leroy, Benjamin Herrenschmidt, Paul Mackerras
  Cc: linuxppc-dev, linux-kernel
In-Reply-To: <6ecbda05b4119c40222dc8ec284604e1597c9bff.1580327381.git.christophe.leroy@c-s.fr>

On Wed, 2020-01-29 at 19:50:07 UTC, Christophe Leroy wrote:
> is_32bit_task() exists on both PPC64 and PPC32, no need of an ifdefery.
> 
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/ba32f4b02105e57627912b42e141d65d90074c64

cheers

^ permalink raw reply

* Re: [PATCH] powerpc/papr_scm: Mark papr_scm_ndctl() as static
From: Michael Ellerman @ 2020-03-06  0:27 UTC (permalink / raw)
  To: Vaibhav Jain, linuxppc-dev
  Cc: Vaibhav Jain, Oliver O'Halloran, Aneesh Kumar K . V
In-Reply-To: <20200130040206.79998-1-vaibhav@linux.ibm.com>

On Thu, 2020-01-30 at 04:02:06 UTC, Vaibhav Jain wrote:
> Function papr_scm_ndctl() is neither exported from the module nor
> called directly from outside 'papr.c' hence should be marked 'static'.
> 
> Signed-off-by: Vaibhav Jain <vaibhav@linux.ibm.com>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/72c4ebbac476b8375e69fd09390e6b64c2891716

cheers

^ permalink raw reply

* Re: [PATCH 1/2] pseries/vio: Remove stray #ifdef CONFIG_PPC_PSERIES
From: Michael Ellerman @ 2020-03-06  0:27 UTC (permalink / raw)
  To: Oliver O'Halloran, linuxppc-dev; +Cc: Oliver O'Halloran
In-Reply-To: <20200130063153.19915-1-oohall@gmail.com>

On Thu, 2020-01-30 at 06:31:52 UTC, Oliver O'Halloran wrote:
> vio.c requires CONFIG_IBMVIO which in turn depends on PPC_PSERIES.
> In other words, this ifdef is pointless. At a guess it's a carry-over
> from pre-history.
> 
> Signed-off-by: Oliver O'Halloran <oohall@gmail.com>

Series applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/f98df5ed0a670f2c4c1a50d7901acbb862a247c7

cheers

^ permalink raw reply

* Re: [PATCH v3 1/2] powerpc/32: Warn and return ENOSYS on syscalls from kernel
From: Michael Ellerman @ 2020-03-06  0:27 UTC (permalink / raw)
  To: Christophe Leroy, Benjamin Herrenschmidt, Paul Mackerras
  Cc: linuxppc-dev, linux-kernel
In-Reply-To: <8ee3bdbbdfdfc64ca7001e90c43b2aee6f333578.1580470482.git.christophe.leroy@c-s.fr>

On Fri, 2020-01-31 at 11:34:54 UTC, Christophe Leroy wrote:
> Since commit b86fb88855ea ("powerpc/32: implement fast entry for
> syscalls on non BOOKE") and commit 1a4b739bbb4f ("powerpc/32:
> implement fast entry for syscalls on BOOKE"), syscalls from
> kernel are unexpected and can have catastrophic consequences
> as it will destroy the kernel stack.
> 
> Test MSR_PR on syscall entry. In case syscall is from kernel,
> emit a warning and return ENOSYS error.
> 
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>

Series applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/9e27086292aa880921a0f2b8501e5189d5efcf03

cheers

^ permalink raw reply

* Re: [PATCH v2] powerpc: drmem: avoid NULL pointer dereference when drmem is unavailable
From: Michael Ellerman @ 2020-03-06  0:27 UTC (permalink / raw)
  To: Michal Suchanek, linuxppc-dev, Nathan Lynch, Libor Pechacek
  Cc: David Hildenbrand, linux-kernel, stable, Michal Suchanek,
	Paul Mackerras, Leonardo Bras, Thomas Gleixner, Michal Suchanek,
	Allison Randal
In-Reply-To: <20200131132829.10281-1-msuchanek@suse.de>

On Fri, 2020-01-31 at 13:28:29 UTC, Michal Suchanek wrote:
> 
> From: Libor Pechacek <lpechacek@suse.cz>
> 
> In guests without hotplugagble memory drmem structure is only zero
> initialized. Trying to manipulate DLPAR parameters results in a crash.
> 
> $ echo "memory add count 1" > /sys/kernel/dlpar
> Oops: Kernel access of bad area, sig: 11 [#1]
> LE PAGE_SIZE=64K MMU=Hash SMP NR_CPUS=2048 NUMA pSeries
> Modules linked in: af_packet(E) rfkill(E) nvram(E) vmx_crypto(E)
> gf128mul(E) e1000(E) virtio_balloon(E) rtc_generic(E) crct10dif_vpmsum(E)
> btrfs(E) blake2b_generic(E) libcrc32c(E) xor(E) raid6_pq(E) virtio_rng(E)
> virtio_blk(E) ohci_pci(E) ehci_pci(E) ohci_hcd(E) ehci_hcd(E)
> crc32c_vpmsum(E) usbcore(E) virtio_pci(E) virtio_ring(E) virtio(E) sg(E)
> dm_multipath(E) dm_mod(E) scsi_dh_rdac(E) scsi_dh_emc(E) scsi_dh_alua(E)
> scsi_mod(E)
> CPU: 1 PID: 4114 Comm: bash Kdump: loaded Tainted: G            E     5.5.0-rc6-2-default #1
> NIP:  c0000000000ff294 LR: c0000000000ff248 CTR: 0000000000000000
> REGS: c0000000fb9d3880 TRAP: 0300   Tainted: G            E      (5.5.0-rc6-2-default)
> MSR:  8000000000009033 <SF,EE,ME,IR,DR,RI,LE>  CR: 28242428  XER: 20000000
> CFAR: c0000000009a6c10 DAR: 0000000000000010 DSISR: 40000000 IRQMASK: 0
> GPR00: c0000000000ff248 c0000000fb9d3b10 c000000001682e00 0000000000000033
> GPR04: c0000000ff30bf90 c0000000ff394800 0000000000005110 ffffffffffffffe8
> GPR08: 0000000000000000 0000000000000000 00000000fe1c0000 0000000000000000
> GPR12: 0000000000002200 c00000003fffee00 0000000000000000 000000011cbc37c0
> GPR16: 000000011cb27ed0 0000000000000000 000000011cb6dd10 0000000000000000
> GPR20: 000000011cb7db28 000001003ce035f0 000000011cbc7828 000000011cbc6c70
> GPR24: 000001003cf01210 0000000000000000 c0000000ffade4e0 c000000002d7216b
> GPR28: 0000000000000001 c000000002d78560 0000000000000000 c0000000015458d0
> NIP [c0000000000ff294] dlpar_memory+0x6e4/0xd00
> LR [c0000000000ff248] dlpar_memory+0x698/0xd00
> Call Trace:
> [c0000000fb9d3b10] [c0000000000ff248] dlpar_memory+0x698/0xd00 (unreliable)
> [c0000000fb9d3ba0] [c0000000000f5990] handle_dlpar_errorlog+0xc0/0x190
> [c0000000fb9d3c10] [c0000000000f5c58] dlpar_store+0x198/0x4a0
> [c0000000fb9d3cd0] [c000000000c4cb00] kobj_attr_store+0x30/0x50
> [c0000000fb9d3cf0] [c0000000005a37b4] sysfs_kf_write+0x64/0x90
> [c0000000fb9d3d10] [c0000000005a2c90] kernfs_fop_write+0x1b0/0x290
> [c0000000fb9d3d60] [c0000000004a2bec] __vfs_write+0x3c/0x70
> [c0000000fb9d3d80] [c0000000004a6560] vfs_write+0xd0/0x260
> [c0000000fb9d3dd0] [c0000000004a69ac] ksys_write+0xdc/0x130
> [c0000000fb9d3e20] [c00000000000b478] system_call+0x5c/0x68
> Instruction dump:
> ebc90000 1ce70018 38e7ffe8 7cfe3a14 7fbe3840 419dff14 fb610068 7fc9f378
> 39000000 4800000c 60000000 4195fef4 <81490010> 39290018 38c80001 7ea93840
> ---[ end trace cc2dd8152608c295 ]---
> 
> Taking closer look at the code, I can see that for_each_drmem_lmb is a
> macro expanding into `for (lmb = &drmem_info->lmbs[0]; lmb <=
> &drmem_info->lmbs[drmem_info->n_lmbs - 1]; lmb++)`. When drmem_info->lmbs
> is NULL, the loop would iterate through the whole address range if it
> weren't stopped by the NULL pointer dereference on the next line.
> 
> This patch aligns for_each_drmem_lmb and for_each_drmem_lmb_in_range macro
> behavior with the common C semantics, where the end marker does not belong
> to the scanned range, and alters get_lmb_range() semantics. As a side
> effect, the wraparound observed in the crash is prevented.
> 
> Fixes: 6c6ea53725b3 ("powerpc/mm: Separate ibm, dynamic-memory data from DT format")
> Cc: Michal Suchanek <msuchanek@suse.cz>
> Cc: stable@vger.kernel.org
> Signed-off-by: Libor Pechacek <lpechacek@suse.cz>
> Signed-off-by: Michal Suchanek <msuchanek@suse.de>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/a83836dbc53e96f13fec248ecc201d18e1e3111d

cheers

^ permalink raw reply

* Re: [PATCH v2] powerpc/32s: Don't flush all TLBs when flushing one page
From: Michael Ellerman @ 2020-03-06  0:27 UTC (permalink / raw)
  To: Christophe Leroy, Benjamin Herrenschmidt, Paul Mackerras
  Cc: linuxppc-dev, linux-kernel
In-Reply-To: <b30b2eae6960502eaf0d9e36c60820b839693c33.1580542939.git.christophe.leroy@c-s.fr>

On Sat, 2020-02-01 at 08:04:31 UTC, Christophe Leroy wrote:
> When flushing any memory range, the flushing function
> flushes all TLBs.
> 
> When (start) and (end - 1) are in the same memory page,
> flush that page instead.
> 
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/030e347430957f6f7f29db9099368f8b86c0bf76

cheers

^ permalink raw reply

* Re: [PATCH] powerpc/32s: Slenderize _tlbia() for powerpc 603/603e
From: Michael Ellerman @ 2020-03-06  0:27 UTC (permalink / raw)
  To: Christophe Leroy, Benjamin Herrenschmidt, Paul Mackerras
  Cc: linuxppc-dev, linux-kernel
In-Reply-To: <12f4f4f0ff89aeab3b937fc96c84fb35e1b2517e.1580748445.git.christophe.leroy@c-s.fr>

On Mon, 2020-02-03 at 16:47:37 UTC, Christophe Leroy wrote:
> _tlbia() is a function used only on 603/603e core, ie on CPUs which
> don't have a hash table.
> 
> _tlbia() uses the tlbia macro which implements a loop of 1024 tlbie.
> 
> On the 603/603e core, flushing the entire TLB requires no more than
> 32 tlbie.
> 
> Replace tlbia by a loop of 32 tlbie.
> 
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/e1347a020b81fe47c80cd277bfaa61295a9482a4

cheers

^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox