Re: [PATCH v9 06/10] arm64: dts: ls1046a: Add serdes bindings

2023-01-26 Thread Shawn Guo
On Thu, Jan 26, 2023 at 11:43:26AM -0500, Sean Anderson wrote:
> On 1/25/23 18:46, Shawn Guo wrote:
> > On Thu, Dec 29, 2022 at 07:01:35PM -0500, Sean Anderson wrote:
> >> This adds bindings for the SerDes devices. They are disabled by default
> > 
> > s/bindings/descriptions?
> > 
> > The term "bindings" generally means the schema/doc in
> > Documentation/devicetree/bindings/.
> 
> How about "nodes"?

Yeah, or device nodes.

Shawn


Re: [PATCH v9 07/10] arm64: dts: ls1046ardb: Add serdes bindings

2023-01-26 Thread Shawn Guo
On Thu, Jan 26, 2023 at 11:48:53AM -0500, Sean Anderson wrote:
> On 1/25/23 18:43, Shawn Guo wrote:
> > On Thu, Dec 29, 2022 at 07:01:36PM -0500, Sean Anderson wrote:
> >> This adds appropriate bindings for the macs which use the SerDes. The
> >> 156.25MHz fixed clock is a crystal. The 100MHz clocks (there are
> >> actually 3) come from a Renesas 6V49205B at address 69 on i2c0. There is
> >> no driver for this device (and as far as I know all you can do with the
> >> 100MHz clocks is gate them), so I have chosen to model it as a single
> >> fixed clock.
> >> 
> >> Note: the SerDes1 lane numbering for the LS1046A is *reversed*.
> >> This means that Lane A (what the driver thinks is lane 0) uses pins
> >> SD1_TX3_P/N.
> >> 
> >> Because this will break ethernet if the serdes is not enabled, enable
> >> the serdes driver by default on Layerscape.
> >> 
> >> Signed-off-by: Sean Anderson 
> >> ---
> >> This depends on [1].
> >> 
> >> [1] 
> >> https://lore.kernel.org/netdev/20220804194705.459670-4-sean.ander...@seco.com/
> >> 
> >> Changes in v9:
> >> - Fix name of phy mode node
> >> - phy-type -> fsl,phy
> >> 
> >> Changes in v8:
> >> - Rename serdes phy handles to use _A, _B, etc. instead of _0, _1, etc.
> >>   This should help remind readers that the numbering corresponds to the
> >>   physical layout of the registers, and not the lane (pin) number.
> >> 
> >> Changes in v6:
> >> - XGI.9 -> XFI.9
> >> 
> >> Changes in v4:
> >> - Convert to new bindings
> >> 
> >>  .../boot/dts/freescale/fsl-ls1046a-rdb.dts| 112 ++
> >>  drivers/phy/freescale/Kconfig |   1 +
> > 
> > The phy driver Kconfig change shouldn't be part of this patch.
> 
> I put it here for bisectability, since this is the point where we need
> to enable it. But I can do this in a separate patch if you want.

>From DT ABI perspective, it's already broken anyway if you need to change
kernel and DT atomically.

Shawn


[PATCH 00/35] Documentation: correct lots of spelling errors (series 1)

2023-01-26 Thread Randy Dunlap
Correct many spelling errors in Documentation/ as reported by codespell.

Maintainers of specific kernel subsystems are only Cc-ed on their
respective patches, not the entire series. [if all goes well]

These patches are based on linux-next-20230125.


 [PATCH 01/35] Documentation: arm64: correct spelling
 [PATCH 02/35] Documentation: arm: correct spelling
 [PATCH 03/35] Documentation: block: correct spelling
 [PATCH 04/35] Documentation: bpf: correct spelling
 [PATCH 05/35] Documentation: core-api: correct spelling
 [PATCH 06/35] Documentation: fault-injection: correct spelling
 [PATCH 07/35] Documentation: fb: correct spelling
 [PATCH 08/35] Documentation: features: correct spelling
 [PATCH 09/35] Documentation: firmware-guide/acpi: correct spelling
 [PATCH 10/35] Documentation: hid: correct spelling
 [PATCH 11/35] Documentation: i2c: correct spelling
 [PATCH 12/35] Documentation: input: correct spelling
 [PATCH 13/35] Documentation: isdn: correct spelling
 [PATCH 14/35] Documentation: leds: correct spelling
 [PATCH 15/35] Documentation: litmus-tests: correct spelling
 [PATCH 16/35] Documentation: livepatch: correct spelling
 [PATCH 17/35] Documentation: locking: correct spelling
 [PATCH 18/35] Documentation: mm: correct spelling
 [PATCH 19/35] Documentation: openrisc: correct spelling
 [PATCH 20/35] Documentation: PCI: correct spelling
 [PATCH 21/35] Documentation: powerpc: correct spelling
 [PATCH 22/35] Documentation: power: correct spelling
 [PATCH 23/35] Documentation: s390: correct spelling
 [PATCH 24/35] Documentation: scheduler: correct spelling
 [PATCH 25/35] Documentation: security: correct spelling
 [PATCH 26/35] Documentation: sound: correct spelling
 [PATCH 27/35] Documentation: spi: correct spelling
 [PATCH 28/35] Documentation: target: correct spelling
 [PATCH 29/35] Documentation: timers: correct spelling
 [PATCH 30/35] Documentation: tools/rtla: correct spelling
 [PATCH 31/35] Documentation: trace: correct spelling
 [PATCH 32/35] Documentation: usb: correct spelling
 [PATCH 33/35] Documentation: w1: correct spelling
 [PATCH 34/35] Documentation: x86: correct spelling
 [PATCH 35/35] Documentation: xtensa: correct spelling


 Documentation/PCI/endpoint/pci-vntb-howto.rst|2 -
 Documentation/PCI/msi-howto.rst  |2 -
 Documentation/arm/arm.rst|2 -
 Documentation/arm/ixp4xx.rst |4 +-
 Documentation/arm/keystone/knav-qmss.rst |2 -
 Documentation/arm/stm32/stm32-dma-mdma-chaining.rst  |6 +--
 Documentation/arm/sunxi/clocks.rst   |2 -
 Documentation/arm/swp_emulation.rst  |2 -
 Documentation/arm/tcm.rst|2 -
 Documentation/arm/vlocks.rst |2 -
 Documentation/arm64/booting.rst  |2 -
 Documentation/arm64/elf_hwcaps.rst   |2 -
 Documentation/arm64/sve.rst  |4 +-
 Documentation/block/data-integrity.rst   |2 -
 Documentation/bpf/libbpf/libbpf_naming_convention.rst|6 +--
 Documentation/bpf/map_xskmap.rst |2 -
 Documentation/bpf/ringbuf.rst|4 +-
 Documentation/bpf/verifier.rst   |2 -
 Documentation/core-api/packing.rst   |2 -
 Documentation/core-api/padata.rst|2 -
 Documentation/fault-injection/fault-injection.rst|2 -
 Documentation/fb/sm712fb.rst |2 -
 Documentation/fb/sstfb.rst   |2 -
 Documentation/features/core/thread-info-in-task/arch-support.txt |2 -
 Documentation/firmware-guide/acpi/acpi-lid.rst   |2 -
 Documentation/firmware-guide/acpi/namespace.rst  |2 -
 Documentation/hid/hid-alps.rst   |2 -
 Documentation/hid/hid-bpf.rst|2 -
 Documentation/hid/hiddev.rst |2 -
 Documentation/hid/hidraw.rst |2 -
 Documentation/hid/intel-ish-hid.rst  |2 -
 Documentation/i2c/gpio-fault-injection.rst   |2 -
 Documentation/i2c/smbus-protocol.rst |2 -
 Documentation/input/devices/iforce-protocol.rst  |2 -
 Documentation/input/multi-touch-protocol.rst |2 -
 Documentation/isdn/interface_capi.rst|2 -
 Documentation/isdn/m_isdn.rst|2 -
 

[PATCH 21/35] Documentation: powerpc: correct spelling

2023-01-26 Thread Randy Dunlap
Correct spelling problems for Documentation/powerpc/ as reported
by codespell.

Signed-off-by: Randy Dunlap 
Cc: Michael Ellerman 
Cc: linuxppc-dev@lists.ozlabs.org
Cc: Jonathan Corbet 
Cc: linux-...@vger.kernel.org
---
 Documentation/powerpc/kasan.txt   |2 +-
 Documentation/powerpc/papr_hcalls.rst |2 +-
 Documentation/powerpc/qe_firmware.rst |4 ++--
 Documentation/powerpc/vas-api.rst |4 ++--
 4 files changed, 6 insertions(+), 6 deletions(-)

diff -- a/Documentation/powerpc/kasan.txt b/Documentation/powerpc/kasan.txt
--- a/Documentation/powerpc/kasan.txt
+++ b/Documentation/powerpc/kasan.txt
@@ -40,7 +40,7 @@ checks can be delayed until after the MM
 instrument any code that runs with translations off after booting. This is the
 current approach.
 
-To avoid this limitiation, the KASAN shadow would have to be placed inside the
+To avoid this limitation, the KASAN shadow would have to be placed inside the
 linear mapping, using the same high-bits trick we use for the rest of the 
linear
 mapping. This is tricky:
 
diff -- a/Documentation/powerpc/papr_hcalls.rst 
b/Documentation/powerpc/papr_hcalls.rst
--- a/Documentation/powerpc/papr_hcalls.rst
+++ b/Documentation/powerpc/papr_hcalls.rst
@@ -22,7 +22,7 @@ privileged operations. Currently there a
 On PPC64 arch a guest kernel running on top of a PAPR hypervisor is called
 a *pSeries guest*. A pseries guest runs in a supervisor mode (HV=0) and must
 issue hypercalls to the hypervisor whenever it needs to perform an action
-that is hypervisor priviledged [3]_ or for other services managed by the
+that is hypervisor privileged [3]_ or for other services managed by the
 hypervisor.
 
 Hence a Hypercall (hcall) is essentially a request by the pseries guest
diff -- a/Documentation/powerpc/qe_firmware.rst 
b/Documentation/powerpc/qe_firmware.rst
--- a/Documentation/powerpc/qe_firmware.rst
+++ b/Documentation/powerpc/qe_firmware.rst
@@ -232,11 +232,11 @@ For example, to match the 8323, revision
 'extended_modes' is a bitfield that defines special functionality which has an
 impact on the device drivers.  Each bit has its own impact and has special
 instructions for the driver associated with it.  This field is stored in
-the QE library and available to any driver that calles qe_get_firmware_info().
+the QE library and available to any driver that calls qe_get_firmware_info().
 
 'vtraps' is an array of 8 words that contain virtual trap values for each
 virtual traps.  As with 'extended_modes', this field is stored in the QE
-library and available to any driver that calles qe_get_firmware_info().
+library and available to any driver that calls qe_get_firmware_info().
 
 'microcode' (type: struct qe_microcode):
For each RISC processor there is one 'microcode' structure.  The first
diff -- a/Documentation/powerpc/vas-api.rst b/Documentation/powerpc/vas-api.rst
--- a/Documentation/powerpc/vas-api.rst
+++ b/Documentation/powerpc/vas-api.rst
@@ -46,7 +46,7 @@ request queue into the application's vir
 The application can then submit one or more requests to the engine by
 using copy/paste instructions and pasting the CRBs to the virtual address
 (aka paste_address) returned by mmap(). User space can close the
-established connection or send window by closing the file descriptior
+established connection or send window by closing the file descriptor
 (close(fd)) or upon the process exit.
 
 Note that applications can send several requests with the same window or
@@ -240,7 +240,7 @@ issued. This signal returns with the fol
siginfo.si_signo = SIGSEGV;
siginfo.si_errno = EFAULT;
siginfo.si_code = SEGV_MAPERR;
-   siginfo.si_addr = CSB adress;
+   siginfo.si_addr = CSB address;
 
 In the case of multi-thread applications, NX send windows can be shared
 across all threads. For example, a child thread can open a send window,


Re: [PATCH] powerpc/tlb: Remove BUILD_BUG for book3s/32/tlbflush.h local_flush_tlb_page_psize

2023-01-26 Thread Christophe Leroy


Le 26/01/2023 à 23:30, Benjamin Gray a écrit :
> On Wed, 2023-01-25 at 09:43 +, Christophe Leroy wrote:
> 
>> By the way, are you should the problem is really BUILD_BUG() ?
>> Looking
>> at your patch I would think that the problem is because it is "static
>> inline". Have you tried 'static __always_inline' instead ?
> 
> I did not try it, so I just did but it doesn't make a difference.
> 
> Looking further, the failing config also enabled
> CONFIG_JUMP_LABEL_FEATURE_CHECK_DEBUG, which causes the
> mmu_has_feature(MMU_FTR_TYPE_RADIX) call of radix_enabled() to be non-
> trivial. It must check static_key_initialized, and falls back to
> early_mmu_has_feature if it triggers. Clang apparently can't see that
> early_mmu_has_feature will also always return false for Radix, so
> doesn't see that everything guarded by radix_enabled() is dead code. I
> suppose it's complicated by the fact it still has to run
> mmu_has_feature for the assertion side effect despite the return value
> being knowable at compile time.
> 
> So because of this weird interaction, the following should (and does)
> also prevent the compilation error by making the radix_enabled() return
> value more obvious to the compiler in the case where Radix is not
> implemented. (I've put the constant second here so the early usage
> assertion still runs).

But then, that's probably not the only place where we may get an issue 
with radix_enabled() or any other use of mmu_has_feature() by the way.

We are in a trivial situation where the feature check is either always 
true or always false. Is it worth checking for jump label init in that 
case ?

I think the best solution should be to move the following trivial checks 
above the static_key_initialised check:

if (MMU_FTRS_ALWAYS & feature)
return true;

if (!(MMU_FTRS_POSSIBLE & feature))
return false;

Christophe

> 
> diff --git a/arch/powerpc/include/asm/mmu.h
> b/arch/powerpc/include/asm/mmu.h
> index 94b981152667..3592ff9a522b 100644
> --- a/arch/powerpc/include/asm/mmu.h
> +++ b/arch/powerpc/include/asm/mmu.h
> @@ -327,7 +327,7 @@ static inline void assert_pte_locked(struct
> mm_struct *mm, unsigned long addr)
>   
>   static __always_inline bool radix_enabled(void)
>   {
> -   return mmu_has_feature(MMU_FTR_TYPE_RADIX);
> +   return mmu_has_feature(MMU_FTR_TYPE_RADIX) &&
> IS_ENABLED(CONFIG_PPC_RADIX_MMU);
>   }
>   
>   static __always_inline bool early_radix_enabled(void)


Re: [PATCH] powerpc/kexec_file: account hot-pluggable memory while estimating FDT size

2023-01-26 Thread Sourabh Jain

Gentle reminder, any comments and suggestions on this fix.

- Sourabh

On 15/12/22 14:08, Sourabh Jain wrote:

On Systems where online memory is lesser compared to max memory, the
kexec_file_load system call may fail to load the kdump kernel with the
below errors:

 "Failed to update fdt with linux,drconf-usable-memory property"
 "Error setting up usable-memory property for kdump kernel"

This happens because the size estimation for usable memory properties
for the kdump kernel's FDT is based on the online memory whereas the
usable memory properties include max memory. In short, the hot-pluggable
memory is not accounted for while estimating the size of the usable
memory properties.

The issue is addressed by calculating usable memory property size using
max hotplug address instead of the last online memory address.

Fixes: 2377c92e37fe ("powerpc/kexec_file: fix FDT size estimation for kdump 
kernel")
Signed-off-by: Sourabh Jain 
---
  arch/powerpc/kexec/file_load_64.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/kexec/file_load_64.c 
b/arch/powerpc/kexec/file_load_64.c
index 349a781cea0b3..2c3fd6fe6bc94 100644
--- a/arch/powerpc/kexec/file_load_64.c
+++ b/arch/powerpc/kexec/file_load_64.c
@@ -947,7 +947,7 @@ unsigned int kexec_extra_fdt_size_ppc64(struct kimage 
*image)
 * linux,drconf-usable-memory properties. Get an approximate on the
 * number of usable memory entries and use for FDT size estimation.
 */
-   usm_entries = ((memblock_end_of_DRAM() / drmem_lmb_size()) +
+   usm_entries = ((memory_hotplug_max() / drmem_lmb_size()) +
   (2 * (resource_size(_res) / drmem_lmb_size(;
return (unsigned int)(usm_entries * sizeof(u64));
  }


Re: [PATCH] kasan: Fix Oops due to missing calls to kasan_arch_is_ready()

2023-01-26 Thread Michael Ellerman
Andrew Morton  writes:
> On Thu, 26 Jan 2023 08:04:47 +0100 Christophe Leroy 
>  wrote:
>
>> On powerpc64, you can build a kernel with KASAN as soon as you build it
>> with RADIX MMU support. However if the CPU doesn't have RADIX MMU,
>> KASAN isn't enabled at init and the following Oops is encountered.
>
> Should we backport to -stable?  If so, can we identify a suitable Fixes: 
> target?

It would be nice if it went to stable, but I'd defer to the Kasan maintainers.

The kasan_arch_is_ready() checks went in a while back, but there wasn't
a meaningful user until the powerpc support went in, so I'd target that:

Fixes: 41b7a347bf14 ("powerpc: Book3S 64-bit outline-only KASAN support")
Cc: sta...@vger.kernel.org # v5.19+

cheers


Re: [PATCH v4 02/24] powerpc/pseries: Fix alignment of PLPKS structures and buffers

2023-01-26 Thread Andrew Donnellan
On Thu, 2023-01-26 at 17:31 +, David Laight wrote:
> Changing the size to kzalloc() doesn't help.
> The alignment depends on the allocator and is only required to have
> a relatively small alignment (ARCH_MINALIGN?) regardless of the size.
> 
> IIRC one of the allocators adds a small header to every item.
> It won't return 16 byte aligned items at all.

I'm relying on the behaviour described in Documentation/core-
api/memory-allocation.rst:

The address of a chunk allocated with kmalloc is aligned to at
least ARCH_KMALLOC_MINALIGN bytes. For sizes which are a power of
two, the alignment is also guaranteed to be at least the respective
size.

Is this wrong?


Andrew

-- 
Andrew DonnellanOzLabs, ADL Canberra
a...@linux.ibm.com   IBM Australia Limited


Re: [PATCH v2 3/6] mm: replace vma->vm_flags direct modifications with modifier calls

2023-01-26 Thread Sebastian Reichel
Hi,

On Wed, Jan 25, 2023 at 12:38:48AM -0800, Suren Baghdasaryan wrote:
> Replace direct modifications to vma->vm_flags with calls to modifier
> functions to be able to track flag changes and to keep vma locking
> correctness.
> 
> Signed-off-by: Suren Baghdasaryan 
> ---
> [...]
>  drivers/hsi/clients/cmt_speech.c   |  2 +-
>  120 files changed, 188 insertions(+), 199 deletions(-)
> [...]
> diff --git a/drivers/hsi/clients/cmt_speech.c 
> b/drivers/hsi/clients/cmt_speech.c
> index 8069f795c864..952a31e742a1 100644
> --- a/drivers/hsi/clients/cmt_speech.c
> +++ b/drivers/hsi/clients/cmt_speech.c
> @@ -1264,7 +1264,7 @@ static int cs_char_mmap(struct file *file, struct 
> vm_area_struct *vma)
>   if (vma_pages(vma) != 1)
>   return -EINVAL;
>  
> - vma->vm_flags |= VM_IO | VM_DONTDUMP | VM_DONTEXPAND;
> + set_vm_flags(vma, VM_IO | VM_DONTDUMP | VM_DONTEXPAND);
>   vma->vm_ops = _char_vm_ops;
>   vma->vm_private_data = file->private_data;
>  

Acked-by: Sebastian Reichel 

-- Sebastian


signature.asc
Description: PGP signature


Re: [PATCH v2 1/6] mm: introduce vma->vm_flags modifier functions

2023-01-26 Thread Suren Baghdasaryan
On Thu, Jan 26, 2023 at 7:09 AM Matthew Wilcox  wrote:
>
> On Thu, Jan 26, 2023 at 04:50:59PM +0200, Mike Rapoport wrote:
> > On Thu, Jan 26, 2023 at 11:17:09AM +0200, Mike Rapoport wrote:
> > > On Wed, Jan 25, 2023 at 12:38:46AM -0800, Suren Baghdasaryan wrote:
> > > > +/* Use when VMA is not part of the VMA tree and needs no locking */
> > > > +static inline void init_vm_flags(struct vm_area_struct *vma,
> > > > +  unsigned long flags)
> > >
> > > I'd suggest to make it vm_flags_init() etc.
> >
> > Thinking more about it, it will be even clearer to name these 
> > vma_flags_xyz()
>
> Perhaps vma_VERB_flags()?
>
> vma_init_flags()
> vma_reset_flags()
> vma_set_flags()
> vma_clear_flags()
> vma_mod_flags()

Due to excessive email bouncing I posted the v3 of this patchset using
the original per-VMA patchset's distribution list. That might have
dropped Mike from the list. Sorry about that Mike, I'll add you to my
usual list of suspects :)
The v3 is here:
https://lore.kernel.org/all/20230125233554.153109-1-sur...@google.com/
and Andrew did suggest the same renames, so I'll be posting v4 with
those changes later today.
Thanks for the feedback!

>


[PATCH] scripts/spelling.txt: add "exsits" pattern and fix typo instances

2023-01-26 Thread Luca Ceresoli
Fix typos and add the following to the scripts/spelling.txt:

  exsits||exists

Signed-off-by: Luca Ceresoli 
---
 drivers/infiniband/ulp/iser/iscsi_iser.c | 2 +-
 net/openvswitch/flow_table.c | 2 +-
 scripts/spelling.txt | 1 +
 sound/soc/fsl/fsl-asoc-card.c| 2 +-
 4 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/infiniband/ulp/iser/iscsi_iser.c 
b/drivers/infiniband/ulp/iser/iscsi_iser.c
index 620ae5b2d80d..6b7603765383 100644
--- a/drivers/infiniband/ulp/iser/iscsi_iser.c
+++ b/drivers/infiniband/ulp/iser/iscsi_iser.c
@@ -446,7 +446,7 @@ iscsi_iser_conn_create(struct iscsi_cls_session 
*cls_session,
  * @is_leading:  indicate if this is the session leading connection (MCS)
  *
  * Return: zero on success, $error if iscsi_conn_bind fails and
- * -EINVAL in case end-point doesn't exsits anymore or iser connection
+ * -EINVAL in case end-point doesn't exists anymore or iser connection
  * state is not UP (teardown already started).
  */
 static int iscsi_iser_conn_bind(struct iscsi_cls_session *cls_session,
diff --git a/net/openvswitch/flow_table.c b/net/openvswitch/flow_table.c
index 0a0e4c283f02..cfac54cbafdf 100644
--- a/net/openvswitch/flow_table.c
+++ b/net/openvswitch/flow_table.c
@@ -1012,7 +1012,7 @@ static int flow_mask_insert(struct flow_table *tbl, 
struct sw_flow *flow,
 
mask = flow_mask_find(tbl, new);
if (!mask) {
-   /* Allocate a new mask if none exsits. */
+   /* Allocate a new mask if none exists. */
mask = mask_alloc();
if (!mask)
return -ENOMEM;
diff --git a/scripts/spelling.txt b/scripts/spelling.txt
index ded8bcfc0247..0147bd8dc6e2 100644
--- a/scripts/spelling.txt
+++ b/scripts/spelling.txt
@@ -625,6 +625,7 @@ exeuction||execution
 existance||existence
 existant||existent
 exixt||exist
+exsits||exists
 exlcude||exclude
 exlcusive||exclusive
 exmaple||example
diff --git a/sound/soc/fsl/fsl-asoc-card.c b/sound/soc/fsl/fsl-asoc-card.c
index 8d14b5593658..2f25358196ee 100644
--- a/sound/soc/fsl/fsl-asoc-card.c
+++ b/sound/soc/fsl/fsl-asoc-card.c
@@ -811,7 +811,7 @@ static int fsl_asoc_card_probe(struct platform_device *pdev)
priv->card.num_links = 1;
 
if (asrc_pdev) {
-   /* DPCM DAI Links only if ASRC exsits */
+   /* DPCM DAI Links only if ASRC exists */
priv->dai_link[1].cpus->of_node = asrc_np;
priv->dai_link[1].platforms->of_node = asrc_np;
priv->dai_link[2].codecs->dai_name = codec_dai_name;
-- 
2.34.1



[PATCH] ASoC: fsl-asoc-card: constify fsl_asoc_card_dai

2023-01-26 Thread Luca Ceresoli
This is never modified and can be made const.

Signed-off-by: Luca Ceresoli 
---
 sound/soc/fsl/fsl-asoc-card.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/fsl/fsl-asoc-card.c b/sound/soc/fsl/fsl-asoc-card.c
index 2f25358196ee..00118a75d126 100644
--- a/sound/soc/fsl/fsl-asoc-card.c
+++ b/sound/soc/fsl/fsl-asoc-card.c
@@ -297,7 +297,7 @@ SND_SOC_DAILINK_DEFS(hifi_be,
DAILINK_COMP_ARRAY(COMP_EMPTY()),
DAILINK_COMP_ARRAY(COMP_DUMMY()));
 
-static struct snd_soc_dai_link fsl_asoc_card_dai[] = {
+static const struct snd_soc_dai_link fsl_asoc_card_dai[] = {
/* Default ASoC DAI Link*/
{
.name = "HiFi",
-- 
2.34.1



Re: [PATCH v2 1/6] mm: introduce vma->vm_flags modifier functions

2023-01-26 Thread Matthew Wilcox
On Thu, Jan 26, 2023 at 04:50:59PM +0200, Mike Rapoport wrote:
> On Thu, Jan 26, 2023 at 11:17:09AM +0200, Mike Rapoport wrote:
> > On Wed, Jan 25, 2023 at 12:38:46AM -0800, Suren Baghdasaryan wrote:
> > > +/* Use when VMA is not part of the VMA tree and needs no locking */
> > > +static inline void init_vm_flags(struct vm_area_struct *vma,
> > > +  unsigned long flags)
> > 
> > I'd suggest to make it vm_flags_init() etc.
> 
> Thinking more about it, it will be even clearer to name these vma_flags_xyz()

Perhaps vma_VERB_flags()?

vma_init_flags()
vma_reset_flags()
vma_set_flags()
vma_clear_flags()
vma_mod_flags()



Re: [PATCH v2 1/6] mm: introduce vma->vm_flags modifier functions

2023-01-26 Thread Mike Rapoport
On Thu, Jan 26, 2023 at 11:17:09AM +0200, Mike Rapoport wrote:
> On Wed, Jan 25, 2023 at 12:38:46AM -0800, Suren Baghdasaryan wrote:
> > vm_flags are among VMA attributes which affect decisions like VMA merging
> > and splitting. Therefore all vm_flags modifications are performed after
> > taking exclusive mmap_lock to prevent vm_flags updates racing with such
> > operations. Introduce modifier functions for vm_flags to be used whenever
> > flags are updated. This way we can better check and control correct
> > locking behavior during these updates.
> > 
> > Signed-off-by: Suren Baghdasaryan 
> > ---
> >  include/linux/mm.h   | 37 +
> >  include/linux/mm_types.h |  8 +++-
> >  2 files changed, 44 insertions(+), 1 deletion(-)
> > 
> > diff --git a/include/linux/mm.h b/include/linux/mm.h
> > index c2f62bdce134..b71f2809caac 100644
> > --- a/include/linux/mm.h
> > +++ b/include/linux/mm.h
> > @@ -627,6 +627,43 @@ static inline void vma_init(struct vm_area_struct 
> > *vma, struct mm_struct *mm)
> > INIT_LIST_HEAD(>anon_vma_chain);
> >  }
> >  
> > +/* Use when VMA is not part of the VMA tree and needs no locking */
> > +static inline void init_vm_flags(struct vm_area_struct *vma,
> > +unsigned long flags)
> 
> I'd suggest to make it vm_flags_init() etc.

Thinking more about it, it will be even clearer to name these vma_flags_xyz()

> Except that
> 
> Acked-by: Mike Rapoport (IBM) 
> 

--
Sincerely yours,
Mike.


Re: [PATCH v2 6/6] mm: export dump_mm()

2023-01-26 Thread Mike Rapoport
On Wed, Jan 25, 2023 at 12:38:51AM -0800, Suren Baghdasaryan wrote:
> mmap_assert_write_locked() is used in vm_flags modifiers. Because
> mmap_assert_write_locked() uses dump_mm() and vm_flags are sometimes
> modified from from inside a module, it's necessary to export
> dump_mm() function.
> 
> Signed-off-by: Suren Baghdasaryan 

Acked-by: Mike Rapoport (IBM) 

> ---
>  mm/debug.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/mm/debug.c b/mm/debug.c
> index 9d3d893dc7f4..96d594e16292 100644
> --- a/mm/debug.c
> +++ b/mm/debug.c
> @@ -215,6 +215,7 @@ void dump_mm(const struct mm_struct *mm)
>   mm->def_flags, >def_flags
>   );
>  }
> +EXPORT_SYMBOL(dump_mm);
>  
>  static bool page_init_poisoning __read_mostly = true;
>  
> -- 
> 2.39.1
> 


Re: [PATCH 3/3] mm, arch: add generic implementation of pfn_valid() for FLATMEM

2023-01-26 Thread Guo Ren
On Thu, Jan 26, 2023 at 3:08 AM Mike Rapoport  wrote:
>
> From: "Mike Rapoport (IBM)" 
>
> Every architecture that supports FLATMEM memory model defines its own
> version of pfn_valid() that essentially compares a pfn to max_mapnr.
>
> Use mips/powerpc version implemented as static inline as a generic
> implementation of pfn_valid() and drop its per-architecture definitions
>
> Signed-off-by: Mike Rapoport (IBM) 
> ---
>  arch/alpha/include/asm/page.h  |  4 
>  arch/arc/include/asm/page.h|  1 -
>  arch/csky/include/asm/page.h   |  1 -
>  arch/hexagon/include/asm/page.h|  1 -
>  arch/ia64/include/asm/page.h   |  4 
>  arch/loongarch/include/asm/page.h  | 13 -
>  arch/m68k/include/asm/page_no.h|  2 --
>  arch/microblaze/include/asm/page.h |  1 -
>  arch/mips/include/asm/page.h   | 13 -
>  arch/nios2/include/asm/page.h  |  9 -
>  arch/openrisc/include/asm/page.h   |  2 --
>  arch/parisc/include/asm/page.h |  4 
>  arch/powerpc/include/asm/page.h|  9 -
>  arch/riscv/include/asm/page.h  |  5 -
>  arch/sh/include/asm/page.h |  3 ---
>  arch/sparc/include/asm/page_32.h   |  1 -
>  arch/um/include/asm/page.h |  1 -
>  arch/x86/include/asm/page_32.h |  4 
>  arch/x86/include/asm/page_64.h |  4 
>  arch/xtensa/include/asm/page.h |  2 --
>  include/asm-generic/memory_model.h | 12 
>  include/asm-generic/page.h |  2 --
>  22 files changed, 12 insertions(+), 86 deletions(-)
>
> diff --git a/arch/alpha/include/asm/page.h b/arch/alpha/include/asm/page.h
> index 8f3f5eecba28..227d32b6b75f 100644
> --- a/arch/alpha/include/asm/page.h
> +++ b/arch/alpha/include/asm/page.h
> @@ -87,10 +87,6 @@ typedef struct page *pgtable_t;
>  #define virt_to_page(kaddr)pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
>  #define virt_addr_valid(kaddr) pfn_valid((__pa(kaddr) >> PAGE_SHIFT))
>
> -#ifdef CONFIG_FLATMEM
> -#define pfn_valid(pfn) ((pfn) < max_mapnr)
> -#endif /* CONFIG_FLATMEM */
> -
>  #include 
>  #include 
>
> diff --git a/arch/arc/include/asm/page.h b/arch/arc/include/asm/page.h
> index 9a62e1d87967..e43fe27ec54d 100644
> --- a/arch/arc/include/asm/page.h
> +++ b/arch/arc/include/asm/page.h
> @@ -109,7 +109,6 @@ extern int pfn_valid(unsigned long pfn);
>  #else /* CONFIG_HIGHMEM */
>
>  #define ARCH_PFN_OFFSETvirt_to_pfn(CONFIG_LINUX_RAM_BASE)
> -#define pfn_valid(pfn) (((pfn) - ARCH_PFN_OFFSET) < max_mapnr)
>
>  #endif /* CONFIG_HIGHMEM */
>
> diff --git a/arch/csky/include/asm/page.h b/arch/csky/include/asm/page.h
> index ed7451478b1b..b23e3006a9e0 100644
> --- a/arch/csky/include/asm/page.h
> +++ b/arch/csky/include/asm/page.h
> @@ -39,7 +39,6 @@
>
>  #define virt_addr_valid(kaddr)  ((void *)(kaddr) >= (void *)PAGE_OFFSET && \
> (void *)(kaddr) < high_memory)
> -#define pfn_valid(pfn) ((pfn) >= ARCH_PFN_OFFSET && ((pfn) - 
> ARCH_PFN_OFFSET) < max_mapnr)
For csky part:
Acked-by: Guo Ren 

>
>  extern void *memset(void *dest, int c, size_t l);
>  extern void *memcpy(void *to, const void *from, size_t l);
> diff --git a/arch/hexagon/include/asm/page.h b/arch/hexagon/include/asm/page.h
> index d7d4f9fca327..9c03b9965f07 100644
> --- a/arch/hexagon/include/asm/page.h
> +++ b/arch/hexagon/include/asm/page.h
> @@ -95,7 +95,6 @@ struct page;
>  /* Default vm area behavior is non-executable.  */
>  #define VM_DATA_DEFAULT_FLAGS  VM_DATA_FLAGS_NON_EXEC
>
> -#define pfn_valid(pfn) ((pfn) < max_mapnr)
>  #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
>
>  /*  Need to not use a define for linesize; may move this to another file.  */
> diff --git a/arch/ia64/include/asm/page.h b/arch/ia64/include/asm/page.h
> index 1b990466d540..783eceab5df3 100644
> --- a/arch/ia64/include/asm/page.h
> +++ b/arch/ia64/include/asm/page.h
> @@ -97,10 +97,6 @@ do { \
>
>  #include 
>
> -#ifdef CONFIG_FLATMEM
> -# define pfn_valid(pfn)((pfn) < max_mapnr)
> -#endif
> -
>  #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
>  #define virt_to_page(kaddr)pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
>  #define pfn_to_kaddr(pfn)  __va((pfn) << PAGE_SHIFT)
> diff --git a/arch/loongarch/include/asm/page.h 
> b/arch/loongarch/include/asm/page.h
> index 53f284a96182..fb5338b352e6 100644
> --- a/arch/loongarch/include/asm/page.h
> +++ b/arch/loongarch/include/asm/page.h
> @@ -82,19 +82,6 @@ typedef struct { unsigned long pgprot; } pgprot_t;
>
>  #define pfn_to_kaddr(pfn)  __va((pfn) << PAGE_SHIFT)
>
> -#ifdef CONFIG_FLATMEM
> -
> -static inline int pfn_valid(unsigned long pfn)
> -{
> -   /* avoid  include hell */
> -   extern unsigned long max_mapnr;
> -   unsigned long pfn_offset = ARCH_PFN_OFFSET;
> -
> -   return pfn >= pfn_offset && pfn < max_mapnr;
> -}
> -
> -#endif
> -
>  #define virt_to_pfn(kaddr) PFN_DOWN(PHYSADDR(kaddr))
>  

Re: [PATCH] scripts/spelling.txt: add "exsits" pattern and fix typo instances

2023-01-26 Thread Jakub Kicinski
On Thu, 26 Jan 2023 16:22:05 +0100 Luca Ceresoli wrote:
> Fix typos and add the following to the scripts/spelling.txt:
> 
>   exsits||exists
> 
> Signed-off-by: Luca Ceresoli 

You need to split this up per subsystem, I reckon :(


[PATCH v5 15/15] perf jevents: Run metric_test.py at compile-time

2023-01-26 Thread Ian Rogers
Add a target that generates a log file for running metric_test.py and
make this a dependency on generating pmu-events.c. The log output is
displayed if the test fails like (the test was modified to make it
fail):

```
  TEST/tmp/perf/pmu-events/metric_test.log
F..
==
FAIL: test_Brackets (__main__.TestMetricExpressions)
--
Traceback (most recent call last):
  File "tools/perf/pmu-events/metric_test.py", line 33, in test_Brackets
self.assertEqual((a * b + c).ToPerfJson(), 'a * b + d')
AssertionError: 'a * b + c' != 'a * b + d'
- a * b + c
? ^
+ a * b + d
? ^

--
Ran 7 tests in 0.004s

FAILED (failures=1)
make[3]: *** [pmu-events/Build:32: /tmp/perf/pmu-events/metric_test.log] Error 1
```

However, normal execution will just show the TEST line.

This is roughly modeled on fortify testing in the kernel lib directory.

Modify metric_test.py so that it is executable. This is necessary when
PYTHON isn't specified in the build, the normal case.

Use variables to make the paths to files clearer and more consistent.
---
 tools/perf/pmu-events/Build  | 13 +++--
 tools/perf/pmu-events/metric_test.py |  1 +
 2 files changed, 12 insertions(+), 2 deletions(-)
 mode change 100644 => 100755 tools/perf/pmu-events/metric_test.py

diff --git a/tools/perf/pmu-events/Build b/tools/perf/pmu-events/Build
index a14de24ecb69..150765f2baee 100644
--- a/tools/perf/pmu-events/Build
+++ b/tools/perf/pmu-events/Build
@@ -6,6 +6,11 @@ JDIR_TEST  =  pmu-events/arch/test
 JSON_TEST  =  $(shell [ -d $(JDIR_TEST) ] &&   \
find $(JDIR_TEST) -name '*.json')
 JEVENTS_PY =  pmu-events/jevents.py
+METRIC_PY  =  pmu-events/metric.py
+METRIC_TEST_PY =  pmu-events/metric_test.py
+EMPTY_PMU_EVENTS_C = pmu-events/empty-pmu-events.c
+PMU_EVENTS_C   =  $(OUTPUT)pmu-events/pmu-events.c
+METRIC_TEST_LOG=  $(OUTPUT)pmu-events/metric_test.log
 
 ifeq ($(JEVENTS_ARCH),)
 JEVENTS_ARCH=$(SRCARCH)
@@ -18,11 +23,15 @@ JEVENTS_MODEL ?= all
 #
 
 ifeq ($(NO_JEVENTS),1)
-$(OUTPUT)pmu-events/pmu-events.c: pmu-events/empty-pmu-events.c
+$(PMU_EVENTS_C): $(EMPTY_PMU_EVENTS_C)
$(call rule_mkdir)
$(Q)$(call echo-cmd,gen)cp $< $@
 else
-$(OUTPUT)pmu-events/pmu-events.c: $(JSON) $(JSON_TEST) $(JEVENTS_PY) 
pmu-events/metric.py
+$(METRIC_TEST_LOG): $(METRIC_TEST_PY) $(METRIC_PY)
+   $(call rule_mkdir)
+   $(Q)$(call echo-cmd,test)$(PYTHON) $< 2> $@ || (cat $@ && false)
+
+$(PMU_EVENTS_C): $(JSON) $(JSON_TEST) $(JEVENTS_PY) $(METRIC_PY) 
$(METRIC_TEST_LOG)
$(call rule_mkdir)
$(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) 
$(JEVENTS_MODEL) pmu-events/arch $@
 endif
diff --git a/tools/perf/pmu-events/metric_test.py 
b/tools/perf/pmu-events/metric_test.py
old mode 100644
new mode 100755
index e4c792428277..40a3c7d8b2bc
--- a/tools/perf/pmu-events/metric_test.py
+++ b/tools/perf/pmu-events/metric_test.py
@@ -1,3 +1,4 @@
+#!/usr/bin/env python3
 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
 import unittest
 from metric import Constant
-- 
2.39.1.456.gfc5497dd1b-goog



[PATCH v5 14/15] tools build: Add test echo-cmd

2023-01-26 Thread Ian Rogers
Add quiet_cmd_test so that:
$(Q)$(call echo-cmd,test)

will print:
TEST   

This is useful for executing compile-time tests similar to what
happens for fortify tests in the kernel's lib directory.
---
 tools/build/Makefile.build | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/build/Makefile.build b/tools/build/Makefile.build
index 715092fc6a23..89430338a3d9 100644
--- a/tools/build/Makefile.build
+++ b/tools/build/Makefile.build
@@ -53,6 +53,7 @@ build-file := $(dir)/Build
 
 quiet_cmd_flex  = FLEX$@
 quiet_cmd_bison = BISON   $@
+quiet_cmd_test  = TEST$@
 
 # Create directory unless it exists
 quiet_cmd_mkdir = MKDIR   $(dir $@)
-- 
2.39.1.456.gfc5497dd1b-goog



[PATCH v5 13/15] perf jevents: Correct bad character encoding

2023-01-26 Thread Ian Rogers
A character encoding issue added a "3D" character that breaks the
metrics test.

Fixes: 40769665b63d ("perf jevents: Parse metrics during conversion")
---
 tools/perf/pmu-events/metric_test.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/pmu-events/metric_test.py 
b/tools/perf/pmu-events/metric_test.py
index ced5998bd827..e4c792428277 100644
--- a/tools/perf/pmu-events/metric_test.py
+++ b/tools/perf/pmu-events/metric_test.py
@@ -89,8 +89,8 @@ class TestMetricExpressions(unittest.TestCase):
 after = r'min((a + b if c > 1 else c + d), e + f)'
 self.assertEqual(ParsePerfJson(before).ToPerfJson(), after)
 
-before =3D r'a if b else c if d else e'
-after =3D r'(a if b else (c if d else e))'
+before = r'a if b else c if d else e'
+after = r'(a if b else (c if d else e))'
 self.assertEqual(ParsePerfJson(before).ToPerfJson(), after)
 
   def test_ToPython(self):
-- 
2.39.1.456.gfc5497dd1b-goog



[PATCH v5 12/15] perf pmu-events: Fix testing with JEVENTS_ARCH=all

2023-01-26 Thread Ian Rogers
The #slots literal will return NAN when not on ARM64 which causes a
perf test failure when not on an ARM64 for a JEVENTS_ARCH=all build:
..
 10.4: Parsing of PMU event table metrics with fake PMUs : FAILED!
..
Add an is_test boolean so that the failure can be avoided when running
as a test.

Fixes: acef233b7ca7 ("perf pmu: Add #slots literal support for arm64")
---
 tools/perf/tests/pmu-events.c | 1 +
 tools/perf/util/expr.h| 1 +
 tools/perf/util/expr.l| 8 +---
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c
index 962c3c0d53ba..accf44b3d968 100644
--- a/tools/perf/tests/pmu-events.c
+++ b/tools/perf/tests/pmu-events.c
@@ -950,6 +950,7 @@ static int metric_parse_fake(const char *metric_name, const 
char *str)
pr_debug("expr__ctx_new failed");
return TEST_FAIL;
}
+   ctx->sctx.is_test = true;
if (expr__find_ids(str, NULL, ctx) < 0) {
pr_err("expr__find_ids failed\n");
return -1;
diff --git a/tools/perf/util/expr.h b/tools/perf/util/expr.h
index 029271540fb0..eaa44b24c555 100644
--- a/tools/perf/util/expr.h
+++ b/tools/perf/util/expr.h
@@ -9,6 +9,7 @@ struct expr_scanner_ctx {
char *user_requested_cpu_list;
int runtime;
bool system_wide;
+   bool is_test;
 };
 
 struct expr_parse_ctx {
diff --git a/tools/perf/util/expr.l b/tools/perf/util/expr.l
index 0168a9637330..72ff4f3d6d4b 100644
--- a/tools/perf/util/expr.l
+++ b/tools/perf/util/expr.l
@@ -84,9 +84,11 @@ static int literal(yyscan_t scanner, const struct 
expr_scanner_ctx *sctx)
YYSTYPE *yylval = expr_get_lval(scanner);
 
yylval->num = expr__get_literal(expr_get_text(scanner), sctx);
-   if (isnan(yylval->num))
-   return EXPR_ERROR;
-
+   if (isnan(yylval->num)) {
+   if (!sctx->is_test)
+   return EXPR_ERROR;
+   yylval->num = 1;
+   }
return LITERAL;
 }
 %}
-- 
2.39.1.456.gfc5497dd1b-goog



[PATCH v5 11/15] perf jevents: Add model list option

2023-01-26 Thread Ian Rogers
This allows the set of generated jevents events and metrics be limited
to a subset of the model names. Appropriate if trying to minimize the
binary size where only a set of models are possible.
---
 tools/perf/pmu-events/Build  |  3 ++-
 tools/perf/pmu-events/jevents.py | 14 ++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/tools/perf/pmu-events/Build b/tools/perf/pmu-events/Build
index 15b9e8fdbffa..a14de24ecb69 100644
--- a/tools/perf/pmu-events/Build
+++ b/tools/perf/pmu-events/Build
@@ -10,6 +10,7 @@ JEVENTS_PY=  pmu-events/jevents.py
 ifeq ($(JEVENTS_ARCH),)
 JEVENTS_ARCH=$(SRCARCH)
 endif
+JEVENTS_MODEL ?= all
 
 #
 # Locate/process JSON files in pmu-events/arch/
@@ -23,5 +24,5 @@ $(OUTPUT)pmu-events/pmu-events.c: 
pmu-events/empty-pmu-events.c
 else
 $(OUTPUT)pmu-events/pmu-events.c: $(JSON) $(JSON_TEST) $(JEVENTS_PY) 
pmu-events/metric.py
$(call rule_mkdir)
-   $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) 
pmu-events/arch $@
+   $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) 
$(JEVENTS_MODEL) pmu-events/arch $@
 endif
diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py
index 627ee817f57f..2bcd07ce609f 100755
--- a/tools/perf/pmu-events/jevents.py
+++ b/tools/perf/pmu-events/jevents.py
@@ -599,6 +599,8 @@ const struct pmu_events_map pmu_events_map[] = {
 else:
   metric_tblname = 'NULL'
   metric_size = '0'
+if event_size == '0' and metric_size == '0':
+  continue
 cpuid = row[0].replace('\\', '')
 _args.output_file.write(f"""{{
 \t.arch = "{arch}",
@@ -888,12 +890,24 @@ def main() -> None:
   action: Callable[[Sequence[str], os.DirEntry], None]) -> None:
 """Replicate the directory/file walking behavior of C's file tree walk."""
 for item in os.scandir(path):
+  if _args.model != 'all' and item.is_dir():
+# Check if the model matches one in _args.model.
+if len(parents) == _args.model.split(',')[0].count('/'):
+  # We're testing the correct directory.
+  item_path = '/'.join(parents) + ('/' if len(parents) > 0 else '') + 
item.name
+  if 'test' not in item_path and item_path not in 
_args.model.split(','):
+continue
   action(parents, item)
   if item.is_dir():
 ftw(item.path, parents + [item.name], action)
 
   ap = argparse.ArgumentParser()
   ap.add_argument('arch', help='Architecture name like x86')
+  ap.add_argument('model', help='''Select a model such as skylake to
+reduce the code size.  Normally set to "all". For architectures like
+ARM64 with an implementor/model, the model must include the implementor
+such as "arm/cortex-a34".''',
+  default='all')
   ap.add_argument(
   'starting_dir',
   type=dir_path,
-- 
2.39.1.456.gfc5497dd1b-goog



[PATCH v5 10/15] perf jevents: Generate metrics and events as separate tables

2023-01-26 Thread Ian Rogers
Turn a perf json event into an event, metric or both. This reduces the
number of events needed to scan to find an event or metric. As events
no longer need the relatively seldom used metric fields, 4 bytes is
saved per event. This reduces the big C string's size by 335kb (14.8%)
on x86.

Note, for the test PMU architecture pme_test_soc_cpu is renamed
pmu_events__test_soc_cpu for consistency with the event vs metric
naming convention.
---
 tools/perf/pmu-events/jevents.py | 244 +++
 tools/perf/tests/pmu-events.c|   3 +-
 2 files changed, 189 insertions(+), 58 deletions(-)

diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py
index d83cc94af51f..627ee817f57f 100755
--- a/tools/perf/pmu-events/jevents.py
+++ b/tools/perf/pmu-events/jevents.py
@@ -13,28 +13,40 @@ import collections
 
 # Global command line arguments.
 _args = None
+# List of regular event tables.
+_event_tables = []
 # List of event tables generated from "/sys" directories.
 _sys_event_tables = []
+# List of regular metric tables.
+_metric_tables = []
+# List of metric tables generated from "/sys" directories.
+_sys_metric_tables = []
+# Mapping between sys event table names and sys metric table names.
+_sys_event_table_to_metric_table_mapping = {}
 # Map from an event name to an architecture standard
 # JsonEvent. Architecture standard events are in json files in the top
 # f'{_args.starting_dir}/{_args.arch}' directory.
 _arch_std_events = {}
 # Events to write out when the table is closed
 _pending_events = []
-# Name of table to be written out
+# Name of events table to be written out
 _pending_events_tblname = None
+# Metrics to write out when the table is closed
+_pending_metrics = []
+# Name of metrics table to be written out
+_pending_metrics_tblname = None
 # Global BigCString shared by all structures.
 _bcs = None
 # Order specific JsonEvent attributes will be visited.
 _json_event_attributes = [
 # cmp_sevent related attributes.
-'name', 'pmu', 'topic', 'desc', 'metric_name', 'metric_group',
+'name', 'pmu', 'topic', 'desc',
 # Seems useful, put it early.
 'event',
 # Short things in alphabetical order.
 'aggr_mode', 'compat', 'deprecated', 'perpkg', 'unit',
 # Longer things (the last won't be iterated over during decompress).
-'metric_constraint', 'metric_expr', 'long_desc'
+'long_desc'
 ]
 
 # Attributes that are in pmu_metric rather than pmu_event.
@@ -52,14 +64,16 @@ def removesuffix(s: str, suffix: str) -> str:
   return s[0:-len(suffix)] if s.endswith(suffix) else s
 
 
-def file_name_to_table_name(parents: Sequence[str], dirname: str) -> str:
+def file_name_to_table_name(prefix: str, parents: Sequence[str],
+dirname: str) -> str:
   """Generate a C table name from directory names."""
-  tblname = 'pme'
+  tblname = prefix
   for p in parents:
 tblname += '_' + p
   tblname += '_' + dirname
   return tblname.replace('-', '_')
 
+
 def c_len(s: str) -> int:
   """Return the length of s a C string
 
@@ -277,7 +291,7 @@ class JsonEvent:
 self.metric_constraint = jd.get('MetricConstraint')
 self.metric_expr = None
 if 'MetricExpr' in jd:
-   self.metric_expr = metric.ParsePerfJson(jd['MetricExpr']).Simplify()
+  self.metric_expr = metric.ParsePerfJson(jd['MetricExpr']).Simplify()
 
 arch_std = jd.get('ArchStdEvent')
 if precise and self.desc and '(Precise Event)' not in self.desc:
@@ -326,23 +340,24 @@ class JsonEvent:
 s += f'\t{attr} = {value},\n'
 return s + '}'
 
-  def build_c_string(self) -> str:
+  def build_c_string(self, metric: bool) -> str:
 s = ''
-for attr in _json_event_attributes:
+for attr in _json_metric_attributes if metric else _json_event_attributes:
   x = getattr(self, attr)
-  if x and attr == 'metric_expr':
+  if metric and x and attr == 'metric_expr':
 # Convert parsed metric expressions into a string. Slashes
 # must be doubled in the file.
 x = x.ToPerfJson().replace('\\', '')
   s += f'{x}\\000' if x else '\\000'
 return s
 
-  def to_c_string(self) -> str:
+  def to_c_string(self, metric: bool) -> str:
 """Representation of the event as a C struct initializer."""
 
-s = self.build_c_string()
+s = self.build_c_string(metric)
 return f'{{ { _bcs.offsets[s] } }}, /* {s} */\n'
 
+
 @lru_cache(maxsize=None)
 def read_json_events(path: str, topic: str) -> Sequence[JsonEvent]:
   """Read json events from the specified file."""
@@ -381,7 +396,10 @@ def preprocess_arch_std_files(archpath: str) -> None:
 def add_events_table_entries(item: os.DirEntry, topic: str) -> None:
   """Add contents of file to _pending_events table."""
   for e in read_json_events(item.path, topic):
-_pending_events.append(e)
+if e.name:
+  _pending_events.append(e)
+if e.metric_name:
+  _pending_metrics.append(e)
 
 
 def print_pending_events() -> None:
@@ -401,15 +419,54 

[PATCH v5 09/15] perf pmu-events: Introduce pmu_metrics_table

2023-01-26 Thread Ian Rogers
Add a metrics table that is just a cast from pmu_events_table. This
changes the APIs so that event and metric usage of the underlying
table is different. For the no jevents case the tables are already
separate, later changes will separate the tables for the jevents case.
---
 tools/perf/arch/arm64/util/pmu.c | 11 -
 tools/perf/pmu-events/empty-pmu-events.c | 21 -
 tools/perf/pmu-events/jevents.py | 21 ++---
 tools/perf/pmu-events/pmu-events.h   | 10 +++--
 tools/perf/tests/expand-cgroup.c |  2 +-
 tools/perf/tests/parse-metric.c  |  2 +-
 tools/perf/tests/pmu-events.c|  5 ++-
 tools/perf/util/metricgroup.c| 54 
 tools/perf/util/metricgroup.h|  2 +-
 tools/perf/util/pmu.c|  5 +++
 tools/perf/util/pmu.h|  1 +
 11 files changed, 78 insertions(+), 56 deletions(-)

diff --git a/tools/perf/arch/arm64/util/pmu.c b/tools/perf/arch/arm64/util/pmu.c
index 801bf52e2ea6..2779840d8896 100644
--- a/tools/perf/arch/arm64/util/pmu.c
+++ b/tools/perf/arch/arm64/util/pmu.c
@@ -22,7 +22,14 @@ static struct perf_pmu *pmu__find_core_pmu(void)
return NULL;
 
return pmu;
-   }
+}
+
+const struct pmu_metrics_table *pmu_metrics_table__find(void)
+{
+   struct perf_pmu *pmu = pmu__find_core_pmu();
+
+   if (pmu)
+   return perf_pmu__find_metrics_table(pmu);
 
return NULL;
 }
@@ -32,7 +39,7 @@ const struct pmu_events_table *pmu_events_table__find(void)
struct perf_pmu *pmu = pmu__find_core_pmu();
 
if (pmu)
-   return perf_pmu__find_table(pmu);
+   return perf_pmu__find_events_table(pmu);
 
return NULL;
 }
diff --git a/tools/perf/pmu-events/empty-pmu-events.c 
b/tools/perf/pmu-events/empty-pmu-events.c
index 10bd4943ebf8..a938b74cf487 100644
--- a/tools/perf/pmu-events/empty-pmu-events.c
+++ b/tools/perf/pmu-events/empty-pmu-events.c
@@ -278,13 +278,11 @@ int pmu_events_table_for_each_event(const struct 
pmu_events_table *table, pmu_ev
return 0;
 }
 
-int pmu_events_table_for_each_metric(const struct pmu_events_table *etable, 
pmu_metric_iter_fn fn,
-void *data)
+int pmu_metrics_table_for_each_metric(const struct pmu_metrics_table *table, 
pmu_metric_iter_fn fn,
+ void *data)
 {
-   struct pmu_metrics_table *table = (struct pmu_metrics_table *)etable;
-
for (const struct pmu_metric *pm = >entries[0]; pm->metric_expr; 
pm++) {
-   int ret = fn(pm, etable, data);
+   int ret = fn(pm, table, data);
 
if (ret)
return ret;
@@ -320,9 +318,9 @@ const struct pmu_events_table 
*perf_pmu__find_events_table(struct perf_pmu *pmu)
return table;
 }
 
-const struct pmu_events_table *perf_pmu__find_metrics_table(struct perf_pmu 
*pmu)
+const struct pmu_metrics_table *perf_pmu__find_metrics_table(struct perf_pmu 
*pmu)
 {
-   const struct pmu_events_table *table = NULL;
+   const struct pmu_metrics_table *table = NULL;
char *cpuid = perf_pmu__getcpuid(pmu);
int i;
 
@@ -340,7 +338,7 @@ const struct pmu_events_table 
*perf_pmu__find_metrics_table(struct perf_pmu *pmu
break;
 
if (!strcmp_cpuid_str(map->cpuid, cpuid)) {
-   table = (const struct pmu_events_table 
*)>metric_table;
+   table = >metric_table;
break;
}
}
@@ -359,13 +357,13 @@ const struct pmu_events_table 
*find_core_events_table(const char *arch, const ch
return NULL;
 }
 
-const struct pmu_events_table *find_core_metrics_table(const char *arch, const 
char *cpuid)
+const struct pmu_metrics_table *find_core_metrics_table(const char *arch, 
const char *cpuid)
 {
for (const struct pmu_events_map *tables = _events_map[0];
 tables->arch;
 tables++) {
if (!strcmp(tables->arch, arch) && 
!strcmp_cpuid_str(tables->cpuid, cpuid))
-   return (const struct pmu_events_table 
*)>metric_table;
+   return >metric_table;
}
return NULL;
 }
@@ -386,8 +384,7 @@ int pmu_for_each_core_metric(pmu_metric_iter_fn fn, void 
*data)
for (const struct pmu_events_map *tables = _events_map[0];
 tables->arch;
 tables++) {
-   int ret = pmu_events_table_for_each_metric(
-   (const struct pmu_events_table *)>metric_table, 
fn, data);
+   int ret = 
pmu_metrics_table_for_each_metric(>metric_table, fn, data);
 
if (ret)
return ret;
diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py
index 5f8d490c7269..d83cc94af51f 100755
--- a/tools/perf/pmu-events/jevents.py
+++ 

[PATCH v5 08/15] perf jevents: Combine table prefix and suffix writing

2023-01-26 Thread Ian Rogers
Combine into a single function to simplify, in a later change, writing
metrics separately.
---
 tools/perf/pmu-events/jevents.py | 36 +---
 1 file changed, 14 insertions(+), 22 deletions(-)

diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py
index 4cdbf34b7298..5f8d490c7269 100755
--- a/tools/perf/pmu-events/jevents.py
+++ b/tools/perf/pmu-events/jevents.py
@@ -19,10 +19,10 @@ _sys_event_tables = []
 # JsonEvent. Architecture standard events are in json files in the top
 # f'{_args.starting_dir}/{_args.arch}' directory.
 _arch_std_events = {}
-# Track whether an events table is currently being defined and needs closing.
-_close_table = False
 # Events to write out when the table is closed
 _pending_events = []
+# Name of table to be written out
+_pending_events_tblname = None
 # Global BigCString shared by all structures.
 _bcs = None
 # Order specific JsonEvent attributes will be visited.
@@ -378,24 +378,13 @@ def preprocess_arch_std_files(archpath: str) -> None:
   _arch_std_events[event.metric_name.lower()] = event
 
 
-def print_events_table_prefix(tblname: str) -> None:
-  """Called when a new events table is started."""
-  global _close_table
-  if _close_table:
-raise IOError('Printing table prefix but last table has no suffix')
-  _args.output_file.write(f'static const struct compact_pmu_event {tblname}[] 
= {{\n')
-  _close_table = True
-
-
 def add_events_table_entries(item: os.DirEntry, topic: str) -> None:
   """Add contents of file to _pending_events table."""
-  if not _close_table:
-raise IOError('Table entries missing prefix')
   for e in read_json_events(item.path, topic):
 _pending_events.append(e)
 
 
-def print_events_table_suffix() -> None:
+def print_pending_events() -> None:
   """Optionally close events table."""
 
   def event_cmp_key(j: JsonEvent) -> Tuple[bool, str, str, str, str]:
@@ -407,17 +396,19 @@ def print_events_table_suffix() -> None:
 return (j.desc is not None, fix_none(j.topic), fix_none(j.name), 
fix_none(j.pmu),
 fix_none(j.metric_name))
 
-  global _close_table
-  if not _close_table:
+  global _pending_events
+  if not _pending_events:
 return
 
-  global _pending_events
+  global _pending_events_tblname
+  _args.output_file.write(
+  f'static const struct compact_pmu_event {_pending_events_tblname}[] = 
{{\n')
+
   for event in sorted(_pending_events, key=event_cmp_key):
 _args.output_file.write(event.to_c_string())
-_pending_events = []
+  _pending_events = []
 
   _args.output_file.write('};\n\n')
-  _close_table = False
 
 def get_topic(topic: str) -> str:
   if topic.endswith('metrics.json'):
@@ -455,12 +446,13 @@ def process_one_file(parents: Sequence[str], item: 
os.DirEntry) -> None:
 
   # model directory, reset topic
   if item.is_dir() and is_leaf_dir(item.path):
-print_events_table_suffix()
+print_pending_events()
 
 tblname = file_name_to_table_name(parents, item.name)
 if item.name == 'sys':
   _sys_event_tables.append(tblname)
-print_events_table_prefix(tblname)
+global _pending_events_tblname
+_pending_events_tblname = tblname
 return
 
   # base dir or too deep
@@ -809,7 +801,7 @@ struct compact_pmu_event {
   for arch in archs:
 arch_path = f'{_args.starting_dir}/{arch}'
 ftw(arch_path, [], process_one_file)
-print_events_table_suffix()
+print_pending_events()
 
   print_mapping_table(archs)
   print_system_mapping_table()
-- 
2.39.1.456.gfc5497dd1b-goog



[PATCH v5 07/15] perf stat: Remove evsel metric_name/expr

2023-01-26 Thread Ian Rogers
Metrics are their own unit and these variables held broken metrics
previously and now just hold the value NULL. Remove code that used
these variables.

Reviewed-by: John Garry 
---
 tools/perf/builtin-stat.c |   1 -
 tools/perf/util/cgroup.c  |   1 -
 tools/perf/util/evsel.c   |   2 -
 tools/perf/util/evsel.h   |   2 -
 tools/perf/util/python.c  |   7 ---
 tools/perf/util/stat-shadow.c | 112 --
 tools/perf/util/stat.h|   1 -
 7 files changed, 126 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 9f3e4b257516..5d18a5a6f662 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -2524,7 +2524,6 @@ int cmd_stat(int argc, const char **argv)
_config.metric_events);
zfree();
}
-   perf_stat__collect_metric_expr(evsel_list);
perf_stat__init_shadow_stats();
 
if (add_default_attributes())
diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c
index cd978c240e0d..bfb13306d82c 100644
--- a/tools/perf/util/cgroup.c
+++ b/tools/perf/util/cgroup.c
@@ -481,7 +481,6 @@ int evlist__expand_cgroup(struct evlist *evlist, const char 
*str,
nr_cgroups++;
 
if (metric_events) {
-   perf_stat__collect_metric_expr(tmp_list);
if (metricgroup__copy_metric_events(tmp_list, cgrp,
metric_events,

_metric_events) < 0)
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 8550638587e5..a90e998826e0 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -285,8 +285,6 @@ void evsel__init(struct evsel *evsel,
evsel->sample_size = __evsel__sample_size(attr->sample_type);
evsel__calc_id_pos(evsel);
evsel->cmdline_group_boundary = false;
-   evsel->metric_expr   = NULL;
-   evsel->metric_name   = NULL;
evsel->metric_events = NULL;
evsel->per_pkg_mask  = NULL;
evsel->collect_stat  = false;
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index d572be41b960..24cb807ef6ce 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -105,8 +105,6 @@ struct evsel {
 * metric fields are similar, but needs more care as they can have
 * references to other metric (evsel).
 */
-   const char *metric_expr;
-   const char *metric_name;
struct evsel**metric_events;
struct evsel*metric_leader;
 
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index 9e5d881b0987..42e8b813d010 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -76,13 +76,6 @@ const char *perf_env__arch(struct perf_env *env 
__maybe_unused)
return NULL;
 }
 
-/*
- * Add this one here not to drag util/stat-shadow.c
- */
-void perf_stat__collect_metric_expr(struct evlist *evsel_list)
-{
-}
-
 /*
  * These ones are needed not to drag the PMU bandwagon, jevents generated
  * pmu_sys_event_tables, etc and evsel__find_pmu() is used so far just for
diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c
index cadb2df23c87..35ea4813f468 100644
--- a/tools/perf/util/stat-shadow.c
+++ b/tools/perf/util/stat-shadow.c
@@ -346,114 +346,6 @@ static const char *get_ratio_color(enum grc_type type, 
double ratio)
return color;
 }
 
-static struct evsel *perf_stat__find_event(struct evlist *evsel_list,
-   const char *name)
-{
-   struct evsel *c2;
-
-   evlist__for_each_entry (evsel_list, c2) {
-   if (!strcasecmp(c2->name, name) && !c2->collect_stat)
-   return c2;
-   }
-   return NULL;
-}
-
-/* Mark MetricExpr target events and link events using them to them. */
-void perf_stat__collect_metric_expr(struct evlist *evsel_list)
-{
-   struct evsel *counter, *leader, **metric_events, *oc;
-   bool found;
-   struct expr_parse_ctx *ctx;
-   struct hashmap_entry *cur;
-   size_t bkt;
-   int i;
-
-   ctx = expr__ctx_new();
-   if (!ctx) {
-   pr_debug("expr__ctx_new failed");
-   return;
-   }
-   evlist__for_each_entry(evsel_list, counter) {
-   bool invalid = false;
-
-   leader = evsel__leader(counter);
-   if (!counter->metric_expr)
-   continue;
-
-   expr__ctx_clear(ctx);
-   metric_events = counter->metric_events;
-   if (!metric_events) {
-   if (expr__find_ids(counter->metric_expr,
-  counter->name,
-  ctx) < 0)
-   continue;
-
-   

[PATCH v5 06/15] perf pmu-events: Remove now unused event and metric variables

2023-01-26 Thread Ian Rogers
Previous changes separated the uses of pmu_event and pmu_metric,
however, both structures contained all the variables of event and
metric. This change removes the event variables from metric and the
metric variables from event.

Note, this change removes the setting of evsel's metric_name/expr as
these fields are no longer part of struct pmu_event. The metric
remains but is no longer implicitly requested when the event is. This
impacts a few Intel uncore events, however, as the ScaleUnit is shared
by the event and the metric this utility is questionable. Also the
MetricNames look broken (contain spaces) in some cases and when trying
to use the functionality with '-e' the metrics fail but regular
metrics with '-M' work. For example, on SkylakeX '-M' works:

```
$ perf stat -M LLC_MISSES.PCIE_WRITE -a sleep 1

 Performance counter stats for 'system wide':

 0  UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 #  57896.0 
Bytes  LLC_MISSES.PCIE_WRITE  (49.84%)
 7,174  UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 
   (49.85%)
 0  UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 
   (50.16%)
63  UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 
   (50.15%)

   1.004576381 seconds time elapsed
```

whilst the event '-e' version is broken even with --group/-g (fwiw, we should 
also remove -g [1]):

```
$ perf stat -g -e LLC_MISSES.PCIE_WRITE -g -a sleep 1
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric 
expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric 
expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric 
expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric 
expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric 
expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric 
expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric 
expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric 
expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric 
expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric 
expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric 
expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric 
expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric 
expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric 
expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric 
expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric 
expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric 
expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric 
expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric 
expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric 
expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric 
expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric 
expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric 
expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric 
expression for LLC_MISSES.PCIE_WRITE

 Performance counter stats for 'system wide':

27,316 Bytes LLC_MISSES.PCIE_WRITE

   1.004505469 seconds time elapsed
```

The code also carries warnings where the user is supposed to select
events for metrics [2] but given the lack of use of such a feature,
let's clean the code and just remove.

[1] https://lore.kernel.org/lkml/20220707195610.303254-1-irog...@google.com/
[2] 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/util/stat-shadow.c?id=01b8957b738f42f96a130079bc951b3cc78c5b8a#n425

Reviewed-by: John Garry 
---
 tools/perf/builtin-list.c  | 20 ++---
 tools/perf/pmu-events/jevents.py   | 20 +
 tools/perf/pmu-events/pmu-events.h | 22 +--
 

[PATCH v5 05/15] perf pmu-events: Separate the metrics from events for no jevents

2023-01-26 Thread Ian Rogers
Separate the event and metric table when building without jevents. Add
find_core_metrics_table and perf_pmu__find_metrics_table while
renaming existing utilities to be event specific, so that users can
find the right table for their need.

Reviewed-by: John Garry 
---
 tools/perf/pmu-events/empty-pmu-events.c | 88 ++--
 tools/perf/pmu-events/jevents.py |  7 +-
 tools/perf/pmu-events/pmu-events.h   |  4 +-
 tools/perf/tests/expand-cgroup.c |  2 +-
 tools/perf/tests/parse-metric.c  |  2 +-
 tools/perf/util/pmu.c|  4 +-
 6 files changed, 79 insertions(+), 28 deletions(-)

diff --git a/tools/perf/pmu-events/empty-pmu-events.c 
b/tools/perf/pmu-events/empty-pmu-events.c
index 4e39d1a8d6d6..10bd4943ebf8 100644
--- a/tools/perf/pmu-events/empty-pmu-events.c
+++ b/tools/perf/pmu-events/empty-pmu-events.c
@@ -11,7 +11,7 @@
 #include 
 #include 
 
-static const struct pmu_event pme_test_soc_cpu[] = {
+static const struct pmu_event pmu_events__test_soc_cpu[] = {
{
.name = "l3_cache_rd",
.event = "event=0x40",
@@ -105,6 +105,14 @@ static const struct pmu_event pme_test_soc_cpu[] = {
.desc = "L2 BTB Correction",
.topic = "branch",
},
+   {
+   .name = 0,
+   .event = 0,
+   .desc = 0,
+   },
+};
+
+static const struct pmu_metric pmu_metrics__test_soc_cpu[] = {
{
.metric_expr= "1 / IPC",
.metric_name= "CPI",
@@ -170,9 +178,8 @@ static const struct pmu_event pme_test_soc_cpu[] = {
.metric_name= "L1D_Cache_Fill_BW",
},
{
-   .name = 0,
-   .event = 0,
-   .desc = 0,
+   .metric_expr = 0,
+   .metric_name = 0,
},
 };
 
@@ -197,7 +204,8 @@ struct pmu_metrics_table {
 struct pmu_events_map {
const char *arch;
const char *cpuid;
-   const struct pmu_events_table table;
+   const struct pmu_events_table event_table;
+   const struct pmu_metrics_table metric_table;
 };
 
 /*
@@ -208,12 +216,14 @@ static const struct pmu_events_map pmu_events_map[] = {
{
.arch = "testarch",
.cpuid = "testcpu",
-   .table = { pme_test_soc_cpu },
+   .event_table = { pmu_events__test_soc_cpu },
+   .metric_table = { pmu_metrics__test_soc_cpu },
},
{
.arch = 0,
.cpuid = 0,
-   .table = { 0 },
+   .event_table = { 0 },
+   .metric_table = { 0 },
},
 };
 
@@ -259,12 +269,9 @@ static const struct pmu_sys_events pmu_sys_event_tables[] 
= {
 int pmu_events_table_for_each_event(const struct pmu_events_table *table, 
pmu_event_iter_fn fn,
void *data)
 {
-   for (const struct pmu_event *pe = >entries[0]; pe->name || 
pe->metric_expr; pe++) {
-   int ret;
+   for (const struct pmu_event *pe = >entries[0]; pe->name; pe++) {
+   int ret = fn(pe, table, data);
 
-   if (!pe->name)
-   continue;
-   ret = fn(pe, table, data);
if (ret)
return ret;
}
@@ -276,19 +283,44 @@ int pmu_events_table_for_each_metric(const struct 
pmu_events_table *etable, pmu_
 {
struct pmu_metrics_table *table = (struct pmu_metrics_table *)etable;
 
-   for (const struct pmu_metric *pm = >entries[0]; pm->name || 
pm->metric_expr; pm++) {
-   int ret;
+   for (const struct pmu_metric *pm = >entries[0]; pm->metric_expr; 
pm++) {
+   int ret = fn(pm, etable, data);
 
-   if (!pm->metric_expr)
-   continue;
-   ret = fn(pm, etable, data);
if (ret)
return ret;
}
return 0;
 }
 
-const struct pmu_events_table *perf_pmu__find_table(struct perf_pmu *pmu)
+const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu 
*pmu)
+{
+   const struct pmu_events_table *table = NULL;
+   char *cpuid = perf_pmu__getcpuid(pmu);
+   int i;
+
+   /* on some platforms which uses cpus map, cpuid can be NULL for
+* PMUs other than CORE PMUs.
+*/
+   if (!cpuid)
+   return NULL;
+
+   i = 0;
+   for (;;) {
+   const struct pmu_events_map *map = _events_map[i++];
+
+   if (!map->cpuid)
+   break;
+
+   if (!strcmp_cpuid_str(map->cpuid, cpuid)) {
+   table = >event_table;
+   break;
+   }
+   }
+   free(cpuid);
+   return table;
+}
+
+const struct pmu_events_table *perf_pmu__find_metrics_table(struct perf_pmu 
*pmu)
 {
const struct pmu_events_table *table = NULL;
char *cpuid = 

[PATCH v5 04/15] perf pmu-events: Add separate metric from pmu_event

2023-01-26 Thread Ian Rogers
Create a new pmu_metric for the metric related variables from
pmu_event but that is initially just a clone of pmu_event. Add
iterators for pmu_metric and use in places that metrics are desired
rather than events. Make the event iterator skip metric only events,
and the metric iterator skip event only events.

Reviewed-by: John Garry 
---
 tools/perf/arch/powerpc/util/header.c|   4 +-
 tools/perf/pmu-events/empty-pmu-events.c |  49 ++-
 tools/perf/pmu-events/jevents.py |  62 -
 tools/perf/pmu-events/pmu-events.h   |  26 
 tools/perf/tests/pmu-events.c|  35 +++--
 tools/perf/util/metricgroup.c| 161 +++
 tools/perf/util/metricgroup.h|   2 +-
 7 files changed, 228 insertions(+), 111 deletions(-)

diff --git a/tools/perf/arch/powerpc/util/header.c 
b/tools/perf/arch/powerpc/util/header.c
index e8fe36b10d20..78eef77d8a8d 100644
--- a/tools/perf/arch/powerpc/util/header.c
+++ b/tools/perf/arch/powerpc/util/header.c
@@ -40,11 +40,11 @@ get_cpuid_str(struct perf_pmu *pmu __maybe_unused)
return bufp;
 }
 
-int arch_get_runtimeparam(const struct pmu_event *pe)
+int arch_get_runtimeparam(const struct pmu_metric *pm)
 {
int count;
char path[PATH_MAX] = "/devices/hv_24x7/interface/";
 
-   atoi(pe->aggr_mode) == PerChip ? strcat(path, "sockets") : strcat(path, 
"coresperchip");
+   atoi(pm->aggr_mode) == PerChip ? strcat(path, "sockets") : strcat(path, 
"coresperchip");
return sysfs__read_int(path, ) < 0 ? 1 : count;
 }
diff --git a/tools/perf/pmu-events/empty-pmu-events.c 
b/tools/perf/pmu-events/empty-pmu-events.c
index 480e8f0d30c8..4e39d1a8d6d6 100644
--- a/tools/perf/pmu-events/empty-pmu-events.c
+++ b/tools/perf/pmu-events/empty-pmu-events.c
@@ -181,6 +181,11 @@ struct pmu_events_table {
const struct pmu_event *entries;
 };
 
+/* Struct used to make the PMU metric table implementation opaque to callers. 
*/
+struct pmu_metrics_table {
+   const struct pmu_metric *entries;
+};
+
 /*
  * Map a CPU to its table of PMU events. The CPU is identified by the
  * cpuid field, which is an arch-specific identifier for the CPU.
@@ -254,11 +259,29 @@ static const struct pmu_sys_events pmu_sys_event_tables[] 
= {
 int pmu_events_table_for_each_event(const struct pmu_events_table *table, 
pmu_event_iter_fn fn,
void *data)
 {
-   for (const struct pmu_event *pe = >entries[0];
-pe->name || pe->metric_group || pe->metric_name;
-pe++) {
-   int ret = fn(pe, table, data);
+   for (const struct pmu_event *pe = >entries[0]; pe->name || 
pe->metric_expr; pe++) {
+   int ret;
 
+   if (!pe->name)
+   continue;
+   ret = fn(pe, table, data);
+   if (ret)
+   return ret;
+   }
+   return 0;
+}
+
+int pmu_events_table_for_each_metric(const struct pmu_events_table *etable, 
pmu_metric_iter_fn fn,
+void *data)
+{
+   struct pmu_metrics_table *table = (struct pmu_metrics_table *)etable;
+
+   for (const struct pmu_metric *pm = >entries[0]; pm->name || 
pm->metric_expr; pm++) {
+   int ret;
+
+   if (!pm->metric_expr)
+   continue;
+   ret = fn(pm, etable, data);
if (ret)
return ret;
}
@@ -305,11 +328,22 @@ const struct pmu_events_table 
*find_core_events_table(const char *arch, const ch
 }
 
 int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data)
+{
+   for (const struct pmu_events_map *tables = _events_map[0]; 
tables->arch; tables++) {
+   int ret = pmu_events_table_for_each_event(>table, fn, 
data);
+
+   if (ret)
+   return ret;
+   }
+   return 0;
+}
+
+int pmu_for_each_core_metric(pmu_metric_iter_fn fn, void *data)
 {
for (const struct pmu_events_map *tables = _events_map[0];
 tables->arch;
 tables++) {
-   int ret = pmu_events_table_for_each_event(>table, fn, 
data);
+   int ret = pmu_events_table_for_each_metric(>table, fn, 
data);
 
if (ret)
return ret;
@@ -340,3 +374,8 @@ int pmu_for_each_sys_event(pmu_event_iter_fn fn, void *data)
}
return 0;
 }
+
+int pmu_for_each_sys_metric(pmu_metric_iter_fn fn __maybe_unused, void *data 
__maybe_unused)
+{
+   return 0;
+}
diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py
index 15a1671740cc..858787a12302 100755
--- a/tools/perf/pmu-events/jevents.py
+++ b/tools/perf/pmu-events/jevents.py
@@ -564,7 +564,19 @@ static const struct pmu_sys_events pmu_sys_event_tables[] 
= {
 \t},
 };
 
-static void decompress(int offset, struct pmu_event *pe)
+static void decompress_event(int offset, struct pmu_event *pe)
+{
+\tconst char *p = 

[PATCH v5 03/15] perf jevents: Rewrite metrics in the same file with each other

2023-01-26 Thread Ian Rogers
Rewrite metrics within the same file in terms of each other. For example, on 
Power8
other_stall_cpi is rewritten from:
"PM_CMPLU_STALL / PM_RUN_INST_CMPL - PM_CMPLU_STALL_BRU_CRU / PM_RUN_INST_CMPL 
- PM_CMPLU_STALL_FXU / PM_RUN_INST_CMPL - PM_CMPLU_STALL_VSU / PM_RUN_INST_CMPL 
- PM_CMPLU_STALL_LSU / PM_RUN_INST_CMPL - PM_CMPLU_STALL_NTCG_FLUSH / 
PM_RUN_INST_CMPL - PM_CMPLU_STALL_NO_NTF / PM_RUN_INST_CMPL"
to:
"stall_cpi - bru_cru_stall_cpi - fxu_stall_cpi - vsu_stall_cpi - lsu_stall_cpi 
- ntcg_flush_cpi - no_ntf_stall_cpi"
Which more closely matches the definition on Power9.

To avoid recomputation decorate the function with a cache.
---
 tools/perf/pmu-events/jevents.py | 21 -
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py
index 0416b7442171..15a1671740cc 100755
--- a/tools/perf/pmu-events/jevents.py
+++ b/tools/perf/pmu-events/jevents.py
@@ -3,6 +3,7 @@
 """Convert directories of JSON events to C code."""
 import argparse
 import csv
+from functools import lru_cache
 import json
 import metric
 import os
@@ -337,18 +338,28 @@ class JsonEvent:
 s = self.build_c_string()
 return f'{{ { _bcs.offsets[s] } }}, /* {s} */\n'
 
-
+@lru_cache(maxsize=None)
 def read_json_events(path: str, topic: str) -> Sequence[JsonEvent]:
   """Read json events from the specified file."""
-
   try:
-result = json.load(open(path), object_hook=JsonEvent)
+events = json.load(open(path), object_hook=JsonEvent)
   except BaseException as err:
 print(f"Exception processing {path}")
 raise
-  for event in result:
+  metrics: list[Tuple[str, metric.Expression]] = []
+  for event in events:
 event.topic = topic
-  return result
+if event.metric_name and '-' not in event.metric_name:
+  metrics.append((event.metric_name, event.metric_expr))
+  updates = metric.RewriteMetricsInTermsOfOthers(metrics)
+  if updates:
+for event in events:
+  if event.metric_name in updates:
+# print(f'Updated {event.metric_name} from\n"{event.metric_expr}"\n'
+#   f'to\n"{updates[event.metric_name]}"')
+event.metric_expr = updates[event.metric_name]
+
+  return events
 
 def preprocess_arch_std_files(archpath: str) -> None:
   """Read in all architecture standard events."""
-- 
2.39.1.456.gfc5497dd1b-goog



[PATCH v5 02/15] perf jevents metric: Add ability to rewrite metrics in terms of others

2023-01-26 Thread Ian Rogers
Add RewriteMetricsInTermsOfOthers that iterates over pairs of names
and expressions trying to replace an expression, within the current
expression, with its name.
---
 tools/perf/pmu-events/metric.py  | 73 +++-
 tools/perf/pmu-events/metric_test.py | 10 
 2 files changed, 81 insertions(+), 2 deletions(-)

diff --git a/tools/perf/pmu-events/metric.py b/tools/perf/pmu-events/metric.py
index 2f2fd220e843..77ea6ff98538 100644
--- a/tools/perf/pmu-events/metric.py
+++ b/tools/perf/pmu-events/metric.py
@@ -4,7 +4,7 @@ import ast
 import decimal
 import json
 import re
-from typing import Dict, List, Optional, Set, Union
+from typing import Dict, List, Optional, Set, Tuple, Union
 
 
 class Expression:
@@ -26,6 +26,9 @@ class Expression:
 """Returns true when two expressions are the same."""
 raise NotImplementedError()
 
+  def Substitute(self, name: str, expression: 'Expression') -> 'Expression':
+raise NotImplementedError()
+
   def __str__(self) -> str:
 return self.ToPerfJson()
 
@@ -186,6 +189,15 @@ class Operator(Expression):
   other.lhs) and self.rhs.Equals(other.rhs)
 return False
 
+  def Substitute(self, name: str, expression: Expression) -> Expression:
+if self.Equals(expression):
+  return Event(name)
+lhs = self.lhs.Substitute(name, expression)
+rhs = None
+if self.rhs:
+  rhs = self.rhs.Substitute(name, expression)
+return Operator(self.operator, lhs, rhs)
+
 
 class Select(Expression):
   """Represents a select ternary in the parse tree."""
@@ -225,6 +237,14 @@ class Select(Expression):
   other.false_val) and self.true_val.Equals(other.true_val)
 return False
 
+  def Substitute(self, name: str, expression: Expression) -> Expression:
+if self.Equals(expression):
+  return Event(name)
+true_val = self.true_val.Substitute(name, expression)
+cond = self.cond.Substitute(name, expression)
+false_val = self.false_val.Substitute(name, expression)
+return Select(true_val, cond, false_val)
+
 
 class Function(Expression):
   """A function in an expression like min, max, d_ratio."""
@@ -267,6 +287,15 @@ class Function(Expression):
   return result
 return False
 
+  def Substitute(self, name: str, expression: Expression) -> Expression:
+if self.Equals(expression):
+  return Event(name)
+lhs = self.lhs.Substitute(name, expression)
+rhs = None
+if self.rhs:
+  rhs = self.rhs.Substitute(name, expression)
+return Function(self.fn, lhs, rhs)
+
 
 def _FixEscapes(s: str) -> str:
   s = re.sub(r'([^\\]),', r'\1\\,', s)
@@ -293,6 +322,9 @@ class Event(Expression):
   def Equals(self, other: Expression) -> bool:
 return isinstance(other, Event) and self.name == other.name
 
+  def Substitute(self, name: str, expression: Expression) -> Expression:
+return self
+
 
 class Constant(Expression):
   """A constant within the expression tree."""
@@ -317,6 +349,9 @@ class Constant(Expression):
   def Equals(self, other: Expression) -> bool:
 return isinstance(other, Constant) and self.value == other.value
 
+  def Substitute(self, name: str, expression: Expression) -> Expression:
+return self
+
 
 class Literal(Expression):
   """A runtime literal within the expression tree."""
@@ -336,6 +371,9 @@ class Literal(Expression):
   def Equals(self, other: Expression) -> bool:
 return isinstance(other, Literal) and self.value == other.value
 
+  def Substitute(self, name: str, expression: Expression) -> Expression:
+return self
+
 
 def min(lhs: Union[int, float, Expression], rhs: Union[int, float,
Expression]) -> 
Function:
@@ -461,6 +499,7 @@ class MetricGroup:
 
 
 class _RewriteIfExpToSelect(ast.NodeTransformer):
+  """Transformer to convert if-else nodes to Select expressions."""
 
   def visit_IfExp(self, node):
 # pylint: disable=invalid-name
@@ -498,7 +537,37 @@ def ParsePerfJson(orig: str) -> Expression:
   for kw in keywords:
 py = re.sub(rf'Event\(r"{kw}"\)', kw, py)
 
-  parsed = ast.parse(py, mode='eval')
+  try:
+parsed = ast.parse(py, mode='eval')
+  except SyntaxError as e:
+raise SyntaxError(f'Parsing expression:\n{orig}') from e
   _RewriteIfExpToSelect().visit(parsed)
   parsed = ast.fix_missing_locations(parsed)
   return _Constify(eval(compile(parsed, orig, 'eval')))
+
+
+def RewriteMetricsInTermsOfOthers(metrics: List[Tuple[str, Expression]]
+  )-> Dict[str, Expression]:
+  """Shorten metrics by rewriting in terms of others.
+
+  Args:
+metrics (list): pairs of metric names and their expressions.
+  Returns:
+Dict: mapping from a metric name to a shortened expression.
+  """
+  updates: Dict[str, Expression] = dict()
+  for outer_name, outer_expression in metrics:
+updated = outer_expression
+while True:
+  for inner_name, inner_expression in metrics:
+if inner_name.lower() == 

[PATCH v5 01/15] perf jevents metric: Correct Function equality

2023-01-26 Thread Ian Rogers
rhs may not be defined, say for source_count, so add a guard.

Reviewed-by: Kajol Jain
---
 tools/perf/pmu-events/metric.py | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/perf/pmu-events/metric.py b/tools/perf/pmu-events/metric.py
index 4797ed4fd817..2f2fd220e843 100644
--- a/tools/perf/pmu-events/metric.py
+++ b/tools/perf/pmu-events/metric.py
@@ -261,8 +261,10 @@ class Function(Expression):
 
   def Equals(self, other: Expression) -> bool:
 if isinstance(other, Function):
-  return self.fn == other.fn and self.lhs.Equals(
-  other.lhs) and self.rhs.Equals(other.rhs)
+  result = self.fn == other.fn and self.lhs.Equals(other.lhs)
+  if self.rhs:
+result = result and self.rhs.Equals(other.rhs)
+  return result
 return False
 
 
-- 
2.39.1.456.gfc5497dd1b-goog



[PATCH v5 00/15] jevents/pmu-events improvements

2023-01-26 Thread Ian Rogers
Add an optimization to jevents using the metric code, rewrite metrics
in terms of each other in order to minimize size and improve
readability. For example, on Power8
other_stall_cpi is rewritten from:
"PM_CMPLU_STALL / PM_RUN_INST_CMPL - PM_CMPLU_STALL_BRU_CRU / PM_RUN_INST_CMPL 
- PM_CMPLU_STALL_FXU / PM_RUN_INST_CMPL - PM_CMPLU_STALL_VSU / PM_RUN_INST_CMPL 
- PM_CMPLU_STALL_LSU / PM_RUN_INST_CMPL - PM_CMPLU_STALL_NTCG_FLUSH / 
PM_RUN_INST_CMPL - PM_CMPLU_STALL_NO_NTF / PM_RUN_INST_CMPL"
to:
"stall_cpi - bru_cru_stall_cpi - fxu_stall_cpi - vsu_stall_cpi - lsu_stall_cpi 
- ntcg_flush_cpi - no_ntf_stall_cpi"
Which more closely matches the definition on Power9.

A limitation of the substitutions are that they depend on strict
equality and the shape of the tree. This means that for "a + b + c"
then a substitution of "a + b" will succeed while "b + c" will fail
(the LHS for "+ c" is "a + b" not just "b").

Separate out the events and metrics in the pmu-events tables saving
14.8% in the table size while making it that metrics no longer need to
iterate over all events and vice versa. These changes remove evsel's
direct metric support as the pmu_event no longer has a metric to
populate it. This is a minor issue as the code wasn't working
properly, metrics for this are rare and can still be properly ran
using '-M'.

Add an ability to just build certain models into the jevents generated
pmu-metrics.c code. This functionality is appropriate for operating
systems like ChromeOS, that aim to minimize binary size and know all
the target CPU models.

v5. s/list/List/ in a type annotation to fix Python 3.6 as reported by
John Garry . Fix a bug in metric_test.py
where a bad character was imported. To avoid similar regressions,
run metric_test.py before generating pmu-events.c.
v4. Better support the implementor/model style --model argument for
jevents.py. Add #slots test fix. On some patches add reviewed-by
John Garry  and Kajol
Jain.
v3. Rebase an incorporate review comments from John Garry
, in particular breaking apart patch 4
into 3 patches. The no jevents breakage and then later fix is
avoided in this series too.
v2. Rebase. Modify the code that skips rewriting a metric with the
same name with itself, to make the name check case insensitive.

Ian Rogers (15):
  perf jevents metric: Correct Function equality
  perf jevents metric: Add ability to rewrite metrics in terms of others
  perf jevents: Rewrite metrics in the same file with each other
  perf pmu-events: Add separate metric from pmu_event
  perf pmu-events: Separate the metrics from events for no jevents
  perf pmu-events: Remove now unused event and metric variables
  perf stat: Remove evsel metric_name/expr
  perf jevents: Combine table prefix and suffix writing
  perf pmu-events: Introduce pmu_metrics_table
  perf jevents: Generate metrics and events as separate tables
  perf jevents: Add model list option
  perf pmu-events: Fix testing with JEVENTS_ARCH=all
  perf jevents: Correct bad character encoding
  tools build: Add test echo-cmd
  perf jevents: Run metric_test.py at compile-time

 tools/build/Makefile.build   |   1 +
 tools/perf/arch/arm64/util/pmu.c |  11 +-
 tools/perf/arch/powerpc/util/header.c|   4 +-
 tools/perf/builtin-list.c|  20 +-
 tools/perf/builtin-stat.c|   1 -
 tools/perf/pmu-events/Build  |  16 +-
 tools/perf/pmu-events/empty-pmu-events.c | 108 ++-
 tools/perf/pmu-events/jevents.py | 357 +++
 tools/perf/pmu-events/metric.py  |  79 -
 tools/perf/pmu-events/metric_test.py |  15 +-
 tools/perf/pmu-events/pmu-events.h   |  26 +-
 tools/perf/tests/expand-cgroup.c |   4 +-
 tools/perf/tests/parse-metric.c  |   4 +-
 tools/perf/tests/pmu-events.c|  69 ++---
 tools/perf/util/cgroup.c |   1 -
 tools/perf/util/evsel.c  |   2 -
 tools/perf/util/evsel.h  |   2 -
 tools/perf/util/expr.h   |   1 +
 tools/perf/util/expr.l   |   8 +-
 tools/perf/util/metricgroup.c| 207 +++--
 tools/perf/util/metricgroup.h|   4 +-
 tools/perf/util/parse-events.c   |   2 -
 tools/perf/util/pmu.c|  44 +--
 tools/perf/util/pmu.h|  10 +-
 tools/perf/util/print-events.c   |  32 +-
 tools/perf/util/print-events.h   |   3 +-
 tools/perf/util/python.c |   7 -
 tools/perf/util/stat-shadow.c| 112 ---
 tools/perf/util/stat.h   |   1 -
 29 files changed, 681 insertions(+), 470 deletions(-)
 mode change 100644 => 100755 tools/perf/pmu-events/metric_test.py

-- 
2.39.1.456.gfc5497dd1b-goog



Re: [PATCH] kasan: Fix Oops due to missing calls to kasan_arch_is_ready()

2023-01-26 Thread Andrey Konovalov
On Thu, Jan 26, 2023 at 8:08 AM Christophe Leroy
 wrote:
>
> On powerpc64, you can build a kernel with KASAN as soon as you build it
> with RADIX MMU support. However if the CPU doesn't have RADIX MMU,
> KASAN isn't enabled at init and the following Oops is encountered.
>
>   [0.00][T0] KASAN not enabled as it requires radix!
>
>   [4.484295][   T26] BUG: Unable to handle kernel data access at 
> 0xc00e00804a04
>   [4.485270][   T26] Faulting instruction address: 0xc062ec6c
>   [4.485748][   T26] Oops: Kernel access of bad area, sig: 11 [#1]
>   [4.485920][   T26] BE PAGE_SIZE=64K MMU=Hash SMP NR_CPUS=2048 NUMA 
> pSeries
>   [4.486259][   T26] Modules linked in:
>   [4.486637][   T26] CPU: 0 PID: 26 Comm: kworker/u2:2 Not tainted 
> 6.2.0-rc3-02590-gf8a023b0a805 #249
>   [4.486907][   T26] Hardware name: IBM pSeries (emulated by qemu) POWER9 
> (raw) 0x4e1200 0xf05 of:SLOF,HEAD pSeries
>   [4.487445][   T26] Workqueue: eval_map_wq .tracer_init_tracefs_work_func
>   [4.488744][   T26] NIP:  c062ec6c LR: c062bb84 CTR: 
> c02ebcd0
>   [4.488867][   T26] REGS: c49175c0 TRAP: 0380   Not tainted  
> (6.2.0-rc3-02590-gf8a023b0a805)
>   [4.489028][   T26] MSR:  82009032   CR: 
> 44002808  XER: 
>   [4.489584][   T26] CFAR: c062bb80 IRQMASK: 0
>   [4.489584][   T26] GPR00: c05624d4 c4917860 
> c1cfc000 18804a04
>   [4.489584][   T26] GPR04: c03a2650 0cc0 
> c000d3d8 c000d3d8
>   [4.489584][   T26] GPR08: c49175b0 a80e 
>  17d78400
>   [4.489584][   T26] GPR12: 44002204 c379 
> c435003c c43f1c40
>   [4.489584][   T26] GPR16: c43f1c68 c43501a0 
> c2106138 c43f1c08
>   [4.489584][   T26] GPR20: c43f1c10 c43f1c20 
> c4146c40 c2fdb7f8
>   [4.489584][   T26] GPR24: c2fdb834 c3685e00 
> c4025030 c3522e90
>   [4.489584][   T26] GPR28: 0cc0 c03a2650 
> c4025020 c4025020
>   [4.491201][   T26] NIP [c062ec6c] 
> .kasan_byte_accessible+0xc/0x20
>   [4.491430][   T26] LR [c062bb84] .__kasan_check_byte+0x24/0x90
>   [4.491767][   T26] Call Trace:
>   [4.491941][   T26] [c4917860] [c062ae70] 
> .__kasan_kmalloc+0xc0/0x110 (unreliable)
>   [4.492270][   T26] [c49178f0] [c05624d4] 
> .krealloc+0x54/0x1c0
>   [4.492453][   T26] [c4917990] [c03a2650] 
> .create_trace_option_files+0x280/0x530
>   [4.492613][   T26] [c4917a90] [c2050d90] 
> .tracer_init_tracefs_work_func+0x274/0x2c0
>   [4.492771][   T26] [c4917b40] [c01f9948] 
> .process_one_work+0x578/0x9f0
>   [4.492927][   T26] [c4917c30] [c01f9ebc] 
> .worker_thread+0xfc/0x950
>   [4.493084][   T26] [c4917d60] [c020be84] 
> .kthread+0x1a4/0x1b0
>   [4.493232][   T26] [c4917e10] [c000d3d8] 
> .ret_from_kernel_thread+0x58/0x60
>   [4.495642][   T26] Code: 6000 7cc802a6 38a0 4bfffc78 6000 
> 7cc802a6 38a1 4bfffc68 6000 3d20a80e 7863e8c2 792907c6 <7c6348ae> 
> 20630007 78630fe0 68630001
>   [4.496704][   T26] ---[ end trace  ]---
>
> The Oops is due to kasan_byte_accessible() not checking the readiness
> of KASAN. Add missing call to kasan_arch_is_ready() and bail out when
> not ready. The same problem is observed with kasan_kfree_large()
> so fix it the same.
>
> Also, as KASAN is not available and no shadow area is allocated for
> linear memory mapping, there is no point in allocating shadow mem for
> vmalloc memory as shown below in /sys/kernel/debug/kernel_page_tables
>
>   ---[ kasan shadow mem start ]---
>   0xc00f-0xc00f0006  0x040f   448K
>  r  w   pte  valid  presentdirty  accessed
>   0xc00f0086-0xc00f0086  0x0ac164K
>  r  w   pte  valid  presentdirty  accessed
>   0xc00f3ffe-0xc00f3fff  0x04d1   128K
>  r  w   pte  valid  presentdirty  accessed
>   ---[ kasan shadow mem end ]---
>
> So, also verify KASAN readiness before allocating and poisoning
> shadow mem for VMAs.

Hi Cristophe,

Would it possible to unify kasan_arch_is_ready with the already
existing kasan_enabled check?

Both functions seem to be serving a similar purpose: for example this
patch adds kasan_arch_is_ready into __kasan_poison_vmalloc, which is
called by kasan_poison_vmalloc when kasan_enabled returns true.

The kasan_enabled is only implemented for HW_TAGS right now, but it
should be easy enough to make it work other cases by
kasan_flag_enabled into common.c and adding 

Re: [PATCH] kasan: Fix Oops due to missing calls to kasan_arch_is_ready()

2023-01-26 Thread Andrew Morton
On Thu, 26 Jan 2023 08:04:47 +0100 Christophe Leroy 
 wrote:

> On powerpc64, you can build a kernel with KASAN as soon as you build it
> with RADIX MMU support. However if the CPU doesn't have RADIX MMU,
> KASAN isn't enabled at init and the following Oops is encountered.

Should we backport to -stable?  If so, can we identify a suitable Fixes: target?

Thanks.


Re: [PATCH v4 5/7] mm: replace vma->vm_flags indirect modification in ksm_madvise

2023-01-26 Thread Michael Ellerman
Suren Baghdasaryan  writes:
> Replace indirect modifications to vma->vm_flags with calls to modifier
> functions to be able to track flag changes and to keep vma locking
> correctness.
>
> Signed-off-by: Suren Baghdasaryan 
> Acked-by: Michal Hocko 
> Acked-by: Mel Gorman 
> Acked-by: Mike Rapoport (IBM) 
> ---
>  arch/powerpc/kvm/book3s_hv_uvmem.c | 6 +-

Acked-by: Michael Ellerman  (powerpc)

cheers


Re: [PATCH] powerpc/tlb: Remove BUILD_BUG for book3s/32/tlbflush.h local_flush_tlb_page_psize

2023-01-26 Thread Benjamin Gray
On Wed, 2023-01-25 at 09:43 +, Christophe Leroy wrote:

> By the way, are you should the problem is really BUILD_BUG() ?
> Looking 
> at your patch I would think that the problem is because it is "static
> inline". Have you tried 'static __always_inline' instead ?

I did not try it, so I just did but it doesn't make a difference.

Looking further, the failing config also enabled
CONFIG_JUMP_LABEL_FEATURE_CHECK_DEBUG, which causes the
mmu_has_feature(MMU_FTR_TYPE_RADIX) call of radix_enabled() to be non-
trivial. It must check static_key_initialized, and falls back to
early_mmu_has_feature if it triggers. Clang apparently can't see that
early_mmu_has_feature will also always return false for Radix, so
doesn't see that everything guarded by radix_enabled() is dead code. I
suppose it's complicated by the fact it still has to run
mmu_has_feature for the assertion side effect despite the return value
being knowable at compile time.

So because of this weird interaction, the following should (and does)
also prevent the compilation error by making the radix_enabled() return
value more obvious to the compiler in the case where Radix is not
implemented. (I've put the constant second here so the early usage
assertion still runs).

diff --git a/arch/powerpc/include/asm/mmu.h
b/arch/powerpc/include/asm/mmu.h
index 94b981152667..3592ff9a522b 100644
--- a/arch/powerpc/include/asm/mmu.h
+++ b/arch/powerpc/include/asm/mmu.h
@@ -327,7 +327,7 @@ static inline void assert_pte_locked(struct
mm_struct *mm, unsigned long addr)
 
 static __always_inline bool radix_enabled(void)
 {
-   return mmu_has_feature(MMU_FTR_TYPE_RADIX);
+   return mmu_has_feature(MMU_FTR_TYPE_RADIX) &&
IS_ENABLED(CONFIG_PPC_RADIX_MMU);
 }
 
 static __always_inline bool early_radix_enabled(void)


Re: [PATCH] powerpc/tlb: Remove BUILD_BUG for book3s/32/tlbflush.h local_flush_tlb_page_psize

2023-01-26 Thread Benjamin Gray
On Wed, 2023-01-25 at 22:35 +1100, Michael Ellerman wrote:
> Can't we just fall back to flush_tlb_page(vma, vmaddr)?
> 
> I'd guess those CPUs can't flush based on page size anyway.
> 
> cheers

Probably. Do they have a fixed page size? It's not a BUILD_BUG/WARN
because it _should_ be unimplemented, just that I don't have an idea of
how that target works.


Re: [PATCH RESEND 0/8] Resend LED patches

2023-01-26 Thread Linus Walleij
On Fri, Jan 20, 2023 at 6:15 PM Lee Jones  wrote:

> If everyone is convinced that applying these drivers is the correct
> thing to do, I'd be happy to (rather) take them via LEDs.

Oh you are co-maintainer of the LED subsystem since a month!

Sadly this series stalled way before that, so that's why we didn't notice.

By all means, pick it up!

Yours,
Linus Walleij


Re: [PATCH v4 6/7] mm: introduce __vm_flags_mod and use it in untrack_pfn

2023-01-26 Thread Mike Rapoport
On Thu, Jan 26, 2023 at 11:37:51AM -0800, Suren Baghdasaryan wrote:
> There are scenarios when vm_flags can be modified without exclusive
> mmap_lock, such as:
> - after VMA was isolated and mmap_lock was downgraded or dropped
> - in exit_mmap when there are no other mm users and locking is unnecessary
> Introduce __vm_flags_mod to avoid assertions when the caller takes
> responsibility for the required locking.
> Pass a hint to untrack_pfn to conditionally use __vm_flags_mod for
> flags modification to avoid assertion.
> 
> Signed-off-by: Suren Baghdasaryan 
> Acked-by: Michal Hocko 

Acked-by: Mike Rapoport (IBM) 

> ---
>  arch/x86/mm/pat/memtype.c | 10 +++---
>  include/linux/mm.h| 14 --
>  include/linux/pgtable.h   |  5 +++--
>  mm/memory.c   | 13 +++--
>  mm/memremap.c |  4 ++--
>  mm/mmap.c | 16 ++--
>  6 files changed, 41 insertions(+), 21 deletions(-)
> 
> diff --git a/arch/x86/mm/pat/memtype.c b/arch/x86/mm/pat/memtype.c
> index 6ca51b1aa5d9..691bf8934b6f 100644
> --- a/arch/x86/mm/pat/memtype.c
> +++ b/arch/x86/mm/pat/memtype.c
> @@ -1046,7 +1046,7 @@ void track_pfn_insert(struct vm_area_struct *vma, 
> pgprot_t *prot, pfn_t pfn)
>   * can be for the entire vma (in which case pfn, size are zero).
>   */
>  void untrack_pfn(struct vm_area_struct *vma, unsigned long pfn,
> -  unsigned long size)
> +  unsigned long size, bool mm_wr_locked)
>  {
>   resource_size_t paddr;
>   unsigned long prot;
> @@ -1065,8 +1065,12 @@ void untrack_pfn(struct vm_area_struct *vma, unsigned 
> long pfn,
>   size = vma->vm_end - vma->vm_start;
>   }
>   free_pfn_range(paddr, size);
> - if (vma)
> - vm_flags_clear(vma, VM_PAT);
> + if (vma) {
> + if (mm_wr_locked)
> + vm_flags_clear(vma, VM_PAT);
> + else
> + __vm_flags_mod(vma, 0, VM_PAT);
> + }
>  }
>  
>  /*
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 3c7fc3ecaece..a00fdeb4492d 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -656,6 +656,16 @@ static inline void vm_flags_clear(struct vm_area_struct 
> *vma,
>   ACCESS_PRIVATE(vma, __vm_flags) &= ~flags;
>  }
>  
> +/*
> + * Use only if VMA is not part of the VMA tree or has no other users and
> + * therefore needs no locking.
> + */
> +static inline void __vm_flags_mod(struct vm_area_struct *vma,
> +   vm_flags_t set, vm_flags_t clear)
> +{
> + vm_flags_init(vma, (vma->vm_flags | set) & ~clear);
> +}
> +
>  /*
>   * Use only when the order of set/clear operations is unimportant, otherwise
>   * use vm_flags_{set|clear} explicitly.
> @@ -664,7 +674,7 @@ static inline void vm_flags_mod(struct vm_area_struct 
> *vma,
>   vm_flags_t set, vm_flags_t clear)
>  {
>   mmap_assert_write_locked(vma->vm_mm);
> - vm_flags_init(vma, (vma->vm_flags | set) & ~clear);
> + __vm_flags_mod(vma, set, clear);
>  }
>  
>  static inline void vma_set_anonymous(struct vm_area_struct *vma)
> @@ -2102,7 +2112,7 @@ static inline void zap_vma_pages(struct vm_area_struct 
> *vma)
>  }
>  void unmap_vmas(struct mmu_gather *tlb, struct maple_tree *mt,
>   struct vm_area_struct *start_vma, unsigned long start,
> - unsigned long end);
> + unsigned long end, bool mm_wr_locked);
>  
>  struct mmu_notifier_range;
>  
> diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
> index 5fd45454c073..c63cd44777ec 100644
> --- a/include/linux/pgtable.h
> +++ b/include/linux/pgtable.h
> @@ -1185,7 +1185,8 @@ static inline int track_pfn_copy(struct vm_area_struct 
> *vma)
>   * can be for the entire vma (in which case pfn, size are zero).
>   */
>  static inline void untrack_pfn(struct vm_area_struct *vma,
> -unsigned long pfn, unsigned long size)
> +unsigned long pfn, unsigned long size,
> +bool mm_wr_locked)
>  {
>  }
>  
> @@ -1203,7 +1204,7 @@ extern void track_pfn_insert(struct vm_area_struct 
> *vma, pgprot_t *prot,
>pfn_t pfn);
>  extern int track_pfn_copy(struct vm_area_struct *vma);
>  extern void untrack_pfn(struct vm_area_struct *vma, unsigned long pfn,
> - unsigned long size);
> + unsigned long size, bool mm_wr_locked);
>  extern void untrack_pfn_moved(struct vm_area_struct *vma);
>  #endif
>  
> diff --git a/mm/memory.c b/mm/memory.c
> index a6316cda0e87..7a04a1130ec1 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -1613,7 +1613,7 @@ void unmap_page_range(struct mmu_gather *tlb,
>  static void unmap_single_vma(struct mmu_gather *tlb,
>   struct vm_area_struct *vma, unsigned long start_addr,
>   unsigned long end_addr,
> - struct zap_details *details)
> + struct zap_details 

Re: [PATCH v4 2/7] mm: introduce vma->vm_flags wrapper functions

2023-01-26 Thread Mike Rapoport
On Thu, Jan 26, 2023 at 11:37:47AM -0800, Suren Baghdasaryan wrote:
> vm_flags are among VMA attributes which affect decisions like VMA merging
> and splitting. Therefore all vm_flags modifications are performed after
> taking exclusive mmap_lock to prevent vm_flags updates racing with such
> operations. Introduce modifier functions for vm_flags to be used whenever
> flags are updated. This way we can better check and control correct
> locking behavior during these updates.
> 
> Signed-off-by: Suren Baghdasaryan 
> Reviewed-by: Davidlohr Bueso 
> Acked-by: Michal Hocko 
> Acked-by: Mel Gorman 

Acked-by: Mike Rapoport (IBM) 

> ---
>  include/linux/mm.h   | 40 
>  include/linux/mm_types.h | 10 +-
>  2 files changed, 49 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 8d636e895ee9..abb31103d060 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -627,6 +627,46 @@ static inline void vma_init(struct vm_area_struct *vma, 
> struct mm_struct *mm)
>   INIT_LIST_HEAD(>anon_vma_chain);
>  }
>  
> +/* Use when VMA is not part of the VMA tree and needs no locking */
> +static inline void vm_flags_init(struct vm_area_struct *vma,
> +  vm_flags_t flags)
> +{
> + ACCESS_PRIVATE(vma, __vm_flags) = flags;
> +}
> +
> +/* Use when VMA is part of the VMA tree and modifications need coordination 
> */
> +static inline void vm_flags_reset(struct vm_area_struct *vma,
> +   vm_flags_t flags)
> +{
> + mmap_assert_write_locked(vma->vm_mm);
> + vm_flags_init(vma, flags);
> +}
> +
> +static inline void vm_flags_set(struct vm_area_struct *vma,
> + vm_flags_t flags)
> +{
> + mmap_assert_write_locked(vma->vm_mm);
> + ACCESS_PRIVATE(vma, __vm_flags) |= flags;
> +}
> +
> +static inline void vm_flags_clear(struct vm_area_struct *vma,
> +   vm_flags_t flags)
> +{
> + mmap_assert_write_locked(vma->vm_mm);
> + ACCESS_PRIVATE(vma, __vm_flags) &= ~flags;
> +}
> +
> +/*
> + * Use only when the order of set/clear operations is unimportant, otherwise
> + * use vm_flags_{set|clear} explicitly.
> + */
> +static inline void vm_flags_mod(struct vm_area_struct *vma,
> + vm_flags_t set, vm_flags_t clear)
> +{
> + mmap_assert_write_locked(vma->vm_mm);
> + vm_flags_init(vma, (vma->vm_flags | set) & ~clear);
> +}
> +
>  static inline void vma_set_anonymous(struct vm_area_struct *vma)
>  {
>   vma->vm_ops = NULL;
> diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
> index 2d6d790d9bed..da983aedb741 100644
> --- a/include/linux/mm_types.h
> +++ b/include/linux/mm_types.h
> @@ -491,7 +491,15 @@ struct vm_area_struct {
>* See vmf_insert_mixed_prot() for discussion.
>*/
>   pgprot_t vm_page_prot;
> - unsigned long vm_flags; /* Flags, see mm.h. */
> +
> + /*
> +  * Flags, see mm.h.
> +  * To modify use vm_flags_{init|reset|set|clear|mod} functions.
> +  */
> + union {
> + const vm_flags_t vm_flags;
> + vm_flags_t __private __vm_flags;
> + };
>  
>   /*
>* For areas with an address space and backing store,
> -- 
> 2.39.1
> 

-- 
Sincerely yours,
Mike.


Re: [PATCH v4 1/7] kernel/fork: convert vma assignment to a memcpy

2023-01-26 Thread Mike Rapoport
On Thu, Jan 26, 2023 at 11:37:46AM -0800, Suren Baghdasaryan wrote:
> Convert vma assignment in vm_area_dup() to a memcpy() to prevent compiler
> errors when we add a const modifier to vma->vm_flags.
> 
> Signed-off-by: Suren Baghdasaryan 
> Acked-by: Mel Gorman 

Acked-by: Mike Rapoport (IBM) 

> ---
>  kernel/fork.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/fork.c b/kernel/fork.c
> index 441dcec60aae..9260f975b8f4 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -472,7 +472,7 @@ struct vm_area_struct *vm_area_dup(struct vm_area_struct 
> *orig)
>* orig->shared.rb may be modified concurrently, but the clone
>* will be reinitialized.
>*/
> - *new = data_race(*orig);
> + data_race(memcpy(new, orig, sizeof(*new)));
>   INIT_LIST_HEAD(>anon_vma_chain);
>   dup_anon_vma_name(orig, new);
>   }
> -- 
> 2.39.1
> 

-- 
Sincerely yours,
Mike.


[PATCH v4 7/7] mm: export dump_mm()

2023-01-26 Thread Suren Baghdasaryan
mmap_assert_write_locked() is used in vm_flags modifiers. Because
mmap_assert_write_locked() uses dump_mm() and vm_flags are sometimes
modified from inside a module, it's necessary to export dump_mm()
function.

Signed-off-by: Suren Baghdasaryan 
Acked-by: Michal Hocko 
Acked-by: Mike Rapoport (IBM) 
---
 mm/debug.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mm/debug.c b/mm/debug.c
index 9d3d893dc7f4..96d594e16292 100644
--- a/mm/debug.c
+++ b/mm/debug.c
@@ -215,6 +215,7 @@ void dump_mm(const struct mm_struct *mm)
mm->def_flags, >def_flags
);
 }
+EXPORT_SYMBOL(dump_mm);
 
 static bool page_init_poisoning __read_mostly = true;
 
-- 
2.39.1



[PATCH v4 6/7] mm: introduce __vm_flags_mod and use it in untrack_pfn

2023-01-26 Thread Suren Baghdasaryan
There are scenarios when vm_flags can be modified without exclusive
mmap_lock, such as:
- after VMA was isolated and mmap_lock was downgraded or dropped
- in exit_mmap when there are no other mm users and locking is unnecessary
Introduce __vm_flags_mod to avoid assertions when the caller takes
responsibility for the required locking.
Pass a hint to untrack_pfn to conditionally use __vm_flags_mod for
flags modification to avoid assertion.

Signed-off-by: Suren Baghdasaryan 
Acked-by: Michal Hocko 
---
 arch/x86/mm/pat/memtype.c | 10 +++---
 include/linux/mm.h| 14 --
 include/linux/pgtable.h   |  5 +++--
 mm/memory.c   | 13 +++--
 mm/memremap.c |  4 ++--
 mm/mmap.c | 16 ++--
 6 files changed, 41 insertions(+), 21 deletions(-)

diff --git a/arch/x86/mm/pat/memtype.c b/arch/x86/mm/pat/memtype.c
index 6ca51b1aa5d9..691bf8934b6f 100644
--- a/arch/x86/mm/pat/memtype.c
+++ b/arch/x86/mm/pat/memtype.c
@@ -1046,7 +1046,7 @@ void track_pfn_insert(struct vm_area_struct *vma, 
pgprot_t *prot, pfn_t pfn)
  * can be for the entire vma (in which case pfn, size are zero).
  */
 void untrack_pfn(struct vm_area_struct *vma, unsigned long pfn,
-unsigned long size)
+unsigned long size, bool mm_wr_locked)
 {
resource_size_t paddr;
unsigned long prot;
@@ -1065,8 +1065,12 @@ void untrack_pfn(struct vm_area_struct *vma, unsigned 
long pfn,
size = vma->vm_end - vma->vm_start;
}
free_pfn_range(paddr, size);
-   if (vma)
-   vm_flags_clear(vma, VM_PAT);
+   if (vma) {
+   if (mm_wr_locked)
+   vm_flags_clear(vma, VM_PAT);
+   else
+   __vm_flags_mod(vma, 0, VM_PAT);
+   }
 }
 
 /*
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 3c7fc3ecaece..a00fdeb4492d 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -656,6 +656,16 @@ static inline void vm_flags_clear(struct vm_area_struct 
*vma,
ACCESS_PRIVATE(vma, __vm_flags) &= ~flags;
 }
 
+/*
+ * Use only if VMA is not part of the VMA tree or has no other users and
+ * therefore needs no locking.
+ */
+static inline void __vm_flags_mod(struct vm_area_struct *vma,
+ vm_flags_t set, vm_flags_t clear)
+{
+   vm_flags_init(vma, (vma->vm_flags | set) & ~clear);
+}
+
 /*
  * Use only when the order of set/clear operations is unimportant, otherwise
  * use vm_flags_{set|clear} explicitly.
@@ -664,7 +674,7 @@ static inline void vm_flags_mod(struct vm_area_struct *vma,
vm_flags_t set, vm_flags_t clear)
 {
mmap_assert_write_locked(vma->vm_mm);
-   vm_flags_init(vma, (vma->vm_flags | set) & ~clear);
+   __vm_flags_mod(vma, set, clear);
 }
 
 static inline void vma_set_anonymous(struct vm_area_struct *vma)
@@ -2102,7 +2112,7 @@ static inline void zap_vma_pages(struct vm_area_struct 
*vma)
 }
 void unmap_vmas(struct mmu_gather *tlb, struct maple_tree *mt,
struct vm_area_struct *start_vma, unsigned long start,
-   unsigned long end);
+   unsigned long end, bool mm_wr_locked);
 
 struct mmu_notifier_range;
 
diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index 5fd45454c073..c63cd44777ec 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -1185,7 +1185,8 @@ static inline int track_pfn_copy(struct vm_area_struct 
*vma)
  * can be for the entire vma (in which case pfn, size are zero).
  */
 static inline void untrack_pfn(struct vm_area_struct *vma,
-  unsigned long pfn, unsigned long size)
+  unsigned long pfn, unsigned long size,
+  bool mm_wr_locked)
 {
 }
 
@@ -1203,7 +1204,7 @@ extern void track_pfn_insert(struct vm_area_struct *vma, 
pgprot_t *prot,
 pfn_t pfn);
 extern int track_pfn_copy(struct vm_area_struct *vma);
 extern void untrack_pfn(struct vm_area_struct *vma, unsigned long pfn,
-   unsigned long size);
+   unsigned long size, bool mm_wr_locked);
 extern void untrack_pfn_moved(struct vm_area_struct *vma);
 #endif
 
diff --git a/mm/memory.c b/mm/memory.c
index a6316cda0e87..7a04a1130ec1 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -1613,7 +1613,7 @@ void unmap_page_range(struct mmu_gather *tlb,
 static void unmap_single_vma(struct mmu_gather *tlb,
struct vm_area_struct *vma, unsigned long start_addr,
unsigned long end_addr,
-   struct zap_details *details)
+   struct zap_details *details, bool mm_wr_locked)
 {
unsigned long start = max(vma->vm_start, start_addr);
unsigned long end;
@@ -1628,7 +1628,7 @@ static void unmap_single_vma(struct mmu_gather *tlb,
uprobe_munmap(vma, start, end);
 
if (unlikely(vma->vm_flags & 

[PATCH v4 5/7] mm: replace vma->vm_flags indirect modification in ksm_madvise

2023-01-26 Thread Suren Baghdasaryan
Replace indirect modifications to vma->vm_flags with calls to modifier
functions to be able to track flag changes and to keep vma locking
correctness.

Signed-off-by: Suren Baghdasaryan 
Acked-by: Michal Hocko 
Acked-by: Mel Gorman 
Acked-by: Mike Rapoport (IBM) 
---
 arch/powerpc/kvm/book3s_hv_uvmem.c | 6 +-
 arch/s390/mm/gmap.c| 6 +-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv_uvmem.c 
b/arch/powerpc/kvm/book3s_hv_uvmem.c
index 1d67baa5557a..709ebd578394 100644
--- a/arch/powerpc/kvm/book3s_hv_uvmem.c
+++ b/arch/powerpc/kvm/book3s_hv_uvmem.c
@@ -393,6 +393,7 @@ static int kvmppc_memslot_page_merge(struct kvm *kvm,
 {
unsigned long gfn = memslot->base_gfn;
unsigned long end, start = gfn_to_hva(kvm, gfn);
+   unsigned long vm_flags;
int ret = 0;
struct vm_area_struct *vma;
int merge_flag = (merge) ? MADV_MERGEABLE : MADV_UNMERGEABLE;
@@ -409,12 +410,15 @@ static int kvmppc_memslot_page_merge(struct kvm *kvm,
ret = H_STATE;
break;
}
+   /* Copy vm_flags to avoid partial modifications in ksm_madvise 
*/
+   vm_flags = vma->vm_flags;
ret = ksm_madvise(vma, vma->vm_start, vma->vm_end,
- merge_flag, >vm_flags);
+ merge_flag, _flags);
if (ret) {
ret = H_STATE;
break;
}
+   vm_flags_reset(vma, vm_flags);
start = vma->vm_end;
} while (end > vma->vm_end);
 
diff --git a/arch/s390/mm/gmap.c b/arch/s390/mm/gmap.c
index ab836597419d..5a716bdcba05 100644
--- a/arch/s390/mm/gmap.c
+++ b/arch/s390/mm/gmap.c
@@ -2587,14 +2587,18 @@ int gmap_mark_unmergeable(void)
 {
struct mm_struct *mm = current->mm;
struct vm_area_struct *vma;
+   unsigned long vm_flags;
int ret;
VMA_ITERATOR(vmi, mm, 0);
 
for_each_vma(vmi, vma) {
+   /* Copy vm_flags to avoid partial modifications in ksm_madvise 
*/
+   vm_flags = vma->vm_flags;
ret = ksm_madvise(vma, vma->vm_start, vma->vm_end,
- MADV_UNMERGEABLE, >vm_flags);
+ MADV_UNMERGEABLE, _flags);
if (ret)
return ret;
+   vm_flags_reset(vma, vm_flags);
}
mm->def_flags &= ~VM_MERGEABLE;
return 0;
-- 
2.39.1



[PATCH v4 4/7] mm: replace vma->vm_flags direct modifications with modifier calls

2023-01-26 Thread Suren Baghdasaryan
Replace direct modifications to vma->vm_flags with calls to modifier
functions to be able to track flag changes and to keep vma locking
correctness.

Signed-off-by: Suren Baghdasaryan 
Acked-by: Michal Hocko 
Acked-by: Mel Gorman 
Acked-by: Mike Rapoport (IBM) 
Acked-by: Sebastian Reichel 
---
 arch/arm/kernel/process.c  |  2 +-
 arch/ia64/mm/init.c|  8 
 arch/loongarch/include/asm/tlb.h   |  2 +-
 arch/powerpc/kvm/book3s_xive_native.c  |  2 +-
 arch/powerpc/mm/book3s64/subpage_prot.c|  2 +-
 arch/powerpc/platforms/book3s/vas-api.c|  2 +-
 arch/powerpc/platforms/cell/spufs/file.c   | 14 +++---
 arch/s390/mm/gmap.c|  3 +--
 arch/x86/entry/vsyscall/vsyscall_64.c  |  2 +-
 arch/x86/kernel/cpu/sgx/driver.c   |  2 +-
 arch/x86/kernel/cpu/sgx/virt.c |  2 +-
 arch/x86/mm/pat/memtype.c  |  6 +++---
 arch/x86/um/mem_32.c   |  2 +-
 drivers/acpi/pfr_telemetry.c   |  2 +-
 drivers/android/binder.c   |  3 +--
 drivers/char/mspec.c   |  2 +-
 drivers/crypto/hisilicon/qm.c  |  2 +-
 drivers/dax/device.c   |  2 +-
 drivers/dma/idxd/cdev.c|  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c|  2 +-
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c   |  4 ++--
 drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c  |  4 ++--
 drivers/gpu/drm/amd/amdkfd/kfd_events.c|  4 ++--
 drivers/gpu/drm/amd/amdkfd/kfd_process.c   |  4 ++--
 drivers/gpu/drm/drm_gem.c  |  2 +-
 drivers/gpu/drm/drm_gem_dma_helper.c   |  3 +--
 drivers/gpu/drm/drm_gem_shmem_helper.c |  2 +-
 drivers/gpu/drm/drm_vm.c   |  8 
 drivers/gpu/drm/etnaviv/etnaviv_gem.c  |  2 +-
 drivers/gpu/drm/exynos/exynos_drm_gem.c|  4 ++--
 drivers/gpu/drm/gma500/framebuffer.c   |  2 +-
 drivers/gpu/drm/i810/i810_dma.c|  2 +-
 drivers/gpu/drm/i915/gem/i915_gem_mman.c   |  4 ++--
 drivers/gpu/drm/mediatek/mtk_drm_gem.c |  2 +-
 drivers/gpu/drm/msm/msm_gem.c  |  2 +-
 drivers/gpu/drm/omapdrm/omap_gem.c |  3 +--
 drivers/gpu/drm/rockchip/rockchip_drm_gem.c|  3 +--
 drivers/gpu/drm/tegra/gem.c|  5 ++---
 drivers/gpu/drm/ttm/ttm_bo_vm.c|  3 +--
 drivers/gpu/drm/virtio/virtgpu_vram.c  |  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c   |  2 +-
 drivers/gpu/drm/xen/xen_drm_front_gem.c|  3 +--
 drivers/hsi/clients/cmt_speech.c   |  2 +-
 drivers/hwtracing/intel_th/msu.c   |  2 +-
 drivers/hwtracing/stm/core.c   |  2 +-
 drivers/infiniband/hw/hfi1/file_ops.c  |  4 ++--
 drivers/infiniband/hw/mlx5/main.c  |  4 ++--
 drivers/infiniband/hw/qib/qib_file_ops.c   | 13 ++---
 drivers/infiniband/hw/usnic/usnic_ib_verbs.c   |  2 +-
 drivers/infiniband/hw/vmw_pvrdma/pvrdma_verbs.c|  2 +-
 .../media/common/videobuf2/videobuf2-dma-contig.c  |  2 +-
 drivers/media/common/videobuf2/videobuf2-vmalloc.c |  2 +-
 drivers/media/v4l2-core/videobuf-dma-contig.c  |  2 +-
 drivers/media/v4l2-core/videobuf-dma-sg.c  |  4 ++--
 drivers/media/v4l2-core/videobuf-vmalloc.c |  2 +-
 drivers/misc/cxl/context.c |  2 +-
 drivers/misc/habanalabs/common/memory.c|  2 +-
 drivers/misc/habanalabs/gaudi/gaudi.c  |  4 ++--
 drivers/misc/habanalabs/gaudi2/gaudi2.c|  8 
 drivers/misc/habanalabs/goya/goya.c|  4 ++--
 drivers/misc/ocxl/context.c|  4 ++--
 drivers/misc/ocxl/sysfs.c  |  2 +-
 drivers/misc/open-dice.c   |  4 ++--
 drivers/misc/sgi-gru/grufile.c |  4 ++--
 drivers/misc/uacce/uacce.c |  2 +-
 drivers/sbus/char/oradax.c |  2 +-
 drivers/scsi/cxlflash/ocxl_hw.c|  2 +-
 drivers/scsi/sg.c  |  2 +-
 drivers/staging/media/atomisp/pci/hmm/hmm_bo.c |  2 +-
 drivers/staging/media/deprecated/meye/meye.c   |  4 ++--
 .../media/deprecated/stkwebcam/stk-webcam.c|  2 +-
 drivers/target/target_core_user.c  |  2 +-
 drivers/uio/uio.c  |  2 +-
 drivers/usb/core/devio.c   |  3 +--
 drivers/usb/mon/mon_bin.c  |  3 +--
 drivers/vdpa/vdpa_user/iova_domain.c   |  2 +-
 drivers/vfio/pci/vfio_pci_core.c   |  2 

[PATCH v4 3/7] mm: replace VM_LOCKED_CLEAR_MASK with VM_LOCKED_MASK

2023-01-26 Thread Suren Baghdasaryan
To simplify the usage of VM_LOCKED_CLEAR_MASK in vm_flags_clear(),
replace it with VM_LOCKED_MASK bitmask and convert all users.

Signed-off-by: Suren Baghdasaryan 
Acked-by: Michal Hocko 
Acked-by: Mel Gorman 
Acked-by: Mike Rapoport (IBM) 
---
 include/linux/mm.h | 4 ++--
 kernel/fork.c  | 2 +-
 mm/hugetlb.c   | 4 ++--
 mm/mlock.c | 6 +++---
 mm/mmap.c  | 6 +++---
 mm/mremap.c| 2 +-
 6 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index abb31103d060..ad4fdb9405ba 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -421,8 +421,8 @@ extern unsigned int kobjsize(const void *objp);
 /* This mask defines which mm->def_flags a process can inherit its parent */
 #define VM_INIT_DEF_MASK   VM_NOHUGEPAGE
 
-/* This mask is used to clear all the VMA flags used by mlock */
-#define VM_LOCKED_CLEAR_MASK   (~(VM_LOCKED | VM_LOCKONFAULT))
+/* This mask represents all the VMA flag bits used by mlock */
+#define VM_LOCKED_MASK (VM_LOCKED | VM_LOCKONFAULT)
 
 /* Arch-specific flags to clear when updating VM flags on protection change */
 #ifndef VM_ARCH_CLEAR
diff --git a/kernel/fork.c b/kernel/fork.c
index 9260f975b8f4..5e3029ea8e1e 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -659,7 +659,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
tmp->anon_vma = NULL;
} else if (anon_vma_fork(tmp, mpnt))
goto fail_nomem_anon_vma_fork;
-   tmp->vm_flags &= ~(VM_LOCKED | VM_LOCKONFAULT);
+   vm_flags_clear(tmp, VM_LOCKED_MASK);
file = tmp->vm_file;
if (file) {
struct address_space *mapping = file->f_mapping;
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index b6cbba105ffc..3a01a9dbf445 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -6970,8 +6970,8 @@ static unsigned long page_table_shareable(struct 
vm_area_struct *svma,
unsigned long s_end = sbase + PUD_SIZE;
 
/* Allow segments to share if only one is marked locked */
-   unsigned long vm_flags = vma->vm_flags & VM_LOCKED_CLEAR_MASK;
-   unsigned long svm_flags = svma->vm_flags & VM_LOCKED_CLEAR_MASK;
+   unsigned long vm_flags = vma->vm_flags & ~VM_LOCKED_MASK;
+   unsigned long svm_flags = svma->vm_flags & ~VM_LOCKED_MASK;
 
/*
 * match the virtual addresses, permission and the alignment of the
diff --git a/mm/mlock.c b/mm/mlock.c
index 0336f52e03d7..5c4fff93cd6b 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -497,7 +497,7 @@ static int apply_vma_lock_flags(unsigned long start, size_t 
len,
if (vma->vm_start != tmp)
return -ENOMEM;
 
-   newflags = vma->vm_flags & VM_LOCKED_CLEAR_MASK;
+   newflags = vma->vm_flags & ~VM_LOCKED_MASK;
newflags |= flags;
/* Here we know that  vma->vm_start <= nstart < vma->vm_end. */
tmp = vma->vm_end;
@@ -661,7 +661,7 @@ static int apply_mlockall_flags(int flags)
struct vm_area_struct *vma, *prev = NULL;
vm_flags_t to_add = 0;
 
-   current->mm->def_flags &= VM_LOCKED_CLEAR_MASK;
+   current->mm->def_flags &= ~VM_LOCKED_MASK;
if (flags & MCL_FUTURE) {
current->mm->def_flags |= VM_LOCKED;
 
@@ -681,7 +681,7 @@ static int apply_mlockall_flags(int flags)
for_each_vma(vmi, vma) {
vm_flags_t newflags;
 
-   newflags = vma->vm_flags & VM_LOCKED_CLEAR_MASK;
+   newflags = vma->vm_flags & ~VM_LOCKED_MASK;
newflags |= to_add;
 
/* Ignore errors */
diff --git a/mm/mmap.c b/mm/mmap.c
index d4abc6feced1..fa3cbd625850 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2671,7 +2671,7 @@ unsigned long mmap_region(struct file *file, unsigned 
long addr,
if ((vm_flags & VM_SPECIAL) || vma_is_dax(vma) ||
is_vm_hugetlb_page(vma) ||
vma == get_gate_vma(current->mm))
-   vma->vm_flags &= VM_LOCKED_CLEAR_MASK;
+   vm_flags_clear(vma, VM_LOCKED_MASK);
else
mm->locked_vm += (len >> PAGE_SHIFT);
}
@@ -3340,8 +3340,8 @@ static struct vm_area_struct *__install_special_mapping(
vma->vm_start = addr;
vma->vm_end = addr + len;
 
-   vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
-   vma->vm_flags &= VM_LOCKED_CLEAR_MASK;
+   vm_flags_init(vma, (vm_flags | mm->def_flags |
+ VM_DONTEXPAND | VM_SOFTDIRTY) & ~VM_LOCKED_MASK);
vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
 
vma->vm_ops = ops;
diff --git a/mm/mremap.c b/mm/mremap.c
index 1b3ee02bead7..55157b990091 100644
--- a/mm/mremap.c
+++ b/mm/mremap.c
@@ -687,7 +687,7 @@ static unsigned long move_vma(struct vm_area_struct 

[PATCH v4 2/7] mm: introduce vma->vm_flags wrapper functions

2023-01-26 Thread Suren Baghdasaryan
vm_flags are among VMA attributes which affect decisions like VMA merging
and splitting. Therefore all vm_flags modifications are performed after
taking exclusive mmap_lock to prevent vm_flags updates racing with such
operations. Introduce modifier functions for vm_flags to be used whenever
flags are updated. This way we can better check and control correct
locking behavior during these updates.

Signed-off-by: Suren Baghdasaryan 
Reviewed-by: Davidlohr Bueso 
Acked-by: Michal Hocko 
Acked-by: Mel Gorman 
---
 include/linux/mm.h   | 40 
 include/linux/mm_types.h | 10 +-
 2 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 8d636e895ee9..abb31103d060 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -627,6 +627,46 @@ static inline void vma_init(struct vm_area_struct *vma, 
struct mm_struct *mm)
INIT_LIST_HEAD(>anon_vma_chain);
 }
 
+/* Use when VMA is not part of the VMA tree and needs no locking */
+static inline void vm_flags_init(struct vm_area_struct *vma,
+vm_flags_t flags)
+{
+   ACCESS_PRIVATE(vma, __vm_flags) = flags;
+}
+
+/* Use when VMA is part of the VMA tree and modifications need coordination */
+static inline void vm_flags_reset(struct vm_area_struct *vma,
+ vm_flags_t flags)
+{
+   mmap_assert_write_locked(vma->vm_mm);
+   vm_flags_init(vma, flags);
+}
+
+static inline void vm_flags_set(struct vm_area_struct *vma,
+   vm_flags_t flags)
+{
+   mmap_assert_write_locked(vma->vm_mm);
+   ACCESS_PRIVATE(vma, __vm_flags) |= flags;
+}
+
+static inline void vm_flags_clear(struct vm_area_struct *vma,
+ vm_flags_t flags)
+{
+   mmap_assert_write_locked(vma->vm_mm);
+   ACCESS_PRIVATE(vma, __vm_flags) &= ~flags;
+}
+
+/*
+ * Use only when the order of set/clear operations is unimportant, otherwise
+ * use vm_flags_{set|clear} explicitly.
+ */
+static inline void vm_flags_mod(struct vm_area_struct *vma,
+   vm_flags_t set, vm_flags_t clear)
+{
+   mmap_assert_write_locked(vma->vm_mm);
+   vm_flags_init(vma, (vma->vm_flags | set) & ~clear);
+}
+
 static inline void vma_set_anonymous(struct vm_area_struct *vma)
 {
vma->vm_ops = NULL;
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 2d6d790d9bed..da983aedb741 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -491,7 +491,15 @@ struct vm_area_struct {
 * See vmf_insert_mixed_prot() for discussion.
 */
pgprot_t vm_page_prot;
-   unsigned long vm_flags; /* Flags, see mm.h. */
+
+   /*
+* Flags, see mm.h.
+* To modify use vm_flags_{init|reset|set|clear|mod} functions.
+*/
+   union {
+   const vm_flags_t vm_flags;
+   vm_flags_t __private __vm_flags;
+   };
 
/*
 * For areas with an address space and backing store,
-- 
2.39.1



[PATCH v4 0/7] introduce vm_flags modifier functions

2023-01-26 Thread Suren Baghdasaryan
This patchset was originally published as a part of per-VMA locking [1] and
was split after suggestion that it's viable on its own and to facilitate
the review process. It is now a preprequisite for the next version of per-VMA
lock patchset, which reuses vm_flags modifier functions to lock the VMA when
vm_flags are being updated.

VMA vm_flags modifications are usually done under exclusive mmap_lock
protection because this attrubute affects other decisions like VMA merging
or splitting and races should be prevented. Introduce vm_flags modifier
functions to enforce correct locking.

The patchset applies cleanly over mm-unstable branch of mm tree.

Changes since v3 [2]
- Fixed build breakage in nommu.c introduced in previous version,
per Andrew Morton
- Added back data_race() hint in vm_area_dup, per Mel Gorman
- Renamed vm_flags modifiers, per Andrew Morton, Mike Rapoport and Mel Gorman
- Changed vm_flags_mod to reset vm_flags with one assignment, per Mel Gorman
- Added comments about the need to copy vm_flags before ksm_madvise,
per Mel Gorman
- Added clarifications for __vm_flags_mod usage, per Mel Gorman

[1] https://lore.kernel.org/all/20230109205336.3665937-1-sur...@google.com/
[2] https://lore.kernel.org/lkml/20230125233554.153109-1-sur...@google.com/

Suren Baghdasaryan (7):
  kernel/fork: convert vma assignment to a memcpy
  mm: introduce vma->vm_flags wrapper functions
  mm: replace VM_LOCKED_CLEAR_MASK with VM_LOCKED_MASK
  mm: replace vma->vm_flags direct modifications with modifier calls
  mm: replace vma->vm_flags indirect modification in ksm_madvise
  mm: introduce __vm_flags_mod and use it in untrack_pfn
  mm: export dump_mm()

 arch/arm/kernel/process.c |  2 +-
 arch/ia64/mm/init.c   |  8 +--
 arch/loongarch/include/asm/tlb.h  |  2 +-
 arch/powerpc/kvm/book3s_hv_uvmem.c|  6 +-
 arch/powerpc/kvm/book3s_xive_native.c |  2 +-
 arch/powerpc/mm/book3s64/subpage_prot.c   |  2 +-
 arch/powerpc/platforms/book3s/vas-api.c   |  2 +-
 arch/powerpc/platforms/cell/spufs/file.c  | 14 ++---
 arch/s390/mm/gmap.c   |  9 ++-
 arch/x86/entry/vsyscall/vsyscall_64.c |  2 +-
 arch/x86/kernel/cpu/sgx/driver.c  |  2 +-
 arch/x86/kernel/cpu/sgx/virt.c|  2 +-
 arch/x86/mm/pat/memtype.c | 14 +++--
 arch/x86/um/mem_32.c  |  2 +-
 drivers/acpi/pfr_telemetry.c  |  2 +-
 drivers/android/binder.c  |  3 +-
 drivers/char/mspec.c  |  2 +-
 drivers/crypto/hisilicon/qm.c |  2 +-
 drivers/dax/device.c  |  2 +-
 drivers/dma/idxd/cdev.c   |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c   |  2 +-
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c  |  4 +-
 drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c |  4 +-
 drivers/gpu/drm/amd/amdkfd/kfd_events.c   |  4 +-
 drivers/gpu/drm/amd/amdkfd/kfd_process.c  |  4 +-
 drivers/gpu/drm/drm_gem.c |  2 +-
 drivers/gpu/drm/drm_gem_dma_helper.c  |  3 +-
 drivers/gpu/drm/drm_gem_shmem_helper.c|  2 +-
 drivers/gpu/drm/drm_vm.c  |  8 +--
 drivers/gpu/drm/etnaviv/etnaviv_gem.c |  2 +-
 drivers/gpu/drm/exynos/exynos_drm_gem.c   |  4 +-
 drivers/gpu/drm/gma500/framebuffer.c  |  2 +-
 drivers/gpu/drm/i810/i810_dma.c   |  2 +-
 drivers/gpu/drm/i915/gem/i915_gem_mman.c  |  4 +-
 drivers/gpu/drm/mediatek/mtk_drm_gem.c|  2 +-
 drivers/gpu/drm/msm/msm_gem.c |  2 +-
 drivers/gpu/drm/omapdrm/omap_gem.c|  3 +-
 drivers/gpu/drm/rockchip/rockchip_drm_gem.c   |  3 +-
 drivers/gpu/drm/tegra/gem.c   |  5 +-
 drivers/gpu/drm/ttm/ttm_bo_vm.c   |  3 +-
 drivers/gpu/drm/virtio/virtgpu_vram.c |  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c  |  2 +-
 drivers/gpu/drm/xen/xen_drm_front_gem.c   |  3 +-
 drivers/hsi/clients/cmt_speech.c  |  2 +-
 drivers/hwtracing/intel_th/msu.c  |  2 +-
 drivers/hwtracing/stm/core.c  |  2 +-
 drivers/infiniband/hw/hfi1/file_ops.c |  4 +-
 drivers/infiniband/hw/mlx5/main.c |  4 +-
 drivers/infiniband/hw/qib/qib_file_ops.c  | 13 ++---
 drivers/infiniband/hw/usnic/usnic_ib_verbs.c  |  2 +-
 .../infiniband/hw/vmw_pvrdma/pvrdma_verbs.c   |  2 +-
 .../common/videobuf2/videobuf2-dma-contig.c   |  2 +-
 .../common/videobuf2/videobuf2-vmalloc.c  |  2 +-
 drivers/media/v4l2-core/videobuf-dma-contig.c |  2 +-
 drivers/media/v4l2-core/videobuf-dma-sg.c |  4 +-
 drivers/media/v4l2-core/videobuf-vmalloc.c|  2 +-
 drivers/misc/cxl/context.c|  2 +-
 drivers/misc/habanalabs/common/memory.c   |  2 +-
 drivers/misc/habanalabs/gaudi/gaudi.c |  4 +-
 drivers/misc/habanalabs/gaudi2/gaudi2.c   |  8 +--
 

[PATCH v4 1/7] kernel/fork: convert vma assignment to a memcpy

2023-01-26 Thread Suren Baghdasaryan
Convert vma assignment in vm_area_dup() to a memcpy() to prevent compiler
errors when we add a const modifier to vma->vm_flags.

Signed-off-by: Suren Baghdasaryan 
Acked-by: Mel Gorman 
---
 kernel/fork.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/fork.c b/kernel/fork.c
index 441dcec60aae..9260f975b8f4 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -472,7 +472,7 @@ struct vm_area_struct *vm_area_dup(struct vm_area_struct 
*orig)
 * orig->shared.rb may be modified concurrently, but the clone
 * will be reinitialized.
 */
-   *new = data_race(*orig);
+   data_race(memcpy(new, orig, sizeof(*new)));
INIT_LIST_HEAD(>anon_vma_chain);
dup_anon_vma_name(orig, new);
}
-- 
2.39.1



Re: [PATCH v4 02/12] perf jevents metric: Add ability to rewrite metrics in terms of others

2023-01-26 Thread Ian Rogers
On Thu, Jan 26, 2023 at 7:59 AM John Garry  wrote:
>
> On 26/01/2023 01:18, Ian Rogers wrote:
> > Add RewriteMetricsInTermsOfOthers that iterates over pairs of names
> > and expressions trying to replace an expression, within the current
> > expression, with its name.
> >
> > Signed-off-by: Ian Rogers 
>
> hmmm ... did you test this for many python versions?
>
> Maybe this patch causes this error:
>
> Traceback (most recent call last):
>   File "pmu-events/jevents.py", line 7, in 
> import metric
>   File "/home/john/acme/tools/perf/pmu-events/metric.py", line 549, in
> 
> def RewriteMetricsInTermsOfOthers(metrics: list[Tuple[str, Expression]]
> TypeError: 'type' object is not subscriptable
> make[3]: *** [pmu-events/Build:26: pmu-events/pmu-events.c] Error 1
> make[2]: *** [Makefile.perf:676: pmu-events/pmu-events-in.o] Error 2
> make[2]: *** Waiting for unfinished jobs
>
> I have python 3.6.15
>
> Thanks,
> John

Apologies, I have to test python3.6 with docker and so if I think the
change is small enough.. My error, will spin v5.

Thanks,
Ian

>


Re: [PATCH v3 2/7] mm: introduce vma->vm_flags wrapper functions

2023-01-26 Thread Davidlohr Bueso

On Wed, 25 Jan 2023, Andrew Morton wrote:


On Wed, 25 Jan 2023 15:35:49 -0800 Suren Baghdasaryan  wrote:


vm_flags are among VMA attributes which affect decisions like VMA merging
and splitting. Therefore all vm_flags modifications are performed after
taking exclusive mmap_lock to prevent vm_flags updates racing with such
operations. Introduce modifier functions for vm_flags to be used whenever
flags are updated. This way we can better check and control correct
locking behavior during these updates.

...

--- a/include/linux/mm.h
+++ b/include/linux/mm.h
+static inline void init_vm_flags(struct vm_area_struct *vma,
+static inline void reset_vm_flags(struct vm_area_struct *vma,
+static inline void set_vm_flags(struct vm_area_struct *vma,
+static inline void clear_vm_flags(struct vm_area_struct *vma,
+static inline void mod_vm_flags(struct vm_area_struct *vma,


vm_flags_init(), vm_flags_reset(), etc?

This would be more idiomatic and I do think the most-significant-first
naming style is preferable.


I tend to prefer this naming yes, but lgtm regardless.

Reviewed-by: Davidlohr Bueso 


Re: arch/powerpc/kernel/head_85xx.o: warning: objtool: .head.text+0x1a6c: unannotated intra-function call

2023-01-26 Thread Segher Boessenkool
Hi!

On Wed, Jan 25, 2023 at 12:57:35PM +0530, Naveen N. Rao wrote:
> Sathvika Vasireddy wrote:
> >--- a/arch/powerpc/kvm/booke.c
> >+++ b/arch/powerpc/kvm/booke.c
> >@@ -917,7 +917,9 @@ static void kvmppc_fill_pt_regs(struct pt_regs *regs)
> >     asm("mr %0, 1" : "=r"(r1));
> >     asm("mflr %0" : "=r"(lr));
> >     asm("mfmsr %0" : "=r"(msr));
> >+   asm(".pushsection .discard.intra_function_calls; .long 999f; 
> >.popsection; 999:");
> >     asm("bl 1f; 1: mflr %0" : "=r"(ip));
> 
> I don't think you can assume that there won't be anything in between two 
> asm statements.

It would be a false assumption.  There is nothing that stops the
compiler from moving, duplicating, or even removing these statements
(removing only if no outputs from the asm are required of course).

> Does it work if you combine both the above asm 
> statements into a single one?
> 
> Even if that works, I don't think it is good to expand the macro here.  
> That asm statement looks to be trying to grab the current nip. I don't 
> know enough about that code, and someone who knows more about KVM may be 
> able to help, but it looks like we should be able to simply set 'ip' to 
> the address of kvmppc_fill_pt_regs()?

Such things are much better as actual assembler code (like, a .s file).
You have to be certain the compiler doesn't transform this in unexpected
ways, like, copy and move it to all callers for example.  You need the
mfmsr to remain somewhat in place for example.

A big reason to not want inline asm for things like this is you need so
very many operands in a single asm that way; it becomes very hard to
write, esp. if you want it to be correct code as well.  That is a good
hint there are better way to do this ;-)


Segher


Re: [PATCH v9 08/10] arm64: dts: ls1088a: Add serdes bindings

2023-01-26 Thread Sean Anderson
On 1/25/23 18:48, Shawn Guo wrote:
> On Thu, Dec 29, 2022 at 07:01:37PM -0500, Sean Anderson wrote:
>> This adds bindings for the SerDes devices. They are disabled by default
>> to prevent any breakage on existing boards.
>> 
>> Signed-off-by: Sean Anderson 
>> ---
>> 
>> (no changes since v4)
>> 
>> Changes in v4:
>> - Convert to new bindings
>> 
>> Changes in v3:
>> - New
>> 
>>  arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi | 18 ++
>>  1 file changed, 18 insertions(+)
>> 
>> diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi 
>> b/arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi
>> index 260d045dbd9a..ecf9d830e36f 100644
>> --- a/arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi
>> +++ b/arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi
>> @@ -238,6 +238,24 @@ reset: syscon@1e6 {
>>  reg = <0x0 0x1e6 0x0 0x1>;
>>  };
>>  
>> +serdes1: serdes@1ea {
>> +#address-cells = <1>;
>> +#size-cells = <0>;
>> +#clock-cells = <1>;
>> +compatible = "fsl,ls1088a-serdes", "fsl,lynx-10g";
>> +reg = <0x0 0x1ea 0x0 0x2000>;
> 
> Can we start the properties with compatible (and reg) like most of other
> device nodes?

Sure.

--Sean

>> +status = "disabled";
>> +};
>> +
>> +serdes2: serdes@1eb {
>> +#address-cells = <1>;
>> +#size-cells = <0>;
>> +#clock-cells = <1>;
>> +compatible = "fsl,ls1088a-serdes", "fsl,lynx-10g";
>> +reg = <0x0 0x1eb 0x0 0x2000>;
>> +status = "disabled";
>> +};
>> +
>>  isc: syscon@1f7 {
>>  compatible = "fsl,ls1088a-isc", "syscon";
>>  reg = <0x0 0x1f7 0x0 0x1>;
>> -- 
>> 2.35.1.1320.gc452695387.dirty
>> 



Re: [PATCH v3 6/7] mm: introduce mod_vm_flags_nolock and use it in untrack_pfn

2023-01-26 Thread Suren Baghdasaryan
On Thu, Jan 26, 2023 at 9:32 AM Mel Gorman  wrote:
>
> On Thu, Jan 26, 2023 at 08:18:31AM -0800, Suren Baghdasaryan wrote:
> > On Thu, Jan 26, 2023 at 7:47 AM Mel Gorman  
> > wrote:
> > >
> > > On Wed, Jan 25, 2023 at 03:35:53PM -0800, Suren Baghdasaryan wrote:
> > > > In cases when VMA flags are modified after VMA was isolated and 
> > > > mmap_lock
> > > > was downgraded, flags modifications would result in an assertion because
> > > > mmap write lock is not held.
> > >
> > > Add note that it's also used during exit when the locking of the VMAs
> > > becomes irrelevant (mm users is 0, should be no VMA modifications taking
> > > place other than zap).
> >
> > Ack.
> >
> > >
> > > The typical naming pattern when a caller either knows it holds the 
> > > necessary
> > > lock or knows it does not matter is __mod_vm_flags()
> >
> > Ok. It sounds less explicit but plenty of examples, so I'm fine with
> > such rename. Will apply in the next version.
> >
>
> It might be a personal thing. nolock to me is ambigious because it might
> mean "lock is already held", "no lock is necessary" or "no lock is acquired"
> where as *for me*, calling foo vs __foo *usually* means "direct callers of
> __foo take care of the locking, memory ordering, per-cpu pinning details etc"
> depending on the context. Of course, this convention is not universally true.
>
> > > > Pass a hint to untrack_pfn to conditionally use mod_vm_flags_nolock for
> > > > flags modification and to avoid assertion.
> > > >
> > > > Signed-off-by: Suren Baghdasaryan 
> > >
> > > Patch itself looks ok. It strays close to being "conditional locking"
> > > though which might attract some complaints.
> >
> > The description seems to accurately describe what's done here but I'm
> > open to better suggestions.
>
> I don't have alternative suggestions but if someone else reads the patch and
> says "this is conditional locking", you can at least claim that someone
> else considered "conditional locking" and didn't think it was a major
> problem in this specific patch.

Perfect. Thanks!

>
> --
> Mel Gorman
> SUSE Labs


Re: [PATCH v3 6/7] mm: introduce mod_vm_flags_nolock and use it in untrack_pfn

2023-01-26 Thread Mel Gorman
On Thu, Jan 26, 2023 at 08:18:31AM -0800, Suren Baghdasaryan wrote:
> On Thu, Jan 26, 2023 at 7:47 AM Mel Gorman  
> wrote:
> >
> > On Wed, Jan 25, 2023 at 03:35:53PM -0800, Suren Baghdasaryan wrote:
> > > In cases when VMA flags are modified after VMA was isolated and mmap_lock
> > > was downgraded, flags modifications would result in an assertion because
> > > mmap write lock is not held.
> >
> > Add note that it's also used during exit when the locking of the VMAs
> > becomes irrelevant (mm users is 0, should be no VMA modifications taking
> > place other than zap).
> 
> Ack.
> 
> >
> > The typical naming pattern when a caller either knows it holds the necessary
> > lock or knows it does not matter is __mod_vm_flags()
> 
> Ok. It sounds less explicit but plenty of examples, so I'm fine with
> such rename. Will apply in the next version.
> 

It might be a personal thing. nolock to me is ambigious because it might
mean "lock is already held", "no lock is necessary" or "no lock is acquired"
where as *for me*, calling foo vs __foo *usually* means "direct callers of
__foo take care of the locking, memory ordering, per-cpu pinning details etc"
depending on the context. Of course, this convention is not universally true.

> > > Pass a hint to untrack_pfn to conditionally use mod_vm_flags_nolock for
> > > flags modification and to avoid assertion.
> > >
> > > Signed-off-by: Suren Baghdasaryan 
> >
> > Patch itself looks ok. It strays close to being "conditional locking"
> > though which might attract some complaints.
> 
> The description seems to accurately describe what's done here but I'm
> open to better suggestions.

I don't have alternative suggestions but if someone else reads the patch and
says "this is conditional locking", you can at least claim that someone
else considered "conditional locking" and didn't think it was a major
problem in this specific patch.

-- 
Mel Gorman
SUSE Labs


RE: [PATCH v4 02/24] powerpc/pseries: Fix alignment of PLPKS structures and buffers

2023-01-26 Thread David Laight
From: Segher Boessenkool
> Sent: 26 January 2023 17:19
> 
> On Thu, Jan 26, 2023 at 12:09:53AM +1100, Michael Ellerman wrote:
> > Andrew Donnellan  writes:
> > > A number of structures and buffers passed to PKS hcalls have alignment
> > > requirements, which could on occasion cause problems:
> > >
> > > - Authorisation structures must be 16-byte aligned and must not cross a
> > >   page boundary
> > >
> > > - Label structures must not cross page boundaries
> > >
> > > - Password output buffers must not cross page boundaries
> > >
> > > Round up the allocations of these structures/buffers to the next power of
> > > 2 to make sure this happens.
> >
> > It's not the *next* power of 2, it's the *nearest* power of 2, including
> > the initial value if it's already a power of 2.
> 
> It's not the nearest either, the nearest power of two to 65 is 64.  You
> could say "but, round up" to which I would say "round?"  :-P
> 
> "Adjust the allocation size to be the smallest power of two greater than
> or equal to the given size."
> 
> "Pad to a power of two" in shorthand.  "Padded to a power of two if
> necessary" if you want to emphasise it can be a no-op.

Changing the size to kzalloc() doesn't help.
The alignment depends on the allocator and is only required to have
a relatively small alignment (ARCH_MINALIGN?) regardless of the size.

IIRC one of the allocators adds a small header to every item.
It won't return 16 byte aligned items at all.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, 
UK
Registration No: 1397386 (Wales)



Re: [PATCH v3 4/7] mm: replace vma->vm_flags direct modifications with modifier calls

2023-01-26 Thread Suren Baghdasaryan
On Thu, Jan 26, 2023 at 9:27 AM Mel Gorman  wrote:
>
> On Thu, Jan 26, 2023 at 08:10:26AM -0800, Suren Baghdasaryan wrote:
> > On Thu, Jan 26, 2023 at 7:10 AM Mel Gorman  
> > wrote:
> > >
> > > On Wed, Jan 25, 2023 at 03:35:51PM -0800, Suren Baghdasaryan wrote:
> > > > Replace direct modifications to vma->vm_flags with calls to modifier
> > > > functions to be able to track flag changes and to keep vma locking
> > > > correctness.
> > > >
> > > > Signed-off-by: Suren Baghdasaryan 
> > > > Acked-by: Michal Hocko 
> > >
> > > Acked-by: Mel Gorman 
> > >
> > > Minor comments that are safe to ignore.
> > >
> > > I think a better name for mod_vm_flags is set_clear_vm_flags to hint that
> > > the first flags are to be set and the second flags are to be cleared.
> > > For this patch, it doesn't matter, but it might avoid accidental swapping
> > > in the future.
> > >
> > > reset_vm_flags might also be better named as reinit_vma_flags (or
> > > vma_flags_reinit). Maybe also encourage the use of 
> > > [set|clear_mod]_vm_flags
> > > where possible in the comment to track exactly what is changing and
> > > why. Some cases like userfaultfd just want to clear __VM_UFFD_FLAGS but
> > > altering the flow in this patch is inappropriate and error prone. Others
> > > such as the infiniband changes and madvise are a lot more complex.
> >
> > That's a good point, but I don't want people to use mod_vm_flags() for
> > the cases when the order of set/clear really matters. In such cases
> > set_vm_flags() and clear_vm_flags() should be explicitly used. Maybe
> > to make that clear I should add a comment and rewrite the functions
> > as:
> >
> > void mod_vm_flags(vma, set, clear) {
> > vma.vm_flags = vma.vm_flags | set & clear;
> > }
> >
>
> Offhand, I'm not thinking of a case where that really matters and as they
> are not necessarily ordered, it's raising a read flag so yes, it definitely
> it needs a comment if the ordering matters.
>
> > In this patchset it's not that obvious but mod_vm_flags() was really
> > introduced in the original per-VMA lock patchset for efficiency to
> > avoid taking extra per-VMA locks. A combo of
> > set_vm_flags()+clear_vm_flags() would try to retake the same per-VMA
> > lock in the second call while mod_vm_flags() takes the lock only once
> > and does both operations.
>
> Ok, that seems fair but still needs a comment on why a mod_vm_flags is
> not necessarily equivalent to a set_vm_flags + clear_vm_flags in terms of
> correctness if that is indeed the case.
>
> > Not a huge overhead because we check if the
> > lock is already taken and bail out early but still...
> > So, would the above modification to mod_vm_flags() address your concern?
> >
>
> My concerns are entirely with the callers, not the implementation. If
> someone is modifying a call site using mod_vm_flags, they have to read
> through all the preceding logic to ensure the final combination of flags
> is valid.  It's a code maintenance issue, not a correctness issue.

Got it. I'll modify the implementation to make a single assignment and
will add a comment to use only when order doesn't matter.
Thanks!

>
> --
> Mel Gorman
> SUSE Labs


Re: [PATCH v3 1/7] kernel/fork: convert vma assignment to a memcpy

2023-01-26 Thread Paul E. McKenney
On Wed, Jan 25, 2023 at 05:34:49PM -0800, Andrew Morton wrote:
> On Wed, 25 Jan 2023 16:50:01 -0800 Suren Baghdasaryan  
> wrote:
> 
> > On Wed, Jan 25, 2023 at 4:22 PM Andrew Morton  
> > wrote:
> > >
> > > On Wed, 25 Jan 2023 15:35:48 -0800 Suren Baghdasaryan  
> > > wrote:
> > >
> > > > Convert vma assignment in vm_area_dup() to a memcpy() to prevent 
> > > > compiler
> > > > errors when we add a const modifier to vma->vm_flags.
> > > >
> > > > ...
> > > >
> > > > --- a/kernel/fork.c
> > > > +++ b/kernel/fork.c
> > > > @@ -482,7 +482,7 @@ struct vm_area_struct *vm_area_dup(struct 
> > > > vm_area_struct *orig)
> > > >* orig->shared.rb may be modified concurrently, but the 
> > > > clone
> > > >* will be reinitialized.
> > > >*/
> > > > - *new = data_race(*orig);
> > > > + memcpy(new, orig, sizeof(*new));
> > >
> > > The data_race() removal is unchangelogged?
> > 
> > True. I'll add a note in the changelog about that. Ideally I would
> > like to preserve it but I could not find a way to do that.
> 
> Perhaps Paul can comment?
> 
> I wonder if KCSAN knows how to detect this race, given that it's now in
> a memcpy.  I assume so.

I ran an experiment memcpy()ing between a static array and an onstack
array, and KCSAN did not complain.  But maybe I was setting it up wrong.

This is what I did:

long myid = (long)arg; /* different value for each task */
static unsigned long z1[10] = { 0 };
unsigned long z2[10];

...

memcpy(z1, z2, ARRAY_SIZE(z1) * sizeof(z1[0]));
for (zi = 0; zi < ARRAY_SIZE(z1); zi++)
z2[zi] += myid;
memcpy(z2, z1, ARRAY_SIZE(z1) * sizeof(z1[0]));

Adding Marco on CC for his thoughts.

Thanx, Paul


Re: [PATCH v3 4/7] mm: replace vma->vm_flags direct modifications with modifier calls

2023-01-26 Thread Mel Gorman
On Thu, Jan 26, 2023 at 08:10:26AM -0800, Suren Baghdasaryan wrote:
> On Thu, Jan 26, 2023 at 7:10 AM Mel Gorman  
> wrote:
> >
> > On Wed, Jan 25, 2023 at 03:35:51PM -0800, Suren Baghdasaryan wrote:
> > > Replace direct modifications to vma->vm_flags with calls to modifier
> > > functions to be able to track flag changes and to keep vma locking
> > > correctness.
> > >
> > > Signed-off-by: Suren Baghdasaryan 
> > > Acked-by: Michal Hocko 
> >
> > Acked-by: Mel Gorman 
> >
> > Minor comments that are safe to ignore.
> >
> > I think a better name for mod_vm_flags is set_clear_vm_flags to hint that
> > the first flags are to be set and the second flags are to be cleared.
> > For this patch, it doesn't matter, but it might avoid accidental swapping
> > in the future.
> >
> > reset_vm_flags might also be better named as reinit_vma_flags (or
> > vma_flags_reinit). Maybe also encourage the use of [set|clear_mod]_vm_flags
> > where possible in the comment to track exactly what is changing and
> > why. Some cases like userfaultfd just want to clear __VM_UFFD_FLAGS but
> > altering the flow in this patch is inappropriate and error prone. Others
> > such as the infiniband changes and madvise are a lot more complex.
> 
> That's a good point, but I don't want people to use mod_vm_flags() for
> the cases when the order of set/clear really matters. In such cases
> set_vm_flags() and clear_vm_flags() should be explicitly used. Maybe
> to make that clear I should add a comment and rewrite the functions
> as:
> 
> void mod_vm_flags(vma, set, clear) {
> vma.vm_flags = vma.vm_flags | set & clear;
> }
> 

Offhand, I'm not thinking of a case where that really matters and as they
are not necessarily ordered, it's raising a read flag so yes, it definitely
it needs a comment if the ordering matters.

> In this patchset it's not that obvious but mod_vm_flags() was really
> introduced in the original per-VMA lock patchset for efficiency to
> avoid taking extra per-VMA locks. A combo of
> set_vm_flags()+clear_vm_flags() would try to retake the same per-VMA
> lock in the second call while mod_vm_flags() takes the lock only once
> and does both operations.

Ok, that seems fair but still needs a comment on why a mod_vm_flags is
not necessarily equivalent to a set_vm_flags + clear_vm_flags in terms of
correctness if that is indeed the case.

> Not a huge overhead because we check if the
> lock is already taken and bail out early but still...
> So, would the above modification to mod_vm_flags() address your concern?
> 

My concerns are entirely with the callers, not the implementation. If
someone is modifying a call site using mod_vm_flags, they have to read
through all the preceding logic to ensure the final combination of flags
is valid.  It's a code maintenance issue, not a correctness issue.

-- 
Mel Gorman
SUSE Labs


Re: [PATCH v4 02/24] powerpc/pseries: Fix alignment of PLPKS structures and buffers

2023-01-26 Thread Segher Boessenkool
On Thu, Jan 26, 2023 at 12:09:53AM +1100, Michael Ellerman wrote:
> Andrew Donnellan  writes:
> > A number of structures and buffers passed to PKS hcalls have alignment
> > requirements, which could on occasion cause problems:
> >
> > - Authorisation structures must be 16-byte aligned and must not cross a
> >   page boundary
> >
> > - Label structures must not cross page boundaries
> >
> > - Password output buffers must not cross page boundaries
> >
> > Round up the allocations of these structures/buffers to the next power of
> > 2 to make sure this happens.
> 
> It's not the *next* power of 2, it's the *nearest* power of 2, including
> the initial value if it's already a power of 2.

It's not the nearest either, the nearest power of two to 65 is 64.  You
could say "but, round up" to which I would say "round?"  :-P

"Adjust the allocation size to be the smallest power of two greater than
or equal to the given size."

"Pad to a power of two" in shorthand.  "Padded to a power of two if
necessary" if you want to emphasise it can be a no-op.


Segher


Re: [PATCH v9 07/10] arm64: dts: ls1046ardb: Add serdes bindings

2023-01-26 Thread Sean Anderson
On 1/25/23 18:43, Shawn Guo wrote:
> On Thu, Dec 29, 2022 at 07:01:36PM -0500, Sean Anderson wrote:
>> This adds appropriate bindings for the macs which use the SerDes. The
>> 156.25MHz fixed clock is a crystal. The 100MHz clocks (there are
>> actually 3) come from a Renesas 6V49205B at address 69 on i2c0. There is
>> no driver for this device (and as far as I know all you can do with the
>> 100MHz clocks is gate them), so I have chosen to model it as a single
>> fixed clock.
>> 
>> Note: the SerDes1 lane numbering for the LS1046A is *reversed*.
>> This means that Lane A (what the driver thinks is lane 0) uses pins
>> SD1_TX3_P/N.
>> 
>> Because this will break ethernet if the serdes is not enabled, enable
>> the serdes driver by default on Layerscape.
>> 
>> Signed-off-by: Sean Anderson 
>> ---
>> This depends on [1].
>> 
>> [1] 
>> https://lore.kernel.org/netdev/20220804194705.459670-4-sean.ander...@seco.com/
>> 
>> Changes in v9:
>> - Fix name of phy mode node
>> - phy-type -> fsl,phy
>> 
>> Changes in v8:
>> - Rename serdes phy handles to use _A, _B, etc. instead of _0, _1, etc.
>>   This should help remind readers that the numbering corresponds to the
>>   physical layout of the registers, and not the lane (pin) number.
>> 
>> Changes in v6:
>> - XGI.9 -> XFI.9
>> 
>> Changes in v4:
>> - Convert to new bindings
>> 
>>  .../boot/dts/freescale/fsl-ls1046a-rdb.dts| 112 ++
>>  drivers/phy/freescale/Kconfig |   1 +
> 
> The phy driver Kconfig change shouldn't be part of this patch.

I put it here for bisectability, since this is the point where we need
to enable it. But I can do this in a separate patch if you want.

>>  2 files changed, 113 insertions(+)
>> 
>> diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1046a-rdb.dts 
>> b/arch/arm64/boot/dts/freescale/fsl-ls1046a-rdb.dts
>> index 7025aad8ae89..534f19855b47 100644
>> --- a/arch/arm64/boot/dts/freescale/fsl-ls1046a-rdb.dts
>> +++ b/arch/arm64/boot/dts/freescale/fsl-ls1046a-rdb.dts
>> @@ -10,6 +10,8 @@
>>  
>>  /dts-v1/;
>>  
>> +#include 
>> +
>>  #include "fsl-ls1046a.dtsi"
>>  
>>  / {
>> @@ -26,8 +28,110 @@ aliases {
>>  chosen {
>>  stdout-path = "serial0:115200n8";
>>  };
>> +
>> +clocks {
> 
> Drop this container node.

OK

--Sean
 
>> +clk_100mhz: clock-100mhz {
>> +compatible = "fixed-clock";
>> +#clock-cells = <0>;
>> +clock-frequency = <1>;
>> +};
>> +
>> +clk_156mhz: clock-156mhz {
>> +compatible = "fixed-clock";
>> +#clock-cells = <0>;
>> +clock-frequency = <15625>;
>> +};
>> +};
>>  };
>>  
>> + {
>> +clocks = <_100mhz>, <_156mhz>;
>> +clock-names = "ref0", "ref1";
>> +status = "okay";
>> +
>> +/*
>> + * XXX: Lane A uses pins SD1_RX3_P/N! That is, the lane numbers and pin
>> + * numbers are _reversed_. In addition, the PCCR documentation is
>> + * _inconsistent_ in its usage of these terms!
>> + *
>> + * PCCR "Lane 0" refers to...
>> + *  =
>> + *0 Lane A
>> + *2 Lane A
>> + *8 Lane A
>> + *9 Lane A
>> + *B Lane D!
>> + */
>> +serdes1_A: phy@0 {
>> +#phy-cells = <0>;
>> +reg = <0>;
>> +
>> +/* SGMII.6 */
>> +sgmii-0 {
>> +fsl,pccr = <0x8>;
>> +fsl,index = <0>;
>> +fsl,cfg = <0x1>;
>> +fsl,type = ;
>> +};
>> +};
>> +
>> +serdes1_B: phy@1 {
>> +#phy-cells = <0>;
>> +reg = <1>;
>> +
>> +/* SGMII.5 */
>> +sgmii-1 {
>> +fsl,pccr = <0x8>;
>> +fsl,index = <1>;
>> +fsl,cfg = <0x1>;
>> +fsl,type = ;
>> +};
>> +};
>> +
>> +serdes1_C: phy@2 {
>> +#phy-cells = <0>;
>> +reg = <2>;
>> +
>> +/* SGMII.10 */
>> +sgmii-2 {
>> +fsl,pccr = <0x8>;
>> +fsl,index = <2>;
>> +fsl,cfg = <0x1>;
>> +fsl,type = ;
>> +};
>> +
>> +/* XFI.10 */
>> +xfi-0 {
>> +fsl,pccr = <0xb>;
>> +fsl,index = <0>;
>> +fsl,cfg = <0x2>;
>> +fsl,type = ;
>> +};
>> +};
>> +
>> +serdes1_D: phy@3 {
>> +#phy-cells = <0>;
>> +reg = <3>;
>> +
>> +/* SGMII.9 */
>> +sgmii-3 {
>> +fsl,pccr = <0x8>;
>> +fsl,index = <3>;
>> +fsl,cfg = <0x1>;
>> +fsl,type = ;
>> +};
>> +
>> +/* XFI.9 */
>> +xfi-1 {
>> +fsl,pccr = <0xb>;

Re: [PATCH v9 06/10] arm64: dts: ls1046a: Add serdes bindings

2023-01-26 Thread Sean Anderson
On 1/25/23 18:46, Shawn Guo wrote:
> On Thu, Dec 29, 2022 at 07:01:35PM -0500, Sean Anderson wrote:
>> This adds bindings for the SerDes devices. They are disabled by default
> 
> s/bindings/descriptions?
> 
> The term "bindings" generally means the schema/doc in
> Documentation/devicetree/bindings/.

How about "nodes"?

--Sean

> Shawn
> 
>> to prevent any breakage on existing boards.
>> 
>> Signed-off-by: Sean Anderson 
>> ---
>> 
>> (no changes since v4)
>> 
>> Changes in v4:
>> - Convert to new bindings
>> 
>> Changes in v3:
>> - Describe modes in device tree
>> 
>> Changes in v2:
>> - Use one phy cell for SerDes1, since no lanes can be grouped
>> - Disable SerDes by default to prevent breaking boards inadvertently.
>> 
>>  arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi | 18 ++
>>  1 file changed, 18 insertions(+)
>> 
>> diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi 
>> b/arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi
>> index a01e3cfec77f..12adccd5caae 100644
>> --- a/arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi
>> +++ b/arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi
>> @@ -424,6 +424,24 @@ sfp: efuse@1e8 {
>>  clock-names = "sfp";
>>  };
>>  
>> +serdes1: serdes@1ea {
>> +#address-cells = <1>;
>> +#size-cells = <0>;
>> +#clock-cells = <1>;
>> +compatible = "fsl,ls1046a-serdes", "fsl,lynx-10g";
>> +reg = <0x0 0x1ea 0x0 0x2000>;
>> +status = "disabled";
>> +};
>> +
>> +serdes2: serdes@1eb {
>> +#address-cells = <1>;
>> +#size-cells = <0>;
>> +#clock-cells = <1>;
>> +compatible = "fsl,ls1046a-serdes", "fsl,lynx-10g";
>> +reg = <0x0 0x1eb 0x0 0x2000>;
>> +status = "disabled";
>> +};
>> +
>>  dcfg: dcfg@1ee {
>>  compatible = "fsl,ls1046a-dcfg", "syscon";
>>  reg = <0x0 0x1ee 0x0 0x1000>;
>> -- 
>> 2.35.1.1320.gc452695387.dirty
>> 



Re: [PATCH 15/15] backlight: backlight: Drop the deprecated fb_blank property

2023-01-26 Thread Lee Jones
On Thu, 26 Jan 2023, Sam Ravnborg wrote:

> Hi Lee,
> On Thu, Jan 26, 2023 at 02:27:26PM +, Lee Jones wrote:
> > On Sat, 07 Jan 2023, Sam Ravnborg via B4 Submission Endpoint wrote:
> > 
> > > From: Sam Ravnborg 
> > > 
> > > With all users gone remove the deprecated fb_blank member in
> > > backlight_properties.
> > > 
> > > Signed-off-by: Sam Ravnborg 
> > > Cc: Lee Jones 
> > > Cc: Daniel Thompson 
> > > Cc: Jingoo Han 
> > > ---
> > >  drivers/video/backlight/backlight.c |  2 --
> > >  include/linux/backlight.h   | 22 --
> > >  2 files changed, 24 deletions(-)
> > 
> > Applied, thanks
> 
> Some of the dependent patches in this series are not yet applied.
> I have them queued up for processing this weekend, but I missed the -rc6
> window for drm-misc so they will likely not hit upstream in the upcoming
> merge window.
> I can try to expedite it.
> 
> But if you have not yet pushed it, please revert this patch.
> Then I will resend only when the remaining patches are upstream.

Thanks for the info.  Dropped.

-- 
Lee Jones [李琼斯]


Re: [PATCH v3 6/7] mm: introduce mod_vm_flags_nolock and use it in untrack_pfn

2023-01-26 Thread Suren Baghdasaryan
On Thu, Jan 26, 2023 at 7:47 AM Mel Gorman  wrote:
>
> On Wed, Jan 25, 2023 at 03:35:53PM -0800, Suren Baghdasaryan wrote:
> > In cases when VMA flags are modified after VMA was isolated and mmap_lock
> > was downgraded, flags modifications would result in an assertion because
> > mmap write lock is not held.
>
> Add note that it's also used during exit when the locking of the VMAs
> becomes irrelevant (mm users is 0, should be no VMA modifications taking
> place other than zap).

Ack.

>
> The typical naming pattern when a caller either knows it holds the necessary
> lock or knows it does not matter is __mod_vm_flags()

Ok. It sounds less explicit but plenty of examples, so I'm fine with
such rename. Will apply in the next version.

>
> > Introduce mod_vm_flags_nolock to be used in such situation, when VMA is
> > not part of VMA tree and locking it is not required.
>
> Instead of such situations, describe in as "used when the caller takes
> responsibility for the required locking".

Ack.

>
> > Pass a hint to untrack_pfn to conditionally use mod_vm_flags_nolock for
> > flags modification and to avoid assertion.
> >
> > Signed-off-by: Suren Baghdasaryan 
>
> Patch itself looks ok. It strays close to being "conditional locking"
> though which might attract some complaints.

The description seems to accurately describe what's done here but I'm
open to better suggestions.
Thanks!

>
> --
> Mel Gorman
> SUSE Labs


Re: [PATCH 15/15] backlight: backlight: Drop the deprecated fb_blank property

2023-01-26 Thread Sam Ravnborg
Hi Lee,
On Thu, Jan 26, 2023 at 02:27:26PM +, Lee Jones wrote:
> On Sat, 07 Jan 2023, Sam Ravnborg via B4 Submission Endpoint wrote:
> 
> > From: Sam Ravnborg 
> > 
> > With all users gone remove the deprecated fb_blank member in
> > backlight_properties.
> > 
> > Signed-off-by: Sam Ravnborg 
> > Cc: Lee Jones 
> > Cc: Daniel Thompson 
> > Cc: Jingoo Han 
> > ---
> >  drivers/video/backlight/backlight.c |  2 --
> >  include/linux/backlight.h   | 22 --
> >  2 files changed, 24 deletions(-)
> 
> Applied, thanks

Some of the dependent patches in this series are not yet applied.
I have them queued up for processing this weekend, but I missed the -rc6
window for drm-misc so they will likely not hit upstream in the upcoming
merge window.
I can try to expedite it.

But if you have not yet pushed it, please revert this patch.
Then I will resend only when the remaining patches are upstream.

Sam


Re: [PATCH v3 5/7] mm: replace vma->vm_flags indirect modification in ksm_madvise

2023-01-26 Thread Suren Baghdasaryan
On Thu, Jan 26, 2023 at 7:19 AM Mel Gorman  wrote:
>
> On Wed, Jan 25, 2023 at 03:35:52PM -0800, Suren Baghdasaryan wrote:
> > Replace indirect modifications to vma->vm_flags with calls to modifier
> > functions to be able to track flag changes and to keep vma locking
> > correctness.
> >
> > Signed-off-by: Suren Baghdasaryan 
> > Acked-by: Michal Hocko 
> > ---
> >  arch/powerpc/kvm/book3s_hv_uvmem.c | 5 -
> >  arch/s390/mm/gmap.c| 5 -
> >  2 files changed, 8 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/powerpc/kvm/book3s_hv_uvmem.c 
> > b/arch/powerpc/kvm/book3s_hv_uvmem.c
> > index 1d67baa5557a..325a7a47d348 100644
> > --- a/arch/powerpc/kvm/book3s_hv_uvmem.c
> > +++ b/arch/powerpc/kvm/book3s_hv_uvmem.c
> > @@ -393,6 +393,7 @@ static int kvmppc_memslot_page_merge(struct kvm *kvm,
> >  {
> >   unsigned long gfn = memslot->base_gfn;
> >   unsigned long end, start = gfn_to_hva(kvm, gfn);
> > + unsigned long vm_flags;
> >   int ret = 0;
> >   struct vm_area_struct *vma;
> >   int merge_flag = (merge) ? MADV_MERGEABLE : MADV_UNMERGEABLE;
> > @@ -409,12 +410,14 @@ static int kvmppc_memslot_page_merge(struct kvm *kvm,
> >   ret = H_STATE;
> >   break;
> >   }
> > + vm_flags = vma->vm_flags;
> >   ret = ksm_madvise(vma, vma->vm_start, vma->vm_end,
> > -   merge_flag, >vm_flags);
> > +   merge_flag, _flags);
> >   if (ret) {
> >   ret = H_STATE;
> >   break;
> >   }
> > + reset_vm_flags(vma, vm_flags);
> >   start = vma->vm_end;
> >   } while (end > vma->vm_end);
>
> Add a comment on why the vm_flags are copied in case someone "optimises"
> this in the future? Something like
>
> /* Copy vm_flags to avoid any partial modifications in ksm_madvise. */

Ack.

>
> >
> > diff --git a/arch/s390/mm/gmap.c b/arch/s390/mm/gmap.c
> > index 3a695b8a1e3c..d5eb47dcdacb 100644
> > --- a/arch/s390/mm/gmap.c
> > +++ b/arch/s390/mm/gmap.c
> > @@ -2587,14 +2587,17 @@ int gmap_mark_unmergeable(void)
> >  {
> >   struct mm_struct *mm = current->mm;
> >   struct vm_area_struct *vma;
> > + unsigned long vm_flags;
> >   int ret;
> >   VMA_ITERATOR(vmi, mm, 0);
> >
> >   for_each_vma(vmi, vma) {
> > + vm_flags = vma->vm_flags;
> >   ret = ksm_madvise(vma, vma->vm_start, vma->vm_end,
> > -   MADV_UNMERGEABLE, >vm_flags);
> > +   MADV_UNMERGEABLE, _flags);
> >   if (ret)
> >   return ret;
> > + reset_vm_flags(vma, vm_flags);
>
> Same.
>
> Not necessary as such as there are few users of ksm_madvise and I doubt
> it'll introduce new surprises.
>
> With or without the comment;
>
> Acked-by: Mel Gorman 

Thanks!

>
> --
> Mel Gorman
> SUSE Labs


Re: [PATCH v3 4/7] mm: replace vma->vm_flags direct modifications with modifier calls

2023-01-26 Thread Suren Baghdasaryan
On Thu, Jan 26, 2023 at 7:10 AM Mel Gorman  wrote:
>
> On Wed, Jan 25, 2023 at 03:35:51PM -0800, Suren Baghdasaryan wrote:
> > Replace direct modifications to vma->vm_flags with calls to modifier
> > functions to be able to track flag changes and to keep vma locking
> > correctness.
> >
> > Signed-off-by: Suren Baghdasaryan 
> > Acked-by: Michal Hocko 
>
> Acked-by: Mel Gorman 
>
> Minor comments that are safe to ignore.
>
> I think a better name for mod_vm_flags is set_clear_vm_flags to hint that
> the first flags are to be set and the second flags are to be cleared.
> For this patch, it doesn't matter, but it might avoid accidental swapping
> in the future.
>
> reset_vm_flags might also be better named as reinit_vma_flags (or
> vma_flags_reinit). Maybe also encourage the use of [set|clear_mod]_vm_flags
> where possible in the comment to track exactly what is changing and
> why. Some cases like userfaultfd just want to clear __VM_UFFD_FLAGS but
> altering the flow in this patch is inappropriate and error prone. Others
> such as the infiniband changes and madvise are a lot more complex.

That's a good point, but I don't want people to use mod_vm_flags() for
the cases when the order of set/clear really matters. In such cases
set_vm_flags() and clear_vm_flags() should be explicitly used. Maybe
to make that clear I should add a comment and rewrite the functions
as:

void mod_vm_flags(vma, set, clear) {
vma.vm_flags = vma.vm_flags | set & clear;
}

In this patchset it's not that obvious but mod_vm_flags() was really
introduced in the original per-VMA lock patchset for efficiency to
avoid taking extra per-VMA locks. A combo of
set_vm_flags()+clear_vm_flags() would try to retake the same per-VMA
lock in the second call while mod_vm_flags() takes the lock only once
and does both operations. Not a huge overhead because we check if the
lock is already taken and bail out early but still...
So, would the above modification to mod_vm_flags() address your concern?

>
> --
> Mel Gorman
> SUSE Labs


Re: [PATCH v3 2/7] mm: introduce vma->vm_flags wrapper functions

2023-01-26 Thread Suren Baghdasaryan
On Thu, Jan 26, 2023 at 5:58 AM Mel Gorman  wrote:
>
> On Wed, Jan 25, 2023 at 03:35:49PM -0800, Suren Baghdasaryan wrote:
> > vm_flags are among VMA attributes which affect decisions like VMA merging
> > and splitting. Therefore all vm_flags modifications are performed after
> > taking exclusive mmap_lock to prevent vm_flags updates racing with such
> > operations. Introduce modifier functions for vm_flags to be used whenever
> > flags are updated. This way we can better check and control correct
> > locking behavior during these updates.
> >
> > Signed-off-by: Suren Baghdasaryan 
>
> With or without the suggested rename;
>
> Acked-by: Mel Gorman 

Thanks! I'll make the renames and repost the patchset.
vm_flags_init(), vm_flags_reset(), etc. sounds like a good naming for
this.

>
> --
> Mel Gorman
> SUSE Labs


Re: [PATCH v4 02/12] perf jevents metric: Add ability to rewrite metrics in terms of others

2023-01-26 Thread John Garry

On 26/01/2023 01:18, Ian Rogers wrote:

Add RewriteMetricsInTermsOfOthers that iterates over pairs of names
and expressions trying to replace an expression, within the current
expression, with its name.

Signed-off-by: Ian Rogers 


hmmm ... did you test this for many python versions?

Maybe this patch causes this error:

Traceback (most recent call last):
 File "pmu-events/jevents.py", line 7, in 
   import metric
 File "/home/john/acme/tools/perf/pmu-events/metric.py", line 549, in 


   def RewriteMetricsInTermsOfOthers(metrics: list[Tuple[str, Expression]]
TypeError: 'type' object is not subscriptable
make[3]: *** [pmu-events/Build:26: pmu-events/pmu-events.c] Error 1
make[2]: *** [Makefile.perf:676: pmu-events/pmu-events-in.o] Error 2
make[2]: *** Waiting for unfinished jobs

I have python 3.6.15

Thanks,
John




Re: [PATCH v3 1/7] kernel/fork: convert vma assignment to a memcpy

2023-01-26 Thread Suren Baghdasaryan
On Thu, Jan 26, 2023 at 3:52 AM Mel Gorman  wrote:
>
> On Wed, Jan 25, 2023 at 05:34:49PM -0800, Andrew Morton wrote:
> > On Wed, 25 Jan 2023 16:50:01 -0800 Suren Baghdasaryan  
> > wrote:
> >
> > > On Wed, Jan 25, 2023 at 4:22 PM Andrew Morton  
> > > wrote:
> > > >
> > > > On Wed, 25 Jan 2023 15:35:48 -0800 Suren Baghdasaryan 
> > > >  wrote:
> > > >
> > > > > Convert vma assignment in vm_area_dup() to a memcpy() to prevent 
> > > > > compiler
> > > > > errors when we add a const modifier to vma->vm_flags.
> > > > >
> > > > > ...
> > > > >
> > > > > --- a/kernel/fork.c
> > > > > +++ b/kernel/fork.c
> > > > > @@ -482,7 +482,7 @@ struct vm_area_struct *vm_area_dup(struct 
> > > > > vm_area_struct *orig)
> > > > >* orig->shared.rb may be modified concurrently, but 
> > > > > the clone
> > > > >* will be reinitialized.
> > > > >*/
> > > > > - *new = data_race(*orig);
> > > > > + memcpy(new, orig, sizeof(*new));
> > > >
> > > > The data_race() removal is unchangelogged?
> > >
> > > True. I'll add a note in the changelog about that. Ideally I would
> > > like to preserve it but I could not find a way to do that.
> > >
> >
> > Perhaps Paul can comment?
> >
> > I wonder if KCSAN knows how to detect this race, given that it's now in
> > a memcpy.  I assume so.
>
> data_race() is just wrapping an expression around
> __kcsan_[en|dis]able_current and ensuring the expression is evaluated once
> and returning the correct type. I believe the following should be sufficient.

Thanks for the suggestion, Mel! I'll try that.

>
> diff --git a/kernel/fork.c b/kernel/fork.c
> index 9f7fe3541897..1b30ee568e02 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -472,7 +472,7 @@ struct vm_area_struct *vm_area_dup(struct vm_area_struct 
> *orig)
>  * orig->shared.rb may be modified concurrently, but the clone
>  * will be reinitialized.
>  */
> -   *new = data_race(*orig);
> +   data_race(memcpy(new, orig, sizeof(*new)));
> INIT_LIST_HEAD(>anon_vma_chain);
> dup_anon_vma_name(orig, new);
> }
>
> I don't see how memcpy could automagically figure out whether the memcpy
> is prone to races or not in an arbitrary context.
>
> Assuming using data_race this way is ok then
>
> Acked-by: Mel Gorman 

Thanks!

>
> --
> Mel Gorman
> SUSE Labs


Re: [PATCH v3 5/7] mm: replace vma->vm_flags indirect modification in ksm_madvise

2023-01-26 Thread Mel Gorman
On Wed, Jan 25, 2023 at 03:35:52PM -0800, Suren Baghdasaryan wrote:
> Replace indirect modifications to vma->vm_flags with calls to modifier
> functions to be able to track flag changes and to keep vma locking
> correctness.
> 
> Signed-off-by: Suren Baghdasaryan 
> Acked-by: Michal Hocko 
> ---
>  arch/powerpc/kvm/book3s_hv_uvmem.c | 5 -
>  arch/s390/mm/gmap.c| 5 -
>  2 files changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/powerpc/kvm/book3s_hv_uvmem.c 
> b/arch/powerpc/kvm/book3s_hv_uvmem.c
> index 1d67baa5557a..325a7a47d348 100644
> --- a/arch/powerpc/kvm/book3s_hv_uvmem.c
> +++ b/arch/powerpc/kvm/book3s_hv_uvmem.c
> @@ -393,6 +393,7 @@ static int kvmppc_memslot_page_merge(struct kvm *kvm,
>  {
>   unsigned long gfn = memslot->base_gfn;
>   unsigned long end, start = gfn_to_hva(kvm, gfn);
> + unsigned long vm_flags;
>   int ret = 0;
>   struct vm_area_struct *vma;
>   int merge_flag = (merge) ? MADV_MERGEABLE : MADV_UNMERGEABLE;
> @@ -409,12 +410,14 @@ static int kvmppc_memslot_page_merge(struct kvm *kvm,
>   ret = H_STATE;
>   break;
>   }
> + vm_flags = vma->vm_flags;
>   ret = ksm_madvise(vma, vma->vm_start, vma->vm_end,
> -   merge_flag, >vm_flags);
> +   merge_flag, _flags);
>   if (ret) {
>   ret = H_STATE;
>   break;
>   }
> + reset_vm_flags(vma, vm_flags);
>   start = vma->vm_end;
>   } while (end > vma->vm_end);

Add a comment on why the vm_flags are copied in case someone "optimises"
this in the future? Something like

/* Copy vm_flags to avoid any partial modifications in ksm_madvise. */

>  
> diff --git a/arch/s390/mm/gmap.c b/arch/s390/mm/gmap.c
> index 3a695b8a1e3c..d5eb47dcdacb 100644
> --- a/arch/s390/mm/gmap.c
> +++ b/arch/s390/mm/gmap.c
> @@ -2587,14 +2587,17 @@ int gmap_mark_unmergeable(void)
>  {
>   struct mm_struct *mm = current->mm;
>   struct vm_area_struct *vma;
> + unsigned long vm_flags;
>   int ret;
>   VMA_ITERATOR(vmi, mm, 0);
>  
>   for_each_vma(vmi, vma) {
> + vm_flags = vma->vm_flags;
>   ret = ksm_madvise(vma, vma->vm_start, vma->vm_end,
> -   MADV_UNMERGEABLE, >vm_flags);
> +   MADV_UNMERGEABLE, _flags);
>   if (ret)
>   return ret;
> + reset_vm_flags(vma, vm_flags);

Same.

Not necessary as such as there are few users of ksm_madvise and I doubt
it'll introduce new surprises.

With or without the comment;

Acked-by: Mel Gorman 

-- 
Mel Gorman
SUSE Labs


Re: [PATCH v3 4/7] mm: replace vma->vm_flags direct modifications with modifier calls

2023-01-26 Thread Mel Gorman
On Wed, Jan 25, 2023 at 03:35:51PM -0800, Suren Baghdasaryan wrote:
> Replace direct modifications to vma->vm_flags with calls to modifier
> functions to be able to track flag changes and to keep vma locking
> correctness.
> 
> Signed-off-by: Suren Baghdasaryan 
> Acked-by: Michal Hocko 

Acked-by: Mel Gorman 

Minor comments that are safe to ignore.

I think a better name for mod_vm_flags is set_clear_vm_flags to hint that
the first flags are to be set and the second flags are to be cleared.
For this patch, it doesn't matter, but it might avoid accidental swapping
in the future.

reset_vm_flags might also be better named as reinit_vma_flags (or
vma_flags_reinit). Maybe also encourage the use of [set|clear_mod]_vm_flags
where possible in the comment to track exactly what is changing and
why. Some cases like userfaultfd just want to clear __VM_UFFD_FLAGS but
altering the flow in this patch is inappropriate and error prone. Others
such as the infiniband changes and madvise are a lot more complex.

-- 
Mel Gorman
SUSE Labs


Re: [PATCH 15/15] backlight: backlight: Drop the deprecated fb_blank property

2023-01-26 Thread Lee Jones
On Sat, 07 Jan 2023, Sam Ravnborg via B4 Submission Endpoint wrote:

> From: Sam Ravnborg 
> 
> With all users gone remove the deprecated fb_blank member in
> backlight_properties.
> 
> Signed-off-by: Sam Ravnborg 
> Cc: Lee Jones 
> Cc: Daniel Thompson 
> Cc: Jingoo Han 
> ---
>  drivers/video/backlight/backlight.c |  2 --
>  include/linux/backlight.h   | 22 --
>  2 files changed, 24 deletions(-)

Applied, thanks

-- 
Lee Jones [李琼斯]


Re: [PATCH v4 11/12] perf jevents: Add model list option

2023-01-26 Thread John Garry

On 26/01/2023 14:20, Arnaldo Carvalho de Melo wrote:

Em Thu, Jan 26, 2023 at 01:44:39PM +, John Garry escreveu:

On 26/01/2023 01:18, Ian Rogers wrote:

This allows the set of generated jevents events and metrics be limited
to a subset of the model names. Appropriate if trying to minimize the
binary size where only a set of models are possible.

Signed-off-by: Ian Rogers

Thanks for this:

Reviewed-by: John Garry

Thanks for reviewing the series John, I see there are a few patches for
which you didn't provide your Reviewed-by, 


Hi Arnaldo,


are you planning to review
those as well?



I will do when I get a chance over the next day or so. I am just 
checking the easier ones at the moment :)


Thanks,
John



Re: [PATCH v3 3/7] mm: replace VM_LOCKED_CLEAR_MASK with VM_LOCKED_MASK

2023-01-26 Thread Mel Gorman
On Wed, Jan 25, 2023 at 03:35:50PM -0800, Suren Baghdasaryan wrote:
> To simplify the usage of VM_LOCKED_CLEAR_MASK in clear_vm_flags(),
> replace it with VM_LOCKED_MASK bitmask and convert all users.
> 
> Signed-off-by: Suren Baghdasaryan 
> Acked-by: Michal Hocko 

Acked-by: Mel Gorman 

-- 
Mel Gorman
SUSE Labs


Re: [PATCH v4 11/12] perf jevents: Add model list option

2023-01-26 Thread Arnaldo Carvalho de Melo
Em Thu, Jan 26, 2023 at 01:44:39PM +, John Garry escreveu:
> On 26/01/2023 01:18, Ian Rogers wrote:
> > This allows the set of generated jevents events and metrics be limited
> > to a subset of the model names. Appropriate if trying to minimize the
> > binary size where only a set of models are possible.
> > 
> > Signed-off-by: Ian Rogers 
> 
> Thanks for this:
> 
> Reviewed-by: John Garry 

Thanks for reviewing the series John, I see there are a few patches for
which you didn't provide your Reviewed-by, are you planning to review
those as well?

- Arnaldo
 
> > ---
> >   tools/perf/pmu-events/Build  |  3 ++-
> >   tools/perf/pmu-events/jevents.py | 14 ++
> >   2 files changed, 16 insertions(+), 1 deletion(-)
> > 
> > diff --git a/tools/perf/pmu-events/Build b/tools/perf/pmu-events/Build
> > index 15b9e8fdbffa..a14de24ecb69 100644
> > --- a/tools/perf/pmu-events/Build
> > +++ b/tools/perf/pmu-events/Build
> > @@ -10,6 +10,7 @@ JEVENTS_PY=  pmu-events/jevents.py
> >   ifeq ($(JEVENTS_ARCH),)
> >   JEVENTS_ARCH=$(SRCARCH)
> >   endif
> > +JEVENTS_MODEL ?= all
> >   #
> >   # Locate/process JSON files in pmu-events/arch/
> > @@ -23,5 +24,5 @@ $(OUTPUT)pmu-events/pmu-events.c: 
> > pmu-events/empty-pmu-events.c
> >   else
> >   $(OUTPUT)pmu-events/pmu-events.c: $(JSON) $(JSON_TEST) $(JEVENTS_PY) 
> > pmu-events/metric.py
> > $(call rule_mkdir)
> > -   $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) 
> > pmu-events/arch $@
> > +   $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) 
> > $(JEVENTS_MODEL) pmu-events/arch $@
> >   endif
> > diff --git a/tools/perf/pmu-events/jevents.py 
> > b/tools/perf/pmu-events/jevents.py
> > index 627ee817f57f..2bcd07ce609f 100755
> > --- a/tools/perf/pmu-events/jevents.py
> > +++ b/tools/perf/pmu-events/jevents.py
> > @@ -599,6 +599,8 @@ const struct pmu_events_map pmu_events_map[] = {
> >   else:
> > metric_tblname = 'NULL'
> > metric_size = '0'
> > +if event_size == '0' and metric_size == '0':
> > +  continue
> >   cpuid = row[0].replace('\\', '')
> >   _args.output_file.write(f"""{{
> >   \t.arch = "{arch}",
> > @@ -888,12 +890,24 @@ def main() -> None:
> > action: Callable[[Sequence[str], os.DirEntry], None]) -> None:
> >   """Replicate the directory/file walking behavior of C's file tree 
> > walk."""
> >   for item in os.scandir(path):
> > +  if _args.model != 'all' and item.is_dir():
> > +# Check if the model matches one in _args.model.
> > +if len(parents) == _args.model.split(',')[0].count('/'):
> > +  # We're testing the correct directory.
> > +  item_path = '/'.join(parents) + ('/' if len(parents) > 0 else 
> > '') + item.name
> > +  if 'test' not in item_path and item_path not in 
> > _args.model.split(','):
> > +continue
> > action(parents, item)
> > if item.is_dir():
> >   ftw(item.path, parents + [item.name], action)
> > ap = argparse.ArgumentParser()
> > ap.add_argument('arch', help='Architecture name like x86')
> > +  ap.add_argument('model', help='''Select a model such as skylake to
> > +reduce the code size.  Normally set to "all". For architectures like
> > +ARM64 with an implementor/model, the model must include the implementor
> 
> mega-nit: /s/ARM64/arm64/
> 
> it just makes grepping easier (without -i, of course)
> 
> > +such as "arm/cortex-a34".''',
> > +  default='all')
> > ap.add_argument(
> > 'starting_dir',
> > type=dir_path,
> 

-- 

- Arnaldo


Re: [PATCH v3 3/7] mm: replace VM_LOCKED_CLEAR_MASK with VM_LOCKED_MASK

2023-01-26 Thread Mel Gorman
On Wed, Jan 25, 2023 at 03:35:50PM -0800, Suren Baghdasaryan wrote:
> To simplify the usage of VM_LOCKED_CLEAR_MASK in clear_vm_flags(),
> replace it with VM_LOCKED_MASK bitmask and convert all users.
> 
> Signed-off-by: Suren Baghdasaryan 
> Acked-by: Michal Hocko 

Acked-by: Mel Gorman 

-- 
Mel Gorman
SUSE Labs


Re: [PATCH v3 2/7] mm: introduce vma->vm_flags wrapper functions

2023-01-26 Thread Mel Gorman
On Wed, Jan 25, 2023 at 03:35:49PM -0800, Suren Baghdasaryan wrote:
> vm_flags are among VMA attributes which affect decisions like VMA merging
> and splitting. Therefore all vm_flags modifications are performed after
> taking exclusive mmap_lock to prevent vm_flags updates racing with such
> operations. Introduce modifier functions for vm_flags to be used whenever
> flags are updated. This way we can better check and control correct
> locking behavior during these updates.
> 
> Signed-off-by: Suren Baghdasaryan 

With or without the suggested rename;

Acked-by: Mel Gorman 

-- 
Mel Gorman
SUSE Labs


Re: [PATCH v2 02/10] ARM: dts: ls1021a: add TQ-Systems MBLS102xA device tree

2023-01-26 Thread Alexander Stein
Hi Shawn,

thanks for your feedback.

Am Donnerstag, 26. Januar 2023, 10:44:21 CET schrieb Shawn Guo:
> On Fri, Jan 20, 2023 at 02:34:47PM +0100, Alexander Stein wrote:
> > Add device tree for the MBLS102xA mainboard with TQMLS1021A SoM.
> > 
> > Signed-off-by: Alexander Stein 
> > ---
> > Changes in v2:
> > * Remove unnecessary status = "okay"
> > * Remove underscore from node names
> > * Move reg direct below compatiblefor i2c devices
> > * Remove i2c device nodes without software support
> > 
> >   Add a comment about existance for the device though
> >  
> >  arch/arm/boot/dts/Makefile|   1 +
> >  .../boot/dts/ls1021a-tqmls1021a-mbls1021a.dts | 406 ++
> >  arch/arm/boot/dts/ls1021a-tqmls1021a.dtsi |  81 
> >  3 files changed, 488 insertions(+)
> >  create mode 100644 arch/arm/boot/dts/ls1021a-tqmls1021a-mbls1021a.dts
> >  create mode 100644 arch/arm/boot/dts/ls1021a-tqmls1021a.dtsi
> > 
> > diff --git a/arch/arm/boot/dts/Makefile b/arch/arm/boot/dts/Makefile
> > index d0c07867aeabe..44b5ed44b13d6 100644
> > --- a/arch/arm/boot/dts/Makefile
> > +++ b/arch/arm/boot/dts/Makefile
> > @@ -802,6 +802,7 @@ dtb-$(CONFIG_SOC_LS1021A) += \
> > 
> > ls1021a-iot.dtb \
> > ls1021a-moxa-uc-8410a.dtb \
> > ls1021a-qds.dtb \
> > 
> > +   ls1021a-tqmls1021a-mbls1021a.dtb \
> > 
> > ls1021a-tsn.dtb \
> > ls1021a-twr.dtb
> >  
> >  dtb-$(CONFIG_SOC_VF610) += \
> > 
> > diff --git a/arch/arm/boot/dts/ls1021a-tqmls1021a-mbls1021a.dts
> > b/arch/arm/boot/dts/ls1021a-tqmls1021a-mbls1021a.dts new file mode 100644
> > index 0..aa8b605344655
> > --- /dev/null
> > +++ b/arch/arm/boot/dts/ls1021a-tqmls1021a-mbls1021a.dts
> > @@ -0,0 +1,406 @@
> > +// SPDX-License-Identifier: (GPL-2.0-or-later OR X11)
> > +/*
> > + * Copyright 2013-2014 Freescale Semiconductor, Inc.
> > + * Copyright 2018-2023 TQ-Systems GmbH ,
> > + * D-82229 Seefeld, Germany.
> > + * Author: Alexander Stein
> > + */
> > +
> > +/dts-v1/;
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include "ls1021a-tqmls1021a.dtsi"
> > +
> > +/ {
> > +   model = "TQMLS102xA SOM on MBLS102xA";
> > +   compatible = "tq,ls1021a-tqmls1021a-mbls102xa", "tq,ls1021a-
tqmls1021a",
> > "fsl,ls1021a"; +
> > +   audio_mclk: audio-clock {
> > +   compatible = "fixed-clock";
> > +   #clock-cells = <0>;
> > +   clock-frequency = <2500>;
> > +   };
> > +
> > +   backlight_dcu: backlight {
> > +   compatible = "gpio-backlight";
> > +   gpios = < 0 GPIO_ACTIVE_LOW>;
> > +   status = "disabled";
> > +   };
> > +
> > +   gpio-keys {
> > +   compatible = "gpio-keys";
> > +   autorepeat;
> > +
> > +   switch-1 {
> > +   label = "S6";
> > +   linux,code = ;
> > +   gpios = <_0 0 GPIO_ACTIVE_LOW>;
> > +   };
> > +
> > +   btn2: switch-2 {
> > +   label = "S7";
> > +   linux,code = ;
> > +   gpios = <_0 1 GPIO_ACTIVE_LOW>;
> > +   };
> > +
> > +   switch-3 {
> > +   label = "S8";
> > +   linux,code = ;
> > +   gpios = <_0 2 GPIO_ACTIVE_LOW>;
> > +   };
> > +   };
> > +
> > +   gpio_leds: gpio-leds {
> > +   compatible = "gpio-leds";
> > +
> > +   led-0 {
> > +   color = ;
> > +   function = LED_FUNCTION_STATUS;
> > +   function-enumerator = <0>;
> > +   gpios = <_2 4 GPIO_ACTIVE_LOW>;
> > +   linux,default-trigger = "default-on";
> > +   };
> > +
> > +   led-1 {
> > +   color = ;
> > +   function = LED_FUNCTION_STATUS;
> > +   function-enumerator = <1>;
> > +   gpios = <_2 5 GPIO_ACTIVE_LOW>;
> > +   linux,default-trigger = "default-on";
> > +   };
> > +
> > +   led-2 {
> > +   color = ;
> > +   function = LED_FUNCTION_STATUS;
> > +   function-enumerator = <2>;
> > +   gpios = <_2 6 GPIO_ACTIVE_LOW>;
> > +   linux,default-trigger = "default-on";
> > +   };
> > +
> > +   led-3 {
> > +   color = ;
> > +   function = LED_FUNCTION_HEARTBEAT;
> > +   function-enumerator = <0>;
> > +   gpios = <_2 7 GPIO_ACTIVE_LOW>;
> > +   linux,default-trigger = "heartbeat";
> > +   };
> > +   };
> > +
> > +   lvds_encoder: lvds-encoder {
> > +   compatible = "ti,sn75lvds83", "lvds-encoder";
> > +   power-supply = <_3p3v>;
> > +   status = "disabled";
> > +
> > +   ports {
> > +   #address-cells = <1>;
> > +   #size-cells = <0>;
> > +
> > +   port@0 {
> > +   reg = 

Re: [PATCH v4 11/12] perf jevents: Add model list option

2023-01-26 Thread John Garry

On 26/01/2023 01:18, Ian Rogers wrote:

This allows the set of generated jevents events and metrics be limited
to a subset of the model names. Appropriate if trying to minimize the
binary size where only a set of models are possible.

Signed-off-by: Ian Rogers 


Thanks for this:

Reviewed-by: John Garry 


---
  tools/perf/pmu-events/Build  |  3 ++-
  tools/perf/pmu-events/jevents.py | 14 ++
  2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/tools/perf/pmu-events/Build b/tools/perf/pmu-events/Build
index 15b9e8fdbffa..a14de24ecb69 100644
--- a/tools/perf/pmu-events/Build
+++ b/tools/perf/pmu-events/Build
@@ -10,6 +10,7 @@ JEVENTS_PY=  pmu-events/jevents.py
  ifeq ($(JEVENTS_ARCH),)
  JEVENTS_ARCH=$(SRCARCH)
  endif
+JEVENTS_MODEL ?= all
  
  #

  # Locate/process JSON files in pmu-events/arch/
@@ -23,5 +24,5 @@ $(OUTPUT)pmu-events/pmu-events.c: 
pmu-events/empty-pmu-events.c
  else
  $(OUTPUT)pmu-events/pmu-events.c: $(JSON) $(JSON_TEST) $(JEVENTS_PY) 
pmu-events/metric.py
$(call rule_mkdir)
-   $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) 
pmu-events/arch $@
+   $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) 
$(JEVENTS_MODEL) pmu-events/arch $@
  endif
diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py
index 627ee817f57f..2bcd07ce609f 100755
--- a/tools/perf/pmu-events/jevents.py
+++ b/tools/perf/pmu-events/jevents.py
@@ -599,6 +599,8 @@ const struct pmu_events_map pmu_events_map[] = {
  else:
metric_tblname = 'NULL'
metric_size = '0'
+if event_size == '0' and metric_size == '0':
+  continue
  cpuid = row[0].replace('\\', '')
  _args.output_file.write(f"""{{
  \t.arch = "{arch}",
@@ -888,12 +890,24 @@ def main() -> None:
action: Callable[[Sequence[str], os.DirEntry], None]) -> None:
  """Replicate the directory/file walking behavior of C's file tree walk."""
  for item in os.scandir(path):
+  if _args.model != 'all' and item.is_dir():
+# Check if the model matches one in _args.model.
+if len(parents) == _args.model.split(',')[0].count('/'):
+  # We're testing the correct directory.
+  item_path = '/'.join(parents) + ('/' if len(parents) > 0 else '') + 
item.name
+  if 'test' not in item_path and item_path not in 
_args.model.split(','):
+continue
action(parents, item)
if item.is_dir():
  ftw(item.path, parents + [item.name], action)
  
ap = argparse.ArgumentParser()

ap.add_argument('arch', help='Architecture name like x86')
+  ap.add_argument('model', help='''Select a model such as skylake to
+reduce the code size.  Normally set to "all". For architectures like
+ARM64 with an implementor/model, the model must include the implementor


mega-nit: /s/ARM64/arm64/

it just makes grepping easier (without -i, of course)


+such as "arm/cortex-a34".''',
+  default='all')
ap.add_argument(
'starting_dir',
type=dir_path,




Re: [PATCH v3 1/7] kernel/fork: convert vma assignment to a memcpy

2023-01-26 Thread Mel Gorman
On Wed, Jan 25, 2023 at 05:34:49PM -0800, Andrew Morton wrote:
> On Wed, 25 Jan 2023 16:50:01 -0800 Suren Baghdasaryan  
> wrote:
> 
> > On Wed, Jan 25, 2023 at 4:22 PM Andrew Morton  
> > wrote:
> > >
> > > On Wed, 25 Jan 2023 15:35:48 -0800 Suren Baghdasaryan  
> > > wrote:
> > >
> > > > Convert vma assignment in vm_area_dup() to a memcpy() to prevent 
> > > > compiler
> > > > errors when we add a const modifier to vma->vm_flags.
> > > >
> > > > ...
> > > >
> > > > --- a/kernel/fork.c
> > > > +++ b/kernel/fork.c
> > > > @@ -482,7 +482,7 @@ struct vm_area_struct *vm_area_dup(struct 
> > > > vm_area_struct *orig)
> > > >* orig->shared.rb may be modified concurrently, but the 
> > > > clone
> > > >* will be reinitialized.
> > > >*/
> > > > - *new = data_race(*orig);
> > > > + memcpy(new, orig, sizeof(*new));
> > >
> > > The data_race() removal is unchangelogged?
> > 
> > True. I'll add a note in the changelog about that. Ideally I would
> > like to preserve it but I could not find a way to do that.
> > 
> 
> Perhaps Paul can comment?
> 
> I wonder if KCSAN knows how to detect this race, given that it's now in
> a memcpy.  I assume so.

data_race() is just wrapping an expression around
__kcsan_[en|dis]able_current and ensuring the expression is evaluated once
and returning the correct type. I believe the following should be sufficient.

diff --git a/kernel/fork.c b/kernel/fork.c
index 9f7fe3541897..1b30ee568e02 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -472,7 +472,7 @@ struct vm_area_struct *vm_area_dup(struct vm_area_struct 
*orig)
 * orig->shared.rb may be modified concurrently, but the clone
 * will be reinitialized.
 */
-   *new = data_race(*orig);
+   data_race(memcpy(new, orig, sizeof(*new)));
INIT_LIST_HEAD(>anon_vma_chain);
dup_anon_vma_name(orig, new);
}

I don't see how memcpy could automagically figure out whether the memcpy
is prone to races or not in an arbitrary context.

Assuming using data_race this way is ok then

Acked-by: Mel Gorman 

-- 
Mel Gorman
SUSE Labs


Re: [PATCH 1/2] powerpc/pci: Allow to disable filling deprecated pci-OF-bus-map

2023-01-26 Thread Michael Ellerman
Pali Rohár  writes:
> PING? It is more than 5 months since this patch series is there and it
> still has not received any comment.

There was some related discussion in another thread.

I planned to pick it up last merge window, but it breaks the
pmac32_defconfig build when CONFIG_PPC_PCI_OF_BUS_MAP_FILL=n:

  ld: arch/powerpc/platforms/powermac/feature.o: in function 
`core99_ata100_enable':
  feature.c:(.text+0xcd0): undefined reference to `pci_device_from_OF_node'
  ld: arch/powerpc/platforms/powermac/pci.o: in function `pmac_pci_init':
  pci.c:(.init.text+0x5d4): undefined reference to `pci_device_from_OF_node'
  ld: pci.c:(.init.text+0x660): undefined reference to `pci_device_from_OF_node'

So I dropped it, and haven't had time to work out a fix.

cheers

> On Friday 16 December 2022 19:12:06 Pali Rohár wrote:
>> PING?
>> 
>> On Saturday 26 November 2022 17:23:45 Pali Rohár wrote:
>> > PING?
>> > 
>> > On Tuesday 01 November 2022 23:26:03 Pali Rohár wrote:
>> > > Hello! Gentle reminder...
>> > > 
>> > > On Sunday 09 October 2022 13:25:55 Pali Rohár wrote:
>> > > > Hello! Any comments on this? It would be nice to take these two patches
>> > > > (or at least patch 2) to finally enable 
>> > > > PPC_PCI_BUS_NUM_DOMAIN_DEPENDENT
>> > > > by default where possible.
>> > > > 
>> > > > Per following comment there can be an issue with early powermac so 
>> > > > seems
>> > > > that PPC_PCI_OF_BUS_MAP_FILL still has to be by default enabled (which
>> > > > implies that PPC_PCI_BUS_NUM_DOMAIN_DEPENDENT is disabled) on powermac:
>> > > > https://lore.kernel.org/linuxppc-dev/575f239205e8635add81c9f902b7d9db7beb83ea.ca...@kernel.crashing.org/
>> > > > 
>> > > > On Wednesday 17 August 2022 18:39:26 Pali Rohár wrote:
>> > > > > Creating or filling pci-OF-bus-map property in the device-tree is
>> > > > > deprecated since May 2006 [1]. Allow to disable filling this 
>> > > > > property by
>> > > > > unsetting config option CONFIG_PPC_PCI_OF_BUS_MAP_FILL for remaining 
>> > > > > chrp
>> > > > > and powermac code.
>> > > > > 
>> > > > > Disabling of pci-OF-bus-map property allows to enable new option
>> > > > > CONFIG_PPC_PCI_BUS_NUM_DOMAIN_DEPENDENT also for chrp and powermac.
>> > > > > 
>> > > > > [1] - 
>> > > > > https://lore.kernel.org/linuxppc-dev/1148016268.13249.14.camel@localhost.localdomain/
>> > > > > 
>> > > > > Signed-off-by: Pali Rohár 
>> > > > > ---
>> > > > >  arch/powerpc/Kconfig | 12 +++-
>> > > > >  arch/powerpc/kernel/pci_32.c |  6 ++
>> > > > >  2 files changed, 17 insertions(+), 1 deletion(-)
>> > > > > 
>> > > > > diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
>> > > > > index 5881441f7672..df2696c406ad 100644
>> > > > > --- a/arch/powerpc/Kconfig
>> > > > > +++ b/arch/powerpc/Kconfig
>> > > > > @@ -373,9 +373,19 @@ config PPC_DCR
>> > > > >  depends on PPC_DCR_NATIVE || PPC_DCR_MMIO
>> > > > >  default y
>> > > > >  
>> > > > > +config PPC_PCI_OF_BUS_MAP_FILL
>> > > > > +bool "Fill pci-OF-bus-map property in the device-tree"
>> > > > > +depends on PPC32
>> > > > > +depends on PPC_PMAC || PPC_CHRP
>> > > > > +default y
>> > > > > +help
>> > > > > +  This option creates and fills pci-OF-bus-map property in the
>> > > > > +  device-tree which is deprecated and is needed only for old
>> > > > > +  platforms.
>> > > > > +
>> > > > >  config PPC_PCI_BUS_NUM_DOMAIN_DEPENDENT
>> > > > >  depends on PPC32
>> > > > > -depends on !PPC_PMAC && !PPC_CHRP
>> > > > > +depends on !PPC_PCI_OF_BUS_MAP_FILL
>> > > > >  bool "Assign PCI bus numbers from zero individually for each 
>> > > > > PCI domain"
>> > > > >  help
>> > > > >By default on PPC32 were PCI bus numbers unique across all 
>> > > > > PCI domains.
>> > > > > diff --git a/arch/powerpc/kernel/pci_32.c 
>> > > > > b/arch/powerpc/kernel/pci_32.c
>> > > > > index 433965bf37b4..ffc4e1928c80 100644
>> > > > > --- a/arch/powerpc/kernel/pci_32.c
>> > > > > +++ b/arch/powerpc/kernel/pci_32.c
>> > > > > @@ -64,6 +64,8 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_IBM,
>> > > > > PCI_DEVICE_ID_IBM_CPC710_PCI64, fixu
>> > > > >  
>> > > > >  #if defined(CONFIG_PPC_PMAC) || defined(CONFIG_PPC_CHRP)
>> > > > >  
>> > > > > +#ifdef CONFIG_PPC_PCI_OF_BUS_MAP_FILL
>> > > > > +
>> > > > >  static u8* pci_to_OF_bus_map;
>> > > > >  static int pci_bus_count;
>> > > > >  
>> > > > > @@ -223,6 +225,8 @@ pci_create_OF_bus_map(void)
>> > > > >  }
>> > > > >  #endif
>> > > > >  
>> > > > > +#endif /* CONFIG_PPC_PCI_OF_BUS_MAP_FILL */
>> > > > > +
>> > > > >  #endif /* defined(CONFIG_PPC_PMAC) || defined(CONFIG_PPC_CHRP) */
>> > > > >  
>> > > > >  void pcibios_setup_phb_io_space(struct pci_controller *hose)
>> > > > > @@ -264,6 +268,7 @@ static int __init pcibios_init(void)
>> > > > >  }
>> > > > >  
>> > > > >  #if defined(CONFIG_PPC_PMAC) || defined(CONFIG_PPC_CHRP)
>> > > > > +#ifdef CONFIG_PPC_PCI_OF_BUS_MAP_FILL
>> > > > >  pci_bus_count = next_busno;
>> > > > 

Re: [PATCH v2 05/14] powerpc: Remove linker flag from KBUILD_AFLAGS

2023-01-26 Thread Michael Ellerman
Masahiro Yamada  writes:
> On Thu, Jan 26, 2023 at 11:07 AM Nathan Chancellor  wrote:
>>
>> On Thu, Jan 26, 2023 at 10:29:54AM +0900, Masahiro Yamada wrote:
>> > On Wed, Jan 25, 2023 at 1:11 PM Michael Ellerman  
>> > wrote:
>> > >
>> > > Nathan Chancellor  writes:
>> > > > When clang's -Qunused-arguments is dropped from KBUILD_CPPFLAGS, it
>> > > > points out that KBUILD_AFLAGS contains a linker flag, which will be
>> > > > used:
>> > >
>> > > Should that say "unused" ?
>> >
>> >
>> >
>> > Nathan, shall I fix it up locally?
>> > (it will change the commit hash, though.)
>>
>> Yes please, if you would not mind. Sorry about that and thank you for
>> spotting it Michael!
>>
>> Since you have to rebase to fix it, you can include Michael's acks?
>>
>> Cheers,
>> Nathan
>
> Done.

Thanks.

cheers


Re: [PATCH v2 5/6] mm: introduce mod_vm_flags_nolock and use it in untrack_pfn

2023-01-26 Thread Mike Rapoport
On Wed, Jan 25, 2023 at 12:38:50AM -0800, Suren Baghdasaryan wrote:
> In cases when VMA flags are modified after VMA was isolated and mmap_lock
> was downgraded, flags modifications would result in an assertion because
> mmap write lock is not held.
> Introduce mod_vm_flags_nolock to be used in such situation.

vm_flags_mod_nolock?

> Pass a hint to untrack_pfn to conditionally use mod_vm_flags_nolock for
> flags modification and to avoid assertion.
> 
> Signed-off-by: Suren Baghdasaryan 
> ---
>  arch/x86/mm/pat/memtype.c | 10 +++---
>  include/linux/mm.h| 12 +---
>  include/linux/pgtable.h   |  5 +++--
>  mm/memory.c   | 13 +++--
>  mm/memremap.c |  4 ++--
>  mm/mmap.c | 16 ++--
>  6 files changed, 38 insertions(+), 22 deletions(-)
> 
> diff --git a/arch/x86/mm/pat/memtype.c b/arch/x86/mm/pat/memtype.c
> index ae9645c900fa..d8adc0b42cf2 100644
> --- a/arch/x86/mm/pat/memtype.c
> +++ b/arch/x86/mm/pat/memtype.c
> @@ -1046,7 +1046,7 @@ void track_pfn_insert(struct vm_area_struct *vma, 
> pgprot_t *prot, pfn_t pfn)
>   * can be for the entire vma (in which case pfn, size are zero).
>   */
>  void untrack_pfn(struct vm_area_struct *vma, unsigned long pfn,
> -  unsigned long size)
> +  unsigned long size, bool mm_wr_locked)
>  {
>   resource_size_t paddr;
>   unsigned long prot;
> @@ -1065,8 +1065,12 @@ void untrack_pfn(struct vm_area_struct *vma, unsigned 
> long pfn,
>   size = vma->vm_end - vma->vm_start;
>   }
>   free_pfn_range(paddr, size);
> - if (vma)
> - clear_vm_flags(vma, VM_PAT);
> + if (vma) {
> + if (mm_wr_locked)
> + clear_vm_flags(vma, VM_PAT);
> + else
> + mod_vm_flags_nolock(vma, 0, VM_PAT);
> + }
>  }
>  
>  /*
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 55335edd1373..48d49930c411 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -656,12 +656,18 @@ static inline void clear_vm_flags(struct vm_area_struct 
> *vma,
>   vma->vm_flags &= ~flags;
>  }
>  
> +static inline void mod_vm_flags_nolock(struct vm_area_struct *vma,
> +unsigned long set, unsigned long clear)
> +{
> + vma->vm_flags |= set;
> + vma->vm_flags &= ~clear;
> +}
> +
>  static inline void mod_vm_flags(struct vm_area_struct *vma,
>   unsigned long set, unsigned long clear)
>  {
>   mmap_assert_write_locked(vma->vm_mm);
> - vma->vm_flags |= set;
> - vma->vm_flags &= ~clear;
> + mod_vm_flags_nolock(vma, set, clear);
>  }
>  
>  static inline void vma_set_anonymous(struct vm_area_struct *vma)
> @@ -2087,7 +2093,7 @@ static inline void zap_vma_pages(struct vm_area_struct 
> *vma)
>  }
>  void unmap_vmas(struct mmu_gather *tlb, struct maple_tree *mt,
>   struct vm_area_struct *start_vma, unsigned long start,
> - unsigned long end);
> + unsigned long end, bool mm_wr_locked);
>  
>  struct mmu_notifier_range;
>  
> diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
> index 5fd45454c073..c63cd44777ec 100644
> --- a/include/linux/pgtable.h
> +++ b/include/linux/pgtable.h
> @@ -1185,7 +1185,8 @@ static inline int track_pfn_copy(struct vm_area_struct 
> *vma)
>   * can be for the entire vma (in which case pfn, size are zero).
>   */
>  static inline void untrack_pfn(struct vm_area_struct *vma,
> -unsigned long pfn, unsigned long size)
> +unsigned long pfn, unsigned long size,
> +bool mm_wr_locked)
>  {
>  }
>  
> @@ -1203,7 +1204,7 @@ extern void track_pfn_insert(struct vm_area_struct 
> *vma, pgprot_t *prot,
>pfn_t pfn);
>  extern int track_pfn_copy(struct vm_area_struct *vma);
>  extern void untrack_pfn(struct vm_area_struct *vma, unsigned long pfn,
> - unsigned long size);
> + unsigned long size, bool mm_wr_locked);
>  extern void untrack_pfn_moved(struct vm_area_struct *vma);
>  #endif
>  
> diff --git a/mm/memory.c b/mm/memory.c
> index d6902065e558..5b11b50e2c4a 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -1613,7 +1613,7 @@ void unmap_page_range(struct mmu_gather *tlb,
>  static void unmap_single_vma(struct mmu_gather *tlb,
>   struct vm_area_struct *vma, unsigned long start_addr,
>   unsigned long end_addr,
> - struct zap_details *details)
> + struct zap_details *details, bool mm_wr_locked)
>  {
>   unsigned long start = max(vma->vm_start, start_addr);
>   unsigned long end;
> @@ -1628,7 +1628,7 @@ static void unmap_single_vma(struct mmu_gather *tlb,
>   uprobe_munmap(vma, start, end);
>  
>   if (unlikely(vma->vm_flags & VM_PFNMAP))
> - untrack_pfn(vma, 0, 0);
> + untrack_pfn(vma, 0, 0, 

Re: [PATCH v2 4/6] mm: replace vma->vm_flags indirect modification in ksm_madvise

2023-01-26 Thread Mike Rapoport
On Wed, Jan 25, 2023 at 12:38:49AM -0800, Suren Baghdasaryan wrote:
> Replace indirect modifications to vma->vm_flags with calls to modifier
> functions to be able to track flag changes and to keep vma locking
> correctness. Add a BUG_ON check in ksm_madvise() to catch indirect
> vm_flags modification attempts.
> 
> Signed-off-by: Suren Baghdasaryan 

Acked-by: Mike Rapoport (IBM) 

> ---
>  arch/powerpc/kvm/book3s_hv_uvmem.c | 5 -
>  arch/s390/mm/gmap.c| 5 -
>  mm/khugepaged.c| 2 ++
>  mm/ksm.c   | 2 ++
>  4 files changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/powerpc/kvm/book3s_hv_uvmem.c 
> b/arch/powerpc/kvm/book3s_hv_uvmem.c
> index 1d67baa5557a..325a7a47d348 100644
> --- a/arch/powerpc/kvm/book3s_hv_uvmem.c
> +++ b/arch/powerpc/kvm/book3s_hv_uvmem.c
> @@ -393,6 +393,7 @@ static int kvmppc_memslot_page_merge(struct kvm *kvm,
>  {
>   unsigned long gfn = memslot->base_gfn;
>   unsigned long end, start = gfn_to_hva(kvm, gfn);
> + unsigned long vm_flags;
>   int ret = 0;
>   struct vm_area_struct *vma;
>   int merge_flag = (merge) ? MADV_MERGEABLE : MADV_UNMERGEABLE;
> @@ -409,12 +410,14 @@ static int kvmppc_memslot_page_merge(struct kvm *kvm,
>   ret = H_STATE;
>   break;
>   }
> + vm_flags = vma->vm_flags;
>   ret = ksm_madvise(vma, vma->vm_start, vma->vm_end,
> -   merge_flag, >vm_flags);
> +   merge_flag, _flags);
>   if (ret) {
>   ret = H_STATE;
>   break;
>   }
> + reset_vm_flags(vma, vm_flags);
>   start = vma->vm_end;
>   } while (end > vma->vm_end);
>  
> diff --git a/arch/s390/mm/gmap.c b/arch/s390/mm/gmap.c
> index 3a695b8a1e3c..d5eb47dcdacb 100644
> --- a/arch/s390/mm/gmap.c
> +++ b/arch/s390/mm/gmap.c
> @@ -2587,14 +2587,17 @@ int gmap_mark_unmergeable(void)
>  {
>   struct mm_struct *mm = current->mm;
>   struct vm_area_struct *vma;
> + unsigned long vm_flags;
>   int ret;
>   VMA_ITERATOR(vmi, mm, 0);
>  
>   for_each_vma(vmi, vma) {
> + vm_flags = vma->vm_flags;
>   ret = ksm_madvise(vma, vma->vm_start, vma->vm_end,
> -   MADV_UNMERGEABLE, >vm_flags);
> +   MADV_UNMERGEABLE, _flags);
>   if (ret)
>   return ret;
> + reset_vm_flags(vma, vm_flags);
>   }
>   mm->def_flags &= ~VM_MERGEABLE;
>   return 0;
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index 8abc59345bf2..76b24cd0c179 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -354,6 +354,8 @@ struct attribute_group khugepaged_attr_group = {
>  int hugepage_madvise(struct vm_area_struct *vma,
>unsigned long *vm_flags, int advice)
>  {
> + /* vma->vm_flags can be changed only using modifier functions */
> + BUG_ON(vm_flags == >vm_flags);
>   switch (advice) {
>   case MADV_HUGEPAGE:
>  #ifdef CONFIG_S390
> diff --git a/mm/ksm.c b/mm/ksm.c
> index 04f1c8c2df11..992b2be9f5e6 100644
> --- a/mm/ksm.c
> +++ b/mm/ksm.c
> @@ -2573,6 +2573,8 @@ int ksm_madvise(struct vm_area_struct *vma, unsigned 
> long start,
>   struct mm_struct *mm = vma->vm_mm;
>   int err;
>  
> + /* vma->vm_flags can be changed only using modifier functions */
> + BUG_ON(vm_flags == >vm_flags);
>   switch (advice) {
>   case MADV_MERGEABLE:
>   /*
> -- 
> 2.39.1
> 
> 


Re: [PATCH v2 3/6] mm: replace vma->vm_flags direct modifications with modifier calls

2023-01-26 Thread Mike Rapoport
On Wed, Jan 25, 2023 at 12:38:48AM -0800, Suren Baghdasaryan wrote:
> Replace direct modifications to vma->vm_flags with calls to modifier
> functions to be able to track flag changes and to keep vma locking
> correctness.
> 
> Signed-off-by: Suren Baghdasaryan 

Acked-by: Mike Rapoport (IBM) 

> ---
>  arch/arm/kernel/process.c  |  2 +-
>  arch/ia64/mm/init.c|  8 
>  arch/loongarch/include/asm/tlb.h   |  2 +-
>  arch/powerpc/kvm/book3s_xive_native.c  |  2 +-
>  arch/powerpc/mm/book3s64/subpage_prot.c|  2 +-
>  arch/powerpc/platforms/book3s/vas-api.c|  2 +-
>  arch/powerpc/platforms/cell/spufs/file.c   | 14 +++---
>  arch/s390/mm/gmap.c|  3 +--
>  arch/x86/entry/vsyscall/vsyscall_64.c  |  2 +-
>  arch/x86/kernel/cpu/sgx/driver.c   |  2 +-
>  arch/x86/kernel/cpu/sgx/virt.c |  2 +-
>  arch/x86/mm/pat/memtype.c  |  6 +++---
>  arch/x86/um/mem_32.c   |  2 +-
>  drivers/acpi/pfr_telemetry.c   |  2 +-
>  drivers/android/binder.c   |  3 +--
>  drivers/char/mspec.c   |  2 +-
>  drivers/crypto/hisilicon/qm.c  |  2 +-
>  drivers/dax/device.c   |  2 +-
>  drivers/dma/idxd/cdev.c|  2 +-
>  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c|  2 +-
>  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c   |  4 ++--
>  drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c  |  4 ++--
>  drivers/gpu/drm/amd/amdkfd/kfd_events.c|  4 ++--
>  drivers/gpu/drm/amd/amdkfd/kfd_process.c   |  4 ++--
>  drivers/gpu/drm/drm_gem.c  |  2 +-
>  drivers/gpu/drm/drm_gem_dma_helper.c   |  3 +--
>  drivers/gpu/drm/drm_gem_shmem_helper.c |  2 +-
>  drivers/gpu/drm/drm_vm.c   |  8 
>  drivers/gpu/drm/etnaviv/etnaviv_gem.c  |  2 +-
>  drivers/gpu/drm/exynos/exynos_drm_gem.c|  4 ++--
>  drivers/gpu/drm/gma500/framebuffer.c   |  2 +-
>  drivers/gpu/drm/i810/i810_dma.c|  2 +-
>  drivers/gpu/drm/i915/gem/i915_gem_mman.c   |  4 ++--
>  drivers/gpu/drm/mediatek/mtk_drm_gem.c |  2 +-
>  drivers/gpu/drm/msm/msm_gem.c  |  2 +-
>  drivers/gpu/drm/omapdrm/omap_gem.c |  3 +--
>  drivers/gpu/drm/rockchip/rockchip_drm_gem.c|  3 +--
>  drivers/gpu/drm/tegra/gem.c|  5 ++---
>  drivers/gpu/drm/ttm/ttm_bo_vm.c|  3 +--
>  drivers/gpu/drm/virtio/virtgpu_vram.c  |  2 +-
>  drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c   |  2 +-
>  drivers/gpu/drm/xen/xen_drm_front_gem.c|  3 +--
>  drivers/hsi/clients/cmt_speech.c   |  2 +-
>  drivers/hwtracing/intel_th/msu.c   |  2 +-
>  drivers/hwtracing/stm/core.c   |  2 +-
>  drivers/infiniband/hw/hfi1/file_ops.c  |  4 ++--
>  drivers/infiniband/hw/mlx5/main.c  |  4 ++--
>  drivers/infiniband/hw/qib/qib_file_ops.c   | 13 ++---
>  drivers/infiniband/hw/usnic/usnic_ib_verbs.c   |  2 +-
>  drivers/infiniband/hw/vmw_pvrdma/pvrdma_verbs.c|  2 +-
>  .../media/common/videobuf2/videobuf2-dma-contig.c  |  2 +-
>  drivers/media/common/videobuf2/videobuf2-vmalloc.c |  2 +-
>  drivers/media/v4l2-core/videobuf-dma-contig.c  |  2 +-
>  drivers/media/v4l2-core/videobuf-dma-sg.c  |  4 ++--
>  drivers/media/v4l2-core/videobuf-vmalloc.c |  2 +-
>  drivers/misc/cxl/context.c |  2 +-
>  drivers/misc/habanalabs/common/memory.c|  2 +-
>  drivers/misc/habanalabs/gaudi/gaudi.c  |  4 ++--
>  drivers/misc/habanalabs/gaudi2/gaudi2.c|  8 
>  drivers/misc/habanalabs/goya/goya.c|  4 ++--
>  drivers/misc/ocxl/context.c|  4 ++--
>  drivers/misc/ocxl/sysfs.c  |  2 +-
>  drivers/misc/open-dice.c   |  4 ++--
>  drivers/misc/sgi-gru/grufile.c |  4 ++--
>  drivers/misc/uacce/uacce.c |  2 +-
>  drivers/sbus/char/oradax.c |  2 +-
>  drivers/scsi/cxlflash/ocxl_hw.c|  2 +-
>  drivers/scsi/sg.c  |  2 +-
>  drivers/staging/media/atomisp/pci/hmm/hmm_bo.c |  2 +-
>  drivers/staging/media/deprecated/meye/meye.c   |  4 ++--
>  .../media/deprecated/stkwebcam/stk-webcam.c|  2 +-
>  drivers/target/target_core_user.c  |  2 +-
>  drivers/uio/uio.c  |  2 +-
>  drivers/usb/core/devio.c   |  3 +--
>  

Re: [PATCH v2 2/6] mm: replace VM_LOCKED_CLEAR_MASK with VM_LOCKED_MASK

2023-01-26 Thread Mike Rapoport
On Wed, Jan 25, 2023 at 12:38:47AM -0800, Suren Baghdasaryan wrote:
> To simplify the usage of VM_LOCKED_CLEAR_MASK in clear_vm_flags(),
> replace it with VM_LOCKED_MASK bitmask and convert all users.
> 
> Signed-off-by: Suren Baghdasaryan 

Acked-by: Mike Rapoport (IBM) 

> ---
>  include/linux/mm.h | 4 ++--
>  kernel/fork.c  | 2 +-
>  mm/hugetlb.c   | 4 ++--
>  mm/mlock.c | 6 +++---
>  mm/mmap.c  | 6 +++---
>  mm/mremap.c| 2 +-
>  6 files changed, 12 insertions(+), 12 deletions(-)
> 
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index b71f2809caac..da62bdd627bf 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -421,8 +421,8 @@ extern unsigned int kobjsize(const void *objp);
>  /* This mask defines which mm->def_flags a process can inherit its parent */
>  #define VM_INIT_DEF_MASK VM_NOHUGEPAGE
>  
> -/* This mask is used to clear all the VMA flags used by mlock */
> -#define VM_LOCKED_CLEAR_MASK (~(VM_LOCKED | VM_LOCKONFAULT))
> +/* This mask represents all the VMA flag bits used by mlock */
> +#define VM_LOCKED_MASK   (VM_LOCKED | VM_LOCKONFAULT)
>  
>  /* Arch-specific flags to clear when updating VM flags on protection change 
> */
>  #ifndef VM_ARCH_CLEAR
> diff --git a/kernel/fork.c b/kernel/fork.c
> index 6683c1b0f460..03d472051236 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -669,7 +669,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
>   tmp->anon_vma = NULL;
>   } else if (anon_vma_fork(tmp, mpnt))
>   goto fail_nomem_anon_vma_fork;
> - tmp->vm_flags &= ~(VM_LOCKED | VM_LOCKONFAULT);
> + clear_vm_flags(tmp, VM_LOCKED_MASK);
>   file = tmp->vm_file;
>   if (file) {
>   struct address_space *mapping = file->f_mapping;
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index d20c8b09890e..4ecdbad9a451 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -6973,8 +6973,8 @@ static unsigned long page_table_shareable(struct 
> vm_area_struct *svma,
>   unsigned long s_end = sbase + PUD_SIZE;
>  
>   /* Allow segments to share if only one is marked locked */
> - unsigned long vm_flags = vma->vm_flags & VM_LOCKED_CLEAR_MASK;
> - unsigned long svm_flags = svma->vm_flags & VM_LOCKED_CLEAR_MASK;
> + unsigned long vm_flags = vma->vm_flags & ~VM_LOCKED_MASK;
> + unsigned long svm_flags = svma->vm_flags & ~VM_LOCKED_MASK;
>  
>   /*
>* match the virtual addresses, permission and the alignment of the
> diff --git a/mm/mlock.c b/mm/mlock.c
> index 0336f52e03d7..5c4fff93cd6b 100644
> --- a/mm/mlock.c
> +++ b/mm/mlock.c
> @@ -497,7 +497,7 @@ static int apply_vma_lock_flags(unsigned long start, 
> size_t len,
>   if (vma->vm_start != tmp)
>   return -ENOMEM;
>  
> - newflags = vma->vm_flags & VM_LOCKED_CLEAR_MASK;
> + newflags = vma->vm_flags & ~VM_LOCKED_MASK;
>   newflags |= flags;
>   /* Here we know that  vma->vm_start <= nstart < vma->vm_end. */
>   tmp = vma->vm_end;
> @@ -661,7 +661,7 @@ static int apply_mlockall_flags(int flags)
>   struct vm_area_struct *vma, *prev = NULL;
>   vm_flags_t to_add = 0;
>  
> - current->mm->def_flags &= VM_LOCKED_CLEAR_MASK;
> + current->mm->def_flags &= ~VM_LOCKED_MASK;
>   if (flags & MCL_FUTURE) {
>   current->mm->def_flags |= VM_LOCKED;
>  
> @@ -681,7 +681,7 @@ static int apply_mlockall_flags(int flags)
>   for_each_vma(vmi, vma) {
>   vm_flags_t newflags;
>  
> - newflags = vma->vm_flags & VM_LOCKED_CLEAR_MASK;
> + newflags = vma->vm_flags & ~VM_LOCKED_MASK;
>   newflags |= to_add;
>  
>   /* Ignore errors */
> diff --git a/mm/mmap.c b/mm/mmap.c
> index d4abc6feced1..323bd253b25a 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -2671,7 +2671,7 @@ unsigned long mmap_region(struct file *file, unsigned 
> long addr,
>   if ((vm_flags & VM_SPECIAL) || vma_is_dax(vma) ||
>   is_vm_hugetlb_page(vma) ||
>   vma == get_gate_vma(current->mm))
> - vma->vm_flags &= VM_LOCKED_CLEAR_MASK;
> + clear_vm_flags(vma, VM_LOCKED_MASK);
>   else
>   mm->locked_vm += (len >> PAGE_SHIFT);
>   }
> @@ -3340,8 +3340,8 @@ static struct vm_area_struct *__install_special_mapping(
>   vma->vm_start = addr;
>   vma->vm_end = addr + len;
>  
> - vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
> - vma->vm_flags &= VM_LOCKED_CLEAR_MASK;
> + init_vm_flags(vma, (vm_flags | mm->def_flags |
> +   VM_DONTEXPAND | VM_SOFTDIRTY) & ~VM_LOCKED_MASK);
>   vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
>  
>   vma->vm_ops = ops;
> diff --git a/mm/mremap.c 

Re: [PATCH v2 1/6] mm: introduce vma->vm_flags modifier functions

2023-01-26 Thread Mike Rapoport
On Wed, Jan 25, 2023 at 12:38:46AM -0800, Suren Baghdasaryan wrote:
> vm_flags are among VMA attributes which affect decisions like VMA merging
> and splitting. Therefore all vm_flags modifications are performed after
> taking exclusive mmap_lock to prevent vm_flags updates racing with such
> operations. Introduce modifier functions for vm_flags to be used whenever
> flags are updated. This way we can better check and control correct
> locking behavior during these updates.
> 
> Signed-off-by: Suren Baghdasaryan 
> ---
>  include/linux/mm.h   | 37 +
>  include/linux/mm_types.h |  8 +++-
>  2 files changed, 44 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index c2f62bdce134..b71f2809caac 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -627,6 +627,43 @@ static inline void vma_init(struct vm_area_struct *vma, 
> struct mm_struct *mm)
>   INIT_LIST_HEAD(>anon_vma_chain);
>  }
>  
> +/* Use when VMA is not part of the VMA tree and needs no locking */
> +static inline void init_vm_flags(struct vm_area_struct *vma,
> +  unsigned long flags)

I'd suggest to make it vm_flags_init() etc.
Except that

Acked-by: Mike Rapoport (IBM) 

> +{
> + vma->vm_flags = flags;
> +}
> +
> +/* Use when VMA is part of the VMA tree and modifications need coordination 
> */
> +static inline void reset_vm_flags(struct vm_area_struct *vma,
> +   unsigned long flags)
> +{
> + mmap_assert_write_locked(vma->vm_mm);
> + init_vm_flags(vma, flags);
> +}
> +
> +static inline void set_vm_flags(struct vm_area_struct *vma,
> + unsigned long flags)
> +{
> + mmap_assert_write_locked(vma->vm_mm);
> + vma->vm_flags |= flags;
> +}
> +
> +static inline void clear_vm_flags(struct vm_area_struct *vma,
> +   unsigned long flags)
> +{
> + mmap_assert_write_locked(vma->vm_mm);
> + vma->vm_flags &= ~flags;
> +}
> +
> +static inline void mod_vm_flags(struct vm_area_struct *vma,
> + unsigned long set, unsigned long clear)
> +{
> + mmap_assert_write_locked(vma->vm_mm);
> + vma->vm_flags |= set;
> + vma->vm_flags &= ~clear;
> +}
> +
>  static inline void vma_set_anonymous(struct vm_area_struct *vma)
>  {
>   vma->vm_ops = NULL;
> diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
> index 2d6d790d9bed..6c7c70bf50dd 100644
> --- a/include/linux/mm_types.h
> +++ b/include/linux/mm_types.h
> @@ -491,7 +491,13 @@ struct vm_area_struct {
>* See vmf_insert_mixed_prot() for discussion.
>*/
>   pgprot_t vm_page_prot;
> - unsigned long vm_flags; /* Flags, see mm.h. */
> +
> + /*
> +  * Flags, see mm.h.
> +  * WARNING! Do not modify directly.
> +  * Use {init|reset|set|clear|mod}_vm_flags() functions instead.
> +  */
> + unsigned long vm_flags;
>  
>   /*
>* For areas with an address space and backing store,
> -- 
> 2.39.1
> 
> 


Re: [PATCH v4 04/10] powerpc/8xx: Use a larger CPM1 command check mask

2023-01-26 Thread Michael Ellerman
Herve Codina  writes:
> The CPM1 command mask is defined for use with the standard
> CPM1 command register as described in the user's manual:
>   0  |13|47|8   11|12  14| 15|
>   RST|- |OPCODE|CH_NUM| -|FLG|
>
> In the QMC extension the CPM1 command register is redefined
> (QMC supplement user's manuel) with the following mapping:
>   0  |13|47|8   13|14| 15|
>   RST|QMC OPCODE|  1110|CHANNEL_NUMBER| -|FLG|
>
> Extend the check command mask in order to support both the
> standard CH_NUM field and the QMC extension CHANNEL_NUMBER
> field.
>
> Signed-off-by: Herve Codina 
> Acked-by: Christophe Leroy 
> ---
>  arch/powerpc/platforms/8xx/cpm1.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Acked-by: Michael Ellerman  (powerpc)

cheers

> diff --git a/arch/powerpc/platforms/8xx/cpm1.c 
> b/arch/powerpc/platforms/8xx/cpm1.c
> index 8ef1f4392086..6b828b9f90d9 100644
> --- a/arch/powerpc/platforms/8xx/cpm1.c
> +++ b/arch/powerpc/platforms/8xx/cpm1.c
> @@ -100,7 +100,7 @@ int cpm_command(u32 command, u8 opcode)
>   int i, ret;
>   unsigned long flags;
>  
> - if (command & 0xff0f)
> + if (command & 0xff03)
>   return -EINVAL;
>  
>   spin_lock_irqsave(_lock, flags);
> -- 
> 2.39.0


Re: [PATCH v2 02/10] ARM: dts: ls1021a: add TQ-Systems MBLS102xA device tree

2023-01-26 Thread Shawn Guo
On Fri, Jan 20, 2023 at 02:34:47PM +0100, Alexander Stein wrote:
> Add device tree for the MBLS102xA mainboard with TQMLS1021A SoM.
> 
> Signed-off-by: Alexander Stein 
> ---
> Changes in v2:
> * Remove unnecessary status = "okay"
> * Remove underscore from node names
> * Move reg direct below compatiblefor i2c devices
> * Remove i2c device nodes without software support
>   Add a comment about existance for the device though
> 
>  arch/arm/boot/dts/Makefile|   1 +
>  .../boot/dts/ls1021a-tqmls1021a-mbls1021a.dts | 406 ++
>  arch/arm/boot/dts/ls1021a-tqmls1021a.dtsi |  81 
>  3 files changed, 488 insertions(+)
>  create mode 100644 arch/arm/boot/dts/ls1021a-tqmls1021a-mbls1021a.dts
>  create mode 100644 arch/arm/boot/dts/ls1021a-tqmls1021a.dtsi
> 
> diff --git a/arch/arm/boot/dts/Makefile b/arch/arm/boot/dts/Makefile
> index d0c07867aeabe..44b5ed44b13d6 100644
> --- a/arch/arm/boot/dts/Makefile
> +++ b/arch/arm/boot/dts/Makefile
> @@ -802,6 +802,7 @@ dtb-$(CONFIG_SOC_LS1021A) += \
>   ls1021a-iot.dtb \
>   ls1021a-moxa-uc-8410a.dtb \
>   ls1021a-qds.dtb \
> + ls1021a-tqmls1021a-mbls1021a.dtb \
>   ls1021a-tsn.dtb \
>   ls1021a-twr.dtb
>  dtb-$(CONFIG_SOC_VF610) += \
> diff --git a/arch/arm/boot/dts/ls1021a-tqmls1021a-mbls1021a.dts 
> b/arch/arm/boot/dts/ls1021a-tqmls1021a-mbls1021a.dts
> new file mode 100644
> index 0..aa8b605344655
> --- /dev/null
> +++ b/arch/arm/boot/dts/ls1021a-tqmls1021a-mbls1021a.dts
> @@ -0,0 +1,406 @@
> +// SPDX-License-Identifier: (GPL-2.0-or-later OR X11)
> +/*
> + * Copyright 2013-2014 Freescale Semiconductor, Inc.
> + * Copyright 2018-2023 TQ-Systems GmbH ,
> + * D-82229 Seefeld, Germany.
> + * Author: Alexander Stein
> + */
> +
> +/dts-v1/;
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include "ls1021a-tqmls1021a.dtsi"
> +
> +/ {
> + model = "TQMLS102xA SOM on MBLS102xA";
> + compatible = "tq,ls1021a-tqmls1021a-mbls102xa", 
> "tq,ls1021a-tqmls1021a", "fsl,ls1021a";
> +
> + audio_mclk: audio-clock {
> + compatible = "fixed-clock";
> + #clock-cells = <0>;
> + clock-frequency = <2500>;
> + };
> +
> + backlight_dcu: backlight {
> + compatible = "gpio-backlight";
> + gpios = < 0 GPIO_ACTIVE_LOW>;
> + status = "disabled";
> + };
> +
> + gpio-keys {
> + compatible = "gpio-keys";
> + autorepeat;
> +
> + switch-1 {
> + label = "S6";
> + linux,code = ;
> + gpios = <_0 0 GPIO_ACTIVE_LOW>;
> + };
> +
> + btn2: switch-2 {
> + label = "S7";
> + linux,code = ;
> + gpios = <_0 1 GPIO_ACTIVE_LOW>;
> + };
> +
> + switch-3 {
> + label = "S8";
> + linux,code = ;
> + gpios = <_0 2 GPIO_ACTIVE_LOW>;
> + };
> + };
> +
> + gpio_leds: gpio-leds {
> + compatible = "gpio-leds";
> +
> + led-0 {
> + color = ;
> + function = LED_FUNCTION_STATUS;
> + function-enumerator = <0>;
> + gpios = <_2 4 GPIO_ACTIVE_LOW>;
> + linux,default-trigger = "default-on";
> + };
> +
> + led-1 {
> + color = ;
> + function = LED_FUNCTION_STATUS;
> + function-enumerator = <1>;
> + gpios = <_2 5 GPIO_ACTIVE_LOW>;
> + linux,default-trigger = "default-on";
> + };
> +
> + led-2 {
> + color = ;
> + function = LED_FUNCTION_STATUS;
> + function-enumerator = <2>;
> + gpios = <_2 6 GPIO_ACTIVE_LOW>;
> + linux,default-trigger = "default-on";
> + };
> +
> + led-3 {
> + color = ;
> + function = LED_FUNCTION_HEARTBEAT;
> + function-enumerator = <0>;
> + gpios = <_2 7 GPIO_ACTIVE_LOW>;
> + linux,default-trigger = "heartbeat";
> + };
> + };
> +
> + lvds_encoder: lvds-encoder {
> + compatible = "ti,sn75lvds83", "lvds-encoder";
> + power-supply = <_3p3v>;
> + status = "disabled";
> +
> + ports {
> + #address-cells = <1>;
> + #size-cells = <0>;
> +
> + port@0 {
> + reg = <0>;
> +
> + lvds_encoder_in: endpoint {};
> + };
> +
> + port@1 {
> + reg = <1>;
> +
> + lvds_encoder_out: endpoint {};
> +   

Re: [PATCH v3 6/7] mm: introduce mod_vm_flags_nolock and use it in untrack_pfn

2023-01-26 Thread Michal Hocko
On Wed 25-01-23 15:35:53, Suren Baghdasaryan wrote:
> In cases when VMA flags are modified after VMA was isolated and mmap_lock
> was downgraded, flags modifications would result in an assertion because
> mmap write lock is not held.
> Introduce mod_vm_flags_nolock to be used in such situation, when VMA is
> not part of VMA tree and locking it is not required.
> Pass a hint to untrack_pfn to conditionally use mod_vm_flags_nolock for
> flags modification and to avoid assertion.
> 
> Signed-off-by: Suren Baghdasaryan 

Acked-by: Michal Hocko 
Thanks!

> ---
>  arch/x86/mm/pat/memtype.c | 10 +++---
>  include/linux/mm.h| 16 +---
>  include/linux/pgtable.h   |  5 +++--
>  mm/memory.c   | 13 +++--
>  mm/memremap.c |  4 ++--
>  mm/mmap.c | 16 ++--
>  6 files changed, 42 insertions(+), 22 deletions(-)
> 
> diff --git a/arch/x86/mm/pat/memtype.c b/arch/x86/mm/pat/memtype.c
> index ae9645c900fa..d8adc0b42cf2 100644
> --- a/arch/x86/mm/pat/memtype.c
> +++ b/arch/x86/mm/pat/memtype.c
> @@ -1046,7 +1046,7 @@ void track_pfn_insert(struct vm_area_struct *vma, 
> pgprot_t *prot, pfn_t pfn)
>   * can be for the entire vma (in which case pfn, size are zero).
>   */
>  void untrack_pfn(struct vm_area_struct *vma, unsigned long pfn,
> -  unsigned long size)
> +  unsigned long size, bool mm_wr_locked)
>  {
>   resource_size_t paddr;
>   unsigned long prot;
> @@ -1065,8 +1065,12 @@ void untrack_pfn(struct vm_area_struct *vma, unsigned 
> long pfn,
>   size = vma->vm_end - vma->vm_start;
>   }
>   free_pfn_range(paddr, size);
> - if (vma)
> - clear_vm_flags(vma, VM_PAT);
> + if (vma) {
> + if (mm_wr_locked)
> + clear_vm_flags(vma, VM_PAT);
> + else
> + mod_vm_flags_nolock(vma, 0, VM_PAT);
> + }
>  }
>  
>  /*
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 1ab5f73360f2..86bf043136f3 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -656,12 +656,22 @@ static inline void clear_vm_flags(struct vm_area_struct 
> *vma,
>   ACCESS_PRIVATE(vma, __vm_flags) &= ~flags;
>  }
>  
> +/*
> + * Use only if VMA has been previously isolated, is not part of the VMA tree
> + * and therefore needs no locking.
> + */
> +static inline void mod_vm_flags_nolock(struct vm_area_struct *vma,
> +vm_flags_t set, vm_flags_t clear)
> +{
> + ACCESS_PRIVATE(vma, __vm_flags) |= set;
> + ACCESS_PRIVATE(vma, __vm_flags) &= ~clear;
> +}
> +
>  static inline void mod_vm_flags(struct vm_area_struct *vma,
>   vm_flags_t set, vm_flags_t clear)
>  {
>   mmap_assert_write_locked(vma->vm_mm);
> - ACCESS_PRIVATE(vma, __vm_flags) |= set;
> - ACCESS_PRIVATE(vma, __vm_flags) &= ~clear;
> + mod_vm_flags_nolock(vma, set, clear);
>  }
>  
>  static inline void vma_set_anonymous(struct vm_area_struct *vma)
> @@ -2087,7 +2097,7 @@ static inline void zap_vma_pages(struct vm_area_struct 
> *vma)
>  }
>  void unmap_vmas(struct mmu_gather *tlb, struct maple_tree *mt,
>   struct vm_area_struct *start_vma, unsigned long start,
> - unsigned long end);
> + unsigned long end, bool mm_wr_locked);
>  
>  struct mmu_notifier_range;
>  
> diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
> index 5fd45454c073..c63cd44777ec 100644
> --- a/include/linux/pgtable.h
> +++ b/include/linux/pgtable.h
> @@ -1185,7 +1185,8 @@ static inline int track_pfn_copy(struct vm_area_struct 
> *vma)
>   * can be for the entire vma (in which case pfn, size are zero).
>   */
>  static inline void untrack_pfn(struct vm_area_struct *vma,
> -unsigned long pfn, unsigned long size)
> +unsigned long pfn, unsigned long size,
> +bool mm_wr_locked)
>  {
>  }
>  
> @@ -1203,7 +1204,7 @@ extern void track_pfn_insert(struct vm_area_struct 
> *vma, pgprot_t *prot,
>pfn_t pfn);
>  extern int track_pfn_copy(struct vm_area_struct *vma);
>  extern void untrack_pfn(struct vm_area_struct *vma, unsigned long pfn,
> - unsigned long size);
> + unsigned long size, bool mm_wr_locked);
>  extern void untrack_pfn_moved(struct vm_area_struct *vma);
>  #endif
>  
> diff --git a/mm/memory.c b/mm/memory.c
> index d6902065e558..5b11b50e2c4a 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -1613,7 +1613,7 @@ void unmap_page_range(struct mmu_gather *tlb,
>  static void unmap_single_vma(struct mmu_gather *tlb,
>   struct vm_area_struct *vma, unsigned long start_addr,
>   unsigned long end_addr,
> - struct zap_details *details)
> + struct zap_details *details, bool mm_wr_locked)
>  {
>   unsigned long start = max(vma->vm_start, start_addr);
>   unsigned 

Re: [PATCH v3 2/7] mm: introduce vma->vm_flags wrapper functions

2023-01-26 Thread Michal Hocko
On Wed 25-01-23 15:35:49, Suren Baghdasaryan wrote:
> vm_flags are among VMA attributes which affect decisions like VMA merging
> and splitting. Therefore all vm_flags modifications are performed after
> taking exclusive mmap_lock to prevent vm_flags updates racing with such
> operations. Introduce modifier functions for vm_flags to be used whenever
> flags are updated. This way we can better check and control correct
> locking behavior during these updates.
> 
> Signed-off-by: Suren Baghdasaryan 

with or without the proposed renaming (it seems we are not consistent
on that much even in the core kernel - e.g. init_rwsem vs. mutex_init)

Acked-by: Michal Hocko 

> ---
>  include/linux/mm.h   | 37 +
>  include/linux/mm_types.h | 10 +-
>  2 files changed, 46 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index c2f62bdce134..bf16ddd544a5 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -627,6 +627,43 @@ static inline void vma_init(struct vm_area_struct *vma, 
> struct mm_struct *mm)
>   INIT_LIST_HEAD(>anon_vma_chain);
>  }
>  
> +/* Use when VMA is not part of the VMA tree and needs no locking */
> +static inline void init_vm_flags(struct vm_area_struct *vma,
> +  vm_flags_t flags)
> +{
> + ACCESS_PRIVATE(vma, __vm_flags) = flags;
> +}
> +
> +/* Use when VMA is part of the VMA tree and modifications need coordination 
> */
> +static inline void reset_vm_flags(struct vm_area_struct *vma,
> +   vm_flags_t flags)
> +{
> + mmap_assert_write_locked(vma->vm_mm);
> + init_vm_flags(vma, flags);
> +}
> +
> +static inline void set_vm_flags(struct vm_area_struct *vma,
> + vm_flags_t flags)
> +{
> + mmap_assert_write_locked(vma->vm_mm);
> + ACCESS_PRIVATE(vma, __vm_flags) |= flags;
> +}
> +
> +static inline void clear_vm_flags(struct vm_area_struct *vma,
> +   vm_flags_t flags)
> +{
> + mmap_assert_write_locked(vma->vm_mm);
> + ACCESS_PRIVATE(vma, __vm_flags) &= ~flags;
> +}
> +
> +static inline void mod_vm_flags(struct vm_area_struct *vma,
> + vm_flags_t set, vm_flags_t clear)
> +{
> + mmap_assert_write_locked(vma->vm_mm);
> + ACCESS_PRIVATE(vma, __vm_flags) |= set;
> + ACCESS_PRIVATE(vma, __vm_flags) &= ~clear;
> +}
> +
>  static inline void vma_set_anonymous(struct vm_area_struct *vma)
>  {
>   vma->vm_ops = NULL;
> diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
> index 2d6d790d9bed..bccbd5896850 100644
> --- a/include/linux/mm_types.h
> +++ b/include/linux/mm_types.h
> @@ -491,7 +491,15 @@ struct vm_area_struct {
>* See vmf_insert_mixed_prot() for discussion.
>*/
>   pgprot_t vm_page_prot;
> - unsigned long vm_flags; /* Flags, see mm.h. */
> +
> + /*
> +  * Flags, see mm.h.
> +  * To modify use {init|reset|set|clear|mod}_vm_flags() functions.
> +  */
> + union {
> + const vm_flags_t vm_flags;
> + vm_flags_t __private __vm_flags;
> + };
>  
>   /*
>* For areas with an address space and backing store,
> -- 
> 2.39.1

-- 
Michal Hocko
SUSE Labs


[PATCH v4 10/10] MAINTAINERS: add the Freescale QMC audio entry

2023-01-26 Thread Herve Codina
After contributing the component, add myself as the maintainer
for the Freescale QMC audio ASoC component.

Signed-off-by: Herve Codina 
---
 MAINTAINERS | 8 
 1 file changed, 8 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 9a574892b9b1..9dcfadec5aa3 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8440,6 +8440,14 @@ F:   sound/soc/fsl/fsl*
 F: sound/soc/fsl/imx*
 F: sound/soc/fsl/mpc8610_hpcd.c
 
+FREESCALE SOC SOUND QMC DRIVER
+M: Herve Codina 
+L: alsa-de...@alsa-project.org (moderated for non-subscribers)
+L: linuxppc-dev@lists.ozlabs.org
+S: Maintained
+F: Documentation/devicetree/bindings/sound/fsl,qmc-audio.yaml
+F: sound/soc/fsl/fsl_qmc_audio.c
+
 FREESCALE USB PERIPHERAL DRIVERS
 M: Li Yang 
 L: linux-...@vger.kernel.org
-- 
2.39.0



[PATCH v4 09/10] ASoC: fsl: Add support for QMC audio

2023-01-26 Thread Herve Codina
The QMC audio is an ASoC component which provides DAIs
that use the QMC (QUICC Multichannel Controller) to transfer
the audio data.

It provides as many DAIs as the number of QMC channels it
references.

Signed-off-by: Herve Codina 
---
 sound/soc/fsl/Kconfig |   9 +
 sound/soc/fsl/Makefile|   2 +
 sound/soc/fsl/fsl_qmc_audio.c | 735 ++
 3 files changed, 746 insertions(+)
 create mode 100644 sound/soc/fsl/fsl_qmc_audio.c

diff --git a/sound/soc/fsl/Kconfig b/sound/soc/fsl/Kconfig
index 614eceda6b9e..17db29c25d96 100644
--- a/sound/soc/fsl/Kconfig
+++ b/sound/soc/fsl/Kconfig
@@ -172,6 +172,15 @@ config SND_MPC52xx_DMA
 config SND_SOC_POWERPC_DMA
tristate
 
+config SND_SOC_POWERPC_QMC_AUDIO
+   tristate "QMC ALSA SoC support"
+   depends on CPM_QMC
+   help
+ ALSA SoC Audio support using the Freescale QUICC Multichannel
+ Controller (QMC).
+ Say Y or M if you want to add support for SoC audio using Freescale
+ QMC.
+
 comment "SoC Audio support for Freescale PPC boards:"
 
 config SND_SOC_MPC8610_HPCD
diff --git a/sound/soc/fsl/Makefile b/sound/soc/fsl/Makefile
index b54beb1a66fa..8db7e97d0bd5 100644
--- a/sound/soc/fsl/Makefile
+++ b/sound/soc/fsl/Makefile
@@ -28,6 +28,7 @@ snd-soc-fsl-easrc-objs := fsl_easrc.o
 snd-soc-fsl-xcvr-objs := fsl_xcvr.o
 snd-soc-fsl-aud2htx-objs := fsl_aud2htx.o
 snd-soc-fsl-rpmsg-objs := fsl_rpmsg.o
+snd-soc-fsl-qmc-audio-objs := fsl_qmc_audio.o
 
 obj-$(CONFIG_SND_SOC_FSL_AUDMIX) += snd-soc-fsl-audmix.o
 obj-$(CONFIG_SND_SOC_FSL_ASOC_CARD) += snd-soc-fsl-asoc-card.o
@@ -44,6 +45,7 @@ obj-$(CONFIG_SND_SOC_POWERPC_DMA) += snd-soc-fsl-dma.o
 obj-$(CONFIG_SND_SOC_FSL_XCVR) += snd-soc-fsl-xcvr.o
 obj-$(CONFIG_SND_SOC_FSL_AUD2HTX) += snd-soc-fsl-aud2htx.o
 obj-$(CONFIG_SND_SOC_FSL_RPMSG) += snd-soc-fsl-rpmsg.o
+obj-$(CONFIG_SND_SOC_POWERPC_QMC_AUDIO) += snd-soc-fsl-qmc-audio.o
 
 # MPC5200 Platform Support
 obj-$(CONFIG_SND_MPC52xx_DMA) += mpc5200_dma.o
diff --git a/sound/soc/fsl/fsl_qmc_audio.c b/sound/soc/fsl/fsl_qmc_audio.c
new file mode 100644
index ..7cbb8e4758cc
--- /dev/null
+++ b/sound/soc/fsl/fsl_qmc_audio.c
@@ -0,0 +1,735 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * ALSA SoC using the QUICC Multichannel Controller (QMC)
+ *
+ * Copyright 2022 CS GROUP France
+ *
+ * Author: Herve Codina 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct qmc_dai {
+   char *name;
+   int id;
+   struct device *dev;
+   struct qmc_chan *qmc_chan;
+   unsigned int nb_tx_ts;
+   unsigned int nb_rx_ts;
+};
+
+struct qmc_audio {
+   struct device *dev;
+   unsigned int num_dais;
+   struct qmc_dai *dais;
+   struct snd_soc_dai_driver *dai_drivers;
+};
+
+struct qmc_dai_prtd {
+   struct qmc_dai *qmc_dai;
+   dma_addr_t dma_buffer_start;
+   dma_addr_t period_ptr_submitted;
+   dma_addr_t period_ptr_ended;
+   dma_addr_t dma_buffer_end;
+   size_t period_size;
+   struct snd_pcm_substream *substream;
+};
+
+static int qmc_audio_pcm_construct(struct snd_soc_component *component,
+  struct snd_soc_pcm_runtime *rtd)
+{
+   struct snd_card *card = rtd->card->snd_card;
+   int ret;
+
+   ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
+   if (ret)
+   return ret;
+
+   snd_pcm_set_managed_buffer_all(rtd->pcm, SNDRV_DMA_TYPE_DEV, card->dev,
+  64*1024, 64*1024);
+   return 0;
+}
+
+static int qmc_audio_pcm_hw_params(struct snd_soc_component *component,
+  struct snd_pcm_substream *substream,
+  struct snd_pcm_hw_params *params)
+{
+   struct snd_pcm_runtime *runtime = substream->runtime;
+   struct qmc_dai_prtd *prtd = substream->runtime->private_data;
+
+   prtd->dma_buffer_start = runtime->dma_addr;
+   prtd->dma_buffer_end = runtime->dma_addr + params_buffer_bytes(params);
+   prtd->period_size = params_period_bytes(params);
+   prtd->period_ptr_submitted = prtd->dma_buffer_start;
+   prtd->period_ptr_ended = prtd->dma_buffer_start;
+   prtd->substream = substream;
+
+   return 0;
+}
+
+static void qmc_audio_pcm_write_complete(void *context)
+{
+   struct qmc_dai_prtd *prtd = context;
+   int ret;
+
+   prtd->period_ptr_ended += prtd->period_size;
+   if (prtd->period_ptr_ended >= prtd->dma_buffer_end)
+   prtd->period_ptr_ended = prtd->dma_buffer_start;
+
+   prtd->period_ptr_submitted += prtd->period_size;
+   if (prtd->period_ptr_submitted >= prtd->dma_buffer_end)
+   prtd->period_ptr_submitted = prtd->dma_buffer_start;
+
+   ret = qmc_chan_write_submit(prtd->qmc_dai->qmc_chan,
+   prtd->period_ptr_submitted, prtd->period_size,
+   qmc_audio_pcm_write_complete, 

[PATCH v4 08/10] dt-bindings: sound: Add support for QMC audio

2023-01-26 Thread Herve Codina
The QMC (QUICC mutichannel controller) is a controller
present in some PowerQUICC SoC such as MPC885.
The QMC audio is an ASoC component that uses the QMC
controller to transfer the audio data.

Signed-off-by: Herve Codina 
Reviewed-by: Krzysztof Kozlowski 
---
 .../bindings/sound/fsl,qmc-audio.yaml | 117 ++
 1 file changed, 117 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/fsl,qmc-audio.yaml

diff --git a/Documentation/devicetree/bindings/sound/fsl,qmc-audio.yaml 
b/Documentation/devicetree/bindings/sound/fsl,qmc-audio.yaml
new file mode 100644
index ..ff5cd9241941
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/fsl,qmc-audio.yaml
@@ -0,0 +1,117 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/fsl,qmc-audio.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: QMC audio
+
+maintainers:
+  - Herve Codina 
+
+description: |
+  The QMC audio is an ASoC component which uses QMC (QUICC Multichannel
+  Controller) channels to transfer the audio data.
+  It provides as many DAI as the number of QMC channel used.
+
+allOf:
+  - $ref: dai-common.yaml#
+
+properties:
+  compatible:
+const: fsl,qmc-audio
+
+  '#address-cells':
+const: 1
+  '#size-cells':
+const: 0
+  '#sound-dai-cells':
+const: 1
+
+patternProperties:
+  '^dai@([0-9]|[1-5][0-9]|6[0-3])$':
+description:
+  A DAI managed by this controller
+type: object
+
+properties:
+  reg:
+minimum: 0
+maximum: 63
+description:
+  The DAI number
+
+  fsl,qmc-chan:
+$ref: /schemas/types.yaml#/definitions/phandle-array
+items:
+  - items:
+  - description: phandle to QMC node
+  - description: Channel number
+description:
+  Should be a phandle/number pair. The phandle to QMC node and the QMC
+  channel to use for this DAI.
+
+required:
+  - reg
+  - fsl,qmc-chan
+
+required:
+  - compatible
+  - '#address-cells'
+  - '#size-cells'
+  - '#sound-dai-cells'
+
+additionalProperties: false
+
+examples:
+  - |
+audio_controller: audio-controller {
+compatible = "fsl,qmc-audio";
+#address-cells = <1>;
+#size-cells = <0>;
+#sound-dai-cells = <1>;
+dai@16 {
+reg = <16>;
+fsl,qmc-chan = < 16>;
+};
+dai@17 {
+reg = <17>;
+fsl,qmc-chan = < 17>;
+};
+};
+
+sound {
+compatible = "simple-audio-card";
+#address-cells = <1>;
+#size-cells = <0>;
+simple-audio-card,dai-link@0 {
+reg = <0>;
+format = "dsp_b";
+cpu {
+sound-dai = <_controller 16>;
+};
+codec {
+sound-dai = <>;
+dai-tdm-slot-num = <4>;
+dai-tdm-slot-width = <8>;
+/* TS 3, 5, 7, 9 */
+dai-tdm-slot-tx-mask = <0 0 0 1 0 1 0 1 0 1>;
+dai-tdm-slot-rx-mask = <0 0 0 1 0 1 0 1 0 1>;
+};
+};
+simple-audio-card,dai-link@1 {
+reg = <1>;
+format = "dsp_b";
+cpu {
+sound-dai = <_controller 17>;
+};
+codec {
+sound-dai = <>;
+dai-tdm-slot-num = <4>;
+dai-tdm-slot-width = <8>;
+/* TS 2, 4, 6, 8 */
+dai-tdm-slot-tx-mask = <0 0 1 0 1 0 1 0 1>;
+dai-tdm-slot-rx-mask = <0 0 1 0 1 0 1 0 1>;
+};
+};
+};
-- 
2.39.0



[PATCH v4 07/10] MAINTAINERS: add the Freescale QMC controller entry

2023-01-26 Thread Herve Codina
After contributing the driver, add myself as the maintainer
for the Freescale QMC controller.

Signed-off-by: Herve Codina 
---
 MAINTAINERS | 8 
 1 file changed, 8 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 6a0605ebf8a0..9a574892b9b1 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8372,6 +8372,14 @@ S:   Maintained
 F: drivers/soc/fsl/qe/
 F: include/soc/fsl/qe/
 
+FREESCALE QUICC ENGINE QMC DRIVER
+M: Herve Codina 
+L: linuxppc-dev@lists.ozlabs.org
+S: Maintained
+F: Documentation/devicetree/bindings/soc/fsl/cpm_qe/fsl,qmc.yaml
+F: drivers/soc/fsl/qe/qmc.c
+F: include/soc/fsl/qe/qmc.h
+
 FREESCALE QUICC ENGINE TSA DRIVER
 M: Herve Codina 
 L: linuxppc-dev@lists.ozlabs.org
-- 
2.39.0



[PATCH v4 06/10] soc: fsl: cmp1: Add support for QMC

2023-01-26 Thread Herve Codina
The QMC (QUICC Multichannel Controller) emulates up to 64
channels within one serial controller using the same TDM
physical interface routed from the TSA.

It is available in some PowerQUICC SoC such as the
MPC885 or MPC866.

It is also available on some Quicc Engine SoCs.
This current version support CPM1 SoCs only and some
enhancement are needed to support Quicc Engine SoCs.

Signed-off-by: Herve Codina 
---
 drivers/soc/fsl/qe/Kconfig  |   12 +
 drivers/soc/fsl/qe/Makefile |1 +
 drivers/soc/fsl/qe/qmc.c| 1533 +++
 include/soc/fsl/qe/qmc.h|   71 ++
 4 files changed, 1617 insertions(+)
 create mode 100644 drivers/soc/fsl/qe/qmc.c
 create mode 100644 include/soc/fsl/qe/qmc.h

diff --git a/drivers/soc/fsl/qe/Kconfig b/drivers/soc/fsl/qe/Kconfig
index 60ec11c9f4d9..25b218351ae3 100644
--- a/drivers/soc/fsl/qe/Kconfig
+++ b/drivers/soc/fsl/qe/Kconfig
@@ -44,6 +44,18 @@ config CPM_TSA
  This option enables support for this
  controller
 
+config CPM_QMC
+   tristate "CPM QMC support"
+   depends on OF && HAS_IOMEM
+   depends on CPM1 || (PPC && COMPILE_TEST)
+   depends on CPM_TSA
+   help
+ Freescale CPM QUICC Multichannel Controller
+ (QMC)
+
+ This option enables support for this
+ controller
+
 config QE_TDM
bool
default y if FSL_UCC_HDLC
diff --git a/drivers/soc/fsl/qe/Makefile b/drivers/soc/fsl/qe/Makefile
index 45c961acc81b..ec8506e13113 100644
--- a/drivers/soc/fsl/qe/Makefile
+++ b/drivers/soc/fsl/qe/Makefile
@@ -5,6 +5,7 @@
 obj-$(CONFIG_QUICC_ENGINE)+= qe.o qe_common.o qe_ic.o qe_io.o
 obj-$(CONFIG_CPM)  += qe_common.o
 obj-$(CONFIG_CPM_TSA)  += tsa.o
+obj-$(CONFIG_CPM_QMC)  += qmc.o
 obj-$(CONFIG_UCC)  += ucc.o
 obj-$(CONFIG_UCC_SLOW) += ucc_slow.o
 obj-$(CONFIG_UCC_FAST) += ucc_fast.o
diff --git a/drivers/soc/fsl/qe/qmc.c b/drivers/soc/fsl/qe/qmc.c
new file mode 100644
index ..cfa7207353e0
--- /dev/null
+++ b/drivers/soc/fsl/qe/qmc.c
@@ -0,0 +1,1533 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * QMC driver
+ *
+ * Copyright 2022 CS GROUP France
+ *
+ * Author: Herve Codina 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "tsa.h"
+
+/* SCC general mode register high (32 bits) */
+#define SCC_GSMRL  0x00
+#define SCC_GSMRL_ENR  (1 << 5)
+#define SCC_GSMRL_ENT  (1 << 4)
+#define SCC_GSMRL_MODE_QMC (0x0A << 0)
+
+/* SCC general mode register low (32 bits) */
+#define SCC_GSMRH  0x04
+#define   SCC_GSMRH_CTSS   (1 << 7)
+#define   SCC_GSMRH_CDS(1 << 8)
+#define   SCC_GSMRH_CTSP   (1 << 9)
+#define   SCC_GSMRH_CDP(1 << 10)
+
+/* SCC event register (16 bits) */
+#define SCC_SCCE   0x10
+#define   SCC_SCCE_IQOV(1 << 3)
+#define   SCC_SCCE_GINT(1 << 2)
+#define   SCC_SCCE_GUN (1 << 1)
+#define   SCC_SCCE_GOV (1 << 0)
+
+/* SCC mask register (16 bits) */
+#define SCC_SCCM   0x14
+/* Multichannel base pointer (32 bits) */
+#define QMC_GBL_MCBASE 0x00
+/* Multichannel controller state (16 bits) */
+#define QMC_GBL_QMCSTATE   0x04
+/* Maximum receive buffer length (16 bits) */
+#define QMC_GBL_MRBLR  0x06
+/* Tx time-slot assignment table pointer (16 bits) */
+#define QMC_GBL_TX_S_PTR   0x08
+/* Rx pointer (16 bits) */
+#define QMC_GBL_RXPTR  0x0A
+/* Global receive frame threshold (16 bits) */
+#define QMC_GBL_GRFTHR 0x0C
+/* Global receive frame count (16 bits) */
+#define QMC_GBL_GRFCNT 0x0E
+/* Multichannel interrupt base address (32 bits) */
+#define QMC_GBL_INTBASE0x10
+/* Multichannel interrupt pointer (32 bits) */
+#define QMC_GBL_INTPTR 0x14
+/* Rx time-slot assignment table pointer (16 bits) */
+#define QMC_GBL_RX_S_PTR   0x18
+/* Tx pointer (16 bits) */
+#define QMC_GBL_TXPTR  0x1A
+/* CRC constant (32 bits) */
+#define QMC_GBL_C_MASK32   0x1C
+/* Time slot assignment table Rx (32 x 16 bits) */
+#define QMC_GBL_TSATRX 0x20
+/* Time slot assignment table Tx (32 x 16 bits) */
+#define QMC_GBL_TSATTX 0x60
+/* CRC constant (16 bits) */
+#define QMC_GBL_C_MASK16   0xA0
+
+/* TSA entry (16bit entry in TSATRX and TSATTX) */
+#define QMC_TSA_VALID  (1 << 15)
+#define QMC_TSA_WRAP   (1 << 14)
+#define QMC_TSA_MASK   (0x303F)
+#define QMC_TSA_CHANNEL(x) ((x) << 6)
+
+/* Tx buffer descriptor base address (16 bits, offset from MCBASE) */
+#define QMC_SPE_TBASE  0x00
+
+/* Channel mode register (16 bits) */
+#define QMC_SPE_CHAMR  0x02
+#define   QMC_SPE_CHAMR_MODE_HDLC  (1 << 15)
+#define   QMC_SPE_CHAMR_MODE_TRANSP((0 << 15) | (1 << 13))
+#define   QMC_SPE_CHAMR_ENT(1 << 12)
+#define   QMC_SPE_CHAMR_POL(1 << 8)
+#define   QMC_SPE_CHAMR_HDLC_IDLM  (1 << 13)
+#define   

[PATCH v4 05/10] dt-bindings: soc: fsl: cpm_qe: Add QMC controller

2023-01-26 Thread Herve Codina
Add support for the QMC (QUICC Multichannel Controller)
available in some PowerQUICC SoC such as MPC885 or MPC866.

Signed-off-by: Herve Codina 
---
 .../bindings/soc/fsl/cpm_qe/fsl,qmc.yaml  | 167 ++
 1 file changed, 167 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/soc/fsl/cpm_qe/fsl,qmc.yaml

diff --git a/Documentation/devicetree/bindings/soc/fsl/cpm_qe/fsl,qmc.yaml 
b/Documentation/devicetree/bindings/soc/fsl/cpm_qe/fsl,qmc.yaml
new file mode 100644
index ..9141a8ca183b
--- /dev/null
+++ b/Documentation/devicetree/bindings/soc/fsl/cpm_qe/fsl,qmc.yaml
@@ -0,0 +1,167 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/soc/fsl/cpm_qe/fsl,qmc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: PowerQUICC CPM QUICC Multichannel Controller (QMC)
+
+maintainers:
+  - Herve Codina 
+
+description:
+  The QMC (QUICC Multichannel Controller) emulates up to 64 channels within one
+  serial controller using the same TDM physical interface routed from TSA.
+
+properties:
+  compatible:
+items:
+  - enum:
+  - fsl,mpc885-scc-qmc
+  - fsl,mpc866-scc-qmc
+  - const: fsl,cpm1-scc-qmc
+
+  reg:
+items:
+  - description: SCC (Serial communication controller) register base
+  - description: SCC parameter ram base
+  - description: Dual port ram base
+
+  reg-names:
+items:
+  - const: scc_regs
+  - const: scc_pram
+  - const: dpram
+
+  interrupts:
+maxItems: 1
+description: SCC interrupt line in the CPM interrupt controller
+
+  fsl,tsa-serial:
+$ref: /schemas/types.yaml#/definitions/phandle-array
+items:
+  - items:
+  - description: phandle to TSA node
+  - enum: [1, 2, 3]
+description: |
+  TSA serial interface (dt-bindings/soc/fsl,tsa.h defines these
+  values)
+   - 1: SCC2
+   - 2: SCC3
+   - 3: SCC4
+description:
+  Should be a phandle/number pair. The phandle to TSA node and the TSA
+  serial interface to use.
+
+  '#address-cells':
+const: 1
+
+  '#size-cells':
+const: 0
+
+  '#chan-cells':
+const: 1
+
+patternProperties:
+  '^channel@([0-9]|[1-5][0-9]|6[0-3])$':
+description:
+  A channel managed by this controller
+type: object
+
+properties:
+  reg:
+minimum: 0
+maximum: 63
+description:
+  The channel number
+
+  fsl,operational-mode:
+$ref: /schemas/types.yaml#/definitions/string
+enum: [transparent, hdlc]
+default: transparent
+description: |
+  The channel operational mode
+- hdlc: The channel handles HDLC frames
+- transparent: The channel handles raw data without any processing
+
+  fsl,reverse-data:
+$ref: /schemas/types.yaml#/definitions/flag
+description:
+  The bit order as seen on the channels is reversed,
+  transmitting/receiving the MSB of each octet first.
+  This flag is used only in 'transparent' mode.
+
+  fsl,tx-ts-mask:
+$ref: /schemas/types.yaml#/definitions/uint64
+description:
+  Channel assigned Tx time-slots within the Tx time-slots routed by the
+  TSA to this cell.
+
+  fsl,rx-ts-mask:
+$ref: /schemas/types.yaml#/definitions/uint64
+description:
+  Channel assigned Rx time-slots within the Rx time-slots routed by the
+  TSA to this cell.
+
+required:
+  - reg
+  - fsl,tx-ts-mask
+  - fsl,rx-ts-mask
+
+required:
+  - compatible
+  - reg
+  - reg-names
+  - interrupts
+  - fsl,tsa-serial
+  - '#address-cells'
+  - '#size-cells'
+  - '#chan-cells'
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+
+qmc@a60 {
+compatible = "fsl,mpc885-scc-qmc", "fsl,cpm1-scc-qmc";
+reg = <0xa60 0x20>,
+  <0x3f00 0xc0>,
+  <0x2000 0x1000>;
+reg-names = "scc_regs", "scc_pram", "dpram";
+interrupts = <27>;
+interrupt-parent = <_PIC>;
+
+#address-cells = <1>;
+#size-cells = <0>;
+#chan-cells = <1>;
+
+fsl,tsa-serial = < FSL_CPM_TSA_SCC4>;
+
+channel@16 {
+/* Ch16 : First 4 even TS from all routed from TSA */
+reg = <16>;
+fsl,mode = "transparent";
+fsl,reverse-data;
+fsl,tx-ts-mask = <0x 0x00aa>;
+fsl,rx-ts-mask = <0x 0x00aa>;
+};
+
+channel@17 {
+/* Ch17 : First 4 odd TS from all routed from TSA */
+reg = <17>;
+fsl,mode = "transparent";
+fsl,reverse-data;
+fsl,tx-ts-mask = <0x 0x0055>;
+fsl,rx-ts-mask = <0x 0x0055>;
+};
+
+channel@19 {
+/* Ch19 : 8 TS (TS 8..15) from all routed 

[PATCH v4 04/10] powerpc/8xx: Use a larger CPM1 command check mask

2023-01-26 Thread Herve Codina
The CPM1 command mask is defined for use with the standard
CPM1 command register as described in the user's manual:
  0  |13|47|8   11|12  14| 15|
  RST|- |OPCODE|CH_NUM| -|FLG|

In the QMC extension the CPM1 command register is redefined
(QMC supplement user's manuel) with the following mapping:
  0  |13|47|8   13|14| 15|
  RST|QMC OPCODE|  1110|CHANNEL_NUMBER| -|FLG|

Extend the check command mask in order to support both the
standard CH_NUM field and the QMC extension CHANNEL_NUMBER
field.

Signed-off-by: Herve Codina 
Acked-by: Christophe Leroy 
---
 arch/powerpc/platforms/8xx/cpm1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/platforms/8xx/cpm1.c 
b/arch/powerpc/platforms/8xx/cpm1.c
index 8ef1f4392086..6b828b9f90d9 100644
--- a/arch/powerpc/platforms/8xx/cpm1.c
+++ b/arch/powerpc/platforms/8xx/cpm1.c
@@ -100,7 +100,7 @@ int cpm_command(u32 command, u8 opcode)
int i, ret;
unsigned long flags;
 
-   if (command & 0xff0f)
+   if (command & 0xff03)
return -EINVAL;
 
spin_lock_irqsave(_lock, flags);
-- 
2.39.0



  1   2   >