Re: [PATCH 1/2] drm/bridge: lt8912b: add support for P/N pin swap

2024-04-02 Thread Francesco Dolcini
On Wed, Apr 03, 2024 at 09:32:41AM +0300, Alexandru Ardelean wrote:
> I did it like this, because I don't have a board with the P/N in the

You use this 'P/N' both here and in the binding document, to me this is
just too generic and confusing.

Just use some wording that people familiar with the topic can easily undestand,
the Lontium datasheet uses MIPI RX DP/DN, MIPI DSI DP/DN would also work fine
for me, or at least DP/DN that is the working used on some MIPI documentation.

This comment applies to both the changes in the driver and the binding.

Thanks,
Francesco



Re: [PATCH v3 07/13] drm: Make drivers depends on DRM_DW_HDMI

2024-04-02 Thread Alexander Stein
Hi,

Am Dienstag, 2. April 2024, 17:43:41 CEST schrieb Mark Brown:
> On Wed, Mar 27, 2024 at 11:57:02AM +0100, Maxime Ripard wrote:
> 
> > DRM_DW_HDMI has a number of dependencies that might not be enabled.
> > However, drivers were used to selecting it while not enforcing the
> > DRM_DW_HDMI dependencies.
> > 
> > This could result in Kconfig warnings (and further build breakages) such
> > as:
> > 
> >   Kconfig warnings: (for reference only)
> >  WARNING: unmet direct dependencies detected for DRM_DW_HDMI
> >  Depends on [n]: HAS_IOMEM [=y] && DRM [=m] && DRM_BRIDGE [=y] && 
> > DRM_DISPLAY_HELPER [=n]
> >  Selected by [m]:
> >  - DRM_SUN8I_DW_HDMI [=m] && HAS_IOMEM [=y] && DRM_SUN4I [=m]
> 
> This has landed in -next and appears to be causing breakage for several
> platforms using these devices.  For example I'm seeing the HDMI fail to
> probe on sun50i-a64-pin64-plus with arm64 defconfig, the DT kselftest
> result isn't terribly informative but it can be seen here:
> [snip]
> 
> The change introduces a new dependency on DRM_DW_HDMI to the various
> drivers but I'm not seeing any defconfig updates which turn that option
> anywhere so it's not clear how this is expected to avoid regressing the
> defconfig behaviours unless I'm missing something?

I noticed the same. From what I can tell, several drivers (e.g. imx8mp and
imx6q) now depend on DRM_DW_HDMI without anybody actually selecting it.
This results in a dependency which can not be enabled manually.
Reverting restores a working driver.

Best regards,
Alexander
-- 
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
http://www.tq-group.com/




Re: [PATCH 2/2] drm/panthor: Fix some kerneldoc warnings

2024-04-02 Thread Boris Brezillon
On Tue,  2 Apr 2024 22:54:23 +0100
Liviu Dudau  wrote:

> When compiling with W=1 the build process will flag empty comments,
> misnamed documented variables and incorrect tagging of functions.
> Fix them in one go.
> 
> Fixes: de8548813824 ("drm/panthor: Add the scheduler logical block")
> Cc: Boris Brezillon 
> Cc: Steven Price 
> Signed-off-by: Liviu Dudau 

Reviewed-by: Boris Brezillon 

> ---
>  drivers/gpu/drm/panthor/panthor_sched.c | 8 +++-
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/gpu/drm/panthor/panthor_sched.c 
> b/drivers/gpu/drm/panthor/panthor_sched.c
> index e5a710f190d2a8..a787f2fea33e98 100644
> --- a/drivers/gpu/drm/panthor/panthor_sched.c
> +++ b/drivers/gpu/drm/panthor/panthor_sched.c
> @@ -517,7 +517,7 @@ struct panthor_group {
>   /** @max_compute_cores: Maximum number of shader cores used for compute 
> jobs. */
>   u8 max_compute_cores;
>  
> - /** @max_compute_cores: Maximum number of shader cores used for 
> fragment jobs. */
> + /** @max_fragment_cores: Maximum number of shader cores used for 
> fragment jobs. */
>   u8 max_fragment_cores;
>  
>   /** @max_tiler_cores: Maximum number of tiler cores used for tiler 
> jobs. */
> @@ -993,7 +993,7 @@ cs_slot_prog_locked(struct panthor_device *ptdev, u32 
> csg_id, u32 cs_id)
>  }
>  
>  /**
> - * @cs_slot_reset_locked() - Reset a queue slot
> + * cs_slot_reset_locked() - Reset a queue slot
>   * @ptdev: Device.
>   * @csg_id: Group slot.
>   * @cs_id: Queue slot.
> @@ -1591,7 +1591,7 @@ static void sched_process_idle_event_locked(struct 
> panthor_device *ptdev)
>  }
>  
>  /**
> - * panthor_sched_process_global_irq() - Process the scheduling part of a 
> global IRQ
> + * sched_process_global_irq_locked() - Process the scheduling part of a 
> global IRQ
>   * @ptdev: Device.
>   */
>  static void sched_process_global_irq_locked(struct panthor_device *ptdev)
> @@ -1660,8 +1660,6 @@ static const struct dma_fence_ops 
> panthor_queue_fence_ops = {
>   .get_timeline_name = queue_fence_get_timeline_name,
>  };
>  
> -/**
> - */
>  struct panthor_csg_slots_upd_ctx {
>   u32 update_mask;
>   u32 timedout_mask;



Re: [PATCH 1/2] drm/panthor: Cleanup unused variable 'cookie'

2024-04-02 Thread Boris Brezillon
On Tue,  2 Apr 2024 22:54:22 +0100
Liviu Dudau  wrote:

> Commit 962f88b9c916 ("drm/panthor: Drop the dev_enter/exit() sections in
> _irq_suspend/resume()") removed the code that used the 'cookie' variable
> but left the declaration in place. Remove it.
> 
> Fixes: 962f88b9c916 ("drm/panthor: Drop the dev_enter/exit() sections in 
> _irq_suspend/resume()")
> Cc: Boris Brezillon 
> Cc: Steven Price 
> Signed-off-by: Liviu Dudau 

Reviewed-by: Boris Brezillon 

> ---
>  drivers/gpu/drm/panthor/panthor_device.h | 4 
>  1 file changed, 4 deletions(-)
> 
> diff --git a/drivers/gpu/drm/panthor/panthor_device.h 
> b/drivers/gpu/drm/panthor/panthor_device.h
> index dc3e9c666b5bd4..2fdd671b38fd9b 100644
> --- a/drivers/gpu/drm/panthor/panthor_device.h
> +++ b/drivers/gpu/drm/panthor/panthor_device.h
> @@ -323,8 +323,6 @@ static irqreturn_t panthor_ ## __name ## 
> _irq_threaded_handler(int irq, void *da
>   
> \
>  static inline void panthor_ ## __name ## _irq_suspend(struct panthor_irq 
> *pirq)  \
>  {
> \
> - int cookie; 
> \
> - 
> \
>   pirq->mask = 0; 
> \
>   gpu_write(pirq->ptdev, __reg_prefix ## _INT_MASK, 0);   
> \
>   synchronize_irq(pirq->irq); 
> \
> @@ -333,8 +331,6 @@ static inline void panthor_ ## __name ## 
> _irq_suspend(struct panthor_irq *pirq)
>   
> \
>  static inline void panthor_ ## __name ## _irq_resume(struct panthor_irq 
> *pirq, u32 mask) \
>  {
> \
> - int cookie; 
> \
> - 
> \
>   atomic_set(&pirq->suspended, false);
> \
>   pirq->mask = mask;  
> \
>   gpu_write(pirq->ptdev, __reg_prefix ## _INT_CLEAR, mask);   
> \



Re: [PATCH v1 1/1] drm/mediatek/dp: The register is written with the parsed DTS SSC value.

2024-04-02 Thread Krzysztof Kozlowski
On 03/04/2024 06:05, Liankun Yang wrote:
> [Description]
> Severe screen flickering has been observed on the external display
> when the DP projection function is used with the market expansion dock.
> 

> + if (!strcmp(mode_name, RG_XTP_GLB_TXPLL_SSC_DELTA_RBR)) {
> + regmap_update_bits(dp_phy->regs, ssc_reg_offset,
> +XTP_GLB_TXPLL_SSC_DELTA_RBR_DEFAULT, read_value);
> + } else if (!strcmp(mode_name, RG_XTP_GLB_TXPLL_SSC_DELTA_HBR)) {
> + read_value = read_value << 16 | 0x;
> + regmap_update_bits(dp_phy->regs, ssc_reg_offset,
> +XTP_GLB_TXPLL_SSC_DELTA_HBR_DEFAULT, read_value);
> + }
> +
> + return 0;
> +}
> +
> +static struct device_node *mtk_dp_get_ssc_node(struct phy *phy, struct 
> mtk_dp_phy *dp_phy)
> +{
> + struct device_node *mode_node = NULL;
> +
> + mode_node = of_find_node_by_name(dp_phy->dev->of_node, SSC_SETTING);

?!?!
You have the node, why do you try to find it?



Best regards,
Krzysztof



Re: [PATCH 1/2] drm/bridge: lt8912b: add support for P/N pin swap

2024-04-02 Thread Alexandru Ardelean
On Tue, Apr 2, 2024 at 7:53 PM Francesco Dolcini  wrote:
>
> Hello Alexandru, thanks for your patch.
>
> On Tue, Apr 02, 2024 at 01:59:24PM +0300, Alexandru Ardelean wrote:
> > On some HW designs, it's easier for the layout if the P/N pins are swapped.
> > In those cases, we need to adjust (for this) by configuring the MIPI analog
> > registers differently. Specifically, register 0x3e needs to be 0xf6
> > (instead of 0xd6).
> >
> > This change adds a 'lontium,pn-swap' device-tree property to configure the
> > MIPI analog registers for P/N swap.
> >
> > Signed-off-by: Alexandru Ardelean 
> > ---
> >  drivers/gpu/drm/bridge/lontium-lt8912b.c | 25 +---
> >  1 file changed, 22 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/bridge/lontium-lt8912b.c 
> > b/drivers/gpu/drm/bridge/lontium-lt8912b.c
> > index 4b2ae27f0a57f..154126bb922b4 100644
> > --- a/drivers/gpu/drm/bridge/lontium-lt8912b.c
> > +++ b/drivers/gpu/drm/bridge/lontium-lt8912b.c
> > @@ -47,6 +47,7 @@ struct lt8912 {
> >
> >   u8 data_lanes;
> >   bool is_power_on;
> > + bool do_pn_swap;
> >  };
> >
> >  static int lt8912_write_init_config(struct lt8912 *lt)
> > @@ -78,15 +79,31 @@ static int lt8912_write_init_config(struct lt8912 *lt)
> >   {0x55, 0x44},
> >   {0x57, 0x01},
> >   {0x5a, 0x02},
> > -
> > - /*MIPI Analog*/
> > + };
> > + const struct reg_sequence mipi_analog_seq[] = {
> >   {0x3e, 0xd6},
> >   {0x3f, 0xd4},
> >   {0x41, 0x3c},
> >   {0xB2, 0x00},
> >   };
> > + const struct reg_sequence mipi_analog_pn_swap_seq[] = {
> > + {0x3e, 0xf6},
> > + {0x3f, 0xd4},
> > + {0x41, 0x3c},
> > + {0xB2, 0x00},
> > + };
> > + int ret;
> >
> > - return regmap_multi_reg_write(lt->regmap[I2C_MAIN], seq, 
> > ARRAY_SIZE(seq));
> > + ret = regmap_multi_reg_write(lt->regmap[I2C_MAIN], seq, 
> > ARRAY_SIZE(seq));
> > + if (ret < 0)
> > + return ret;
> > +
> > + if (!lt->do_pn_swap)
> > + return regmap_multi_reg_write(lt->regmap[I2C_MAIN], 
> > mipi_analog_seq,
> > +   ARRAY_SIZE(mipi_analog_seq));
> > +
> > + return regmap_multi_reg_write(lt->regmap[I2C_MAIN], 
> > mipi_analog_pn_swap_seq,
> > +   ARRAY_SIZE(mipi_analog_pn_swap_seq));
>
> Can you just remove {0x3e, 0xd6} from the register/value array and write
> it afterward depending on `do_pn_swap` value? Or keep it with the
> current value and only overwrite it when do_pn_swap is true?
>
> If you do it this way is a 4 line change.

Hmm, good point.
I did it like this, because I don't have a board with the P/N in the
0xd6 configuration, to test.
But, if I leave it like this, and just overwrite 0x3e when
`do_pn_swap` is true, I can test that; and I don't need to test the
original case.

I'm actually not 100% sure here if the order of registers (being
written) matters for the initialization.


>
>
> >  static int lt8912_write_mipi_basic_config(struct lt8912 *lt)
> > @@ -702,6 +719,8 @@ static int lt8912_parse_dt(struct lt8912 *lt)
> >   }
> >   lt->gp_reset = gp_reset;
> >
> > + lt->do_pn_swap = device_property_read_bool(dev, "lontium,pn-swap");
>
> I would call this variable the same that is called in the lontium
> documentation, mipirx_diff_swap

Oh.
I actually based this change on a reference software for the LT8912B.
I didn't get a chance to see/find a documentation for the registers.
I compared with the Linux driver, to see what was missing to get
output on the HDMI display (for our setup).

>
> Francesco
>


[drm-misc:for-linux-next 3/4] drivers/gpu/drm/panthor/panthor_fw.c:979:1: error: unused variable 'cookie'

2024-04-02 Thread kernel test robot
tree:   git://anongit.freedesktop.org/drm/drm-misc for-linux-next
head:   10021ef27310279c850cf6cb38542c443a995e92
commit: 962f88b9c91647f3ff4a0d3709662641baed5164 [3/4] drm/panthor: Drop the 
dev_enter/exit() sections in _irq_suspend/resume()
config: riscv-allyesconfig 
(https://download.01.org/0day-ci/archive/20240403/202404031446.7mpki5dv-...@intel.com/config)
compiler: clang version 19.0.0git (https://github.com/llvm/llvm-project 
546dc2245ffc4cccd0b05b58b7a5955e355a3b27)
reproduce (this is a W=1 build): 
(https://download.01.org/0day-ci/archive/20240403/202404031446.7mpki5dv-...@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot 
| Closes: 
https://lore.kernel.org/oe-kbuild-all/202404031446.7mpki5dv-...@intel.com/

All errors (new ones prefixed by >>):

   In file included from drivers/gpu/drm/panthor/panthor_fw.c:9:
   In file included from include/linux/dma-mapping.h:11:
   In file included from include/linux/scatterlist.h:8:
   In file included from include/linux/mm.h:2188:
   include/linux/vmstat.h:508:43: error: arithmetic between different 
enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') 
[-Werror,-Wenum-enum-conversion]
 508 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
 |~ ^
 509 |item];
 |
   include/linux/vmstat.h:515:43: error: arithmetic between different 
enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') 
[-Werror,-Wenum-enum-conversion]
 515 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
 |~ ^
 516 |NR_VM_NUMA_EVENT_ITEMS +
 |~~
   include/linux/vmstat.h:522:36: error: arithmetic between different 
enumeration types ('enum node_stat_item' and 'enum lru_list') 
[-Werror,-Wenum-enum-conversion]
 522 | return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
 |   ~~~ ^ ~~~
   include/linux/vmstat.h:527:43: error: arithmetic between different 
enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') 
[-Werror,-Wenum-enum-conversion]
 527 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
 |~ ^
 528 |NR_VM_NUMA_EVENT_ITEMS +
 |~~
   include/linux/vmstat.h:536:43: error: arithmetic between different 
enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') 
[-Werror,-Wenum-enum-conversion]
 536 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
 |~ ^
 537 |NR_VM_NUMA_EVENT_ITEMS +
 |~~
>> drivers/gpu/drm/panthor/panthor_fw.c:979:1: error: unused variable 'cookie' 
>> [-Werror,-Wunused-variable]
 979 | PANTHOR_IRQ_HANDLER(job, JOB, panthor_job_irq_handler);
 | ^~
   drivers/gpu/drm/panthor/panthor_device.h:326:6: note: expanded from macro 
'PANTHOR_IRQ_HANDLER'
 326 | int cookie;  
   \
 | ^~
>> drivers/gpu/drm/panthor/panthor_fw.c:979:1: error: unused variable 'cookie' 
>> [-Werror,-Wunused-variable]
 979 | PANTHOR_IRQ_HANDLER(job, JOB, panthor_job_irq_handler);
 | ^~
   drivers/gpu/drm/panthor/panthor_device.h:336:6: note: expanded from macro 
'PANTHOR_IRQ_HANDLER'
 336 | int cookie;  
   \
 | ^~
   7 errors generated.
--
   In file included from drivers/gpu/drm/panthor/panthor_gpu.c:9:
   In file included from include/linux/dma-mapping.h:11:
   In file included from include/linux/scatterlist.h:8:
   In file included from include/linux/mm.h:2188:
   include/linux/vmstat.h:508:43: error: arithmetic between different 
enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') 
[-Werror,-Wenum-enum-conversion]
 508 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
 |~ ^
 509 |item];
 |
   include/linux/vmstat.h:515:43: error: arithmetic between different 
enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') 
[-Werror,-Wenum-enum-conversion]
 515 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
 |~ ^
 516 |

Re: [PATCH 2/2] dt-bindings: display: bridge: lt8912b: document 'lontium,pn-swap' property

2024-04-02 Thread Alexandru Ardelean
On Tue, Apr 2, 2024 at 9:06 PM Conor Dooley  wrote:
>
> On Tue, Apr 02, 2024 at 01:59:25PM +0300, Alexandru Ardelean wrote:
> > On some HW designs, it's easier for the layout if the P/N pins are swapped.
> > The driver currently has a DT property to do that.
>
> "currently", because 1/2 adds it. bindings patches should precede the
> driver patches in the series, so please swap the patches and remove this
> portion of the description.

ack;
i'll invert the order and remove this;

>
> >
> > This change documents the 'lontium,pn-swap' property.
> >
> > Signed-off-by: Alexandru Ardelean 
> > ---
> >  .../devicetree/bindings/display/bridge/lontium,lt8912b.yaml | 6 ++
> >  1 file changed, 6 insertions(+)
> >
> > diff --git 
> > a/Documentation/devicetree/bindings/display/bridge/lontium,lt8912b.yaml 
> > b/Documentation/devicetree/bindings/display/bridge/lontium,lt8912b.yaml
> > index 2cef252157985..3a804926b288a 100644
> > --- a/Documentation/devicetree/bindings/display/bridge/lontium,lt8912b.yaml
> > +++ b/Documentation/devicetree/bindings/display/bridge/lontium,lt8912b.yaml
> > @@ -24,6 +24,12 @@ properties:
> >  maxItems: 1
> >  description: GPIO connected to active high RESET pin.
> >
> > +  lontium,pn-swap:
> > +description: Swap the polarities of the P/N pins in software.
> > +  On some HW designs, the layout is simplified if the P/N pins
> > +  are inverted.
>
> Please explain what configuration of a board would cause these to be
> swapped, rather than why someone might want to configure the board this
> way. I've got no idea what this hardware is actually doing, so this is
> being pulled out of a hat, but I'd expect something like "Some boards
> swap the polarity of the P/N pins, use this property to indicate this to
> software".

ack
if it's fine with you, i'll use your suggested description;

for a broader context, we were using a DSI-HDMI converter [1] from
SomLabs on a different (than SomLabs) board;
and we were not seeing anything on the HDMI-connected display;
as I understand it, some DSI-HDMI bridges support P/N auto-inversion;
this one doesn't AFAICT;
on this DSI-HDMI converter [1], we've noticed that the P/N pins were
inverted from the DSI to the chip (vs what we expected to see)
after changing the register value (for the P/N swap), it worked;
our conclusion was that, the design of the converter (board) was done
as-such, because it made the layout easier

[1] 
https://wiki.somlabs.com/index.php/SL-MIPI-LVDS-HDMI-CNV-11_Datasheet_and_Pinout

>
> > +type: boolean
>
> The type here should be flag.

ack; i'll change the type

>
> Cheers,
> Conor.
>
> > +
> >ports:
> >  $ref: /schemas/graph.yaml#/properties/ports
> >
> > --
> > 2.44.0
> >


[PATCH v4 3/4] drm/mipi-dsi: add mipi_dsi_compression_mode_ext()

2024-04-02 Thread Dmitry Baryshkov
Add the extended version of mipi_dsi_compression_mode(). It provides
a way to specify the algorithm and PPS selector.

Signed-off-by: Dmitry Baryshkov 
---
 drivers/gpu/drm/drm_mipi_dsi.c | 41 ++---
 include/drm/drm_mipi_dsi.h |  9 +
 2 files changed, 43 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c
index 9874ff6d4718..795001bb7ff1 100644
--- a/drivers/gpu/drm/drm_mipi_dsi.c
+++ b/drivers/gpu/drm/drm_mipi_dsi.c
@@ -645,29 +645,56 @@ int mipi_dsi_set_maximum_return_packet_size(struct 
mipi_dsi_device *dsi,
 EXPORT_SYMBOL(mipi_dsi_set_maximum_return_packet_size);
 
 /**
- * mipi_dsi_compression_mode() - enable/disable DSC on the peripheral
+ * mipi_dsi_compression_mode_ext() - enable/disable DSC on the peripheral
  * @dsi: DSI peripheral device
  * @enable: Whether to enable or disable the DSC
+ * @algo: Selected compression algorithm
+ * @pps_selector: Select PPS from the table of pre-stored or uploaded PPS 
entries
  *
- * Enable or disable Display Stream Compression on the peripheral using the
- * default Picture Parameter Set and VESA DSC 1.1 algorithm.
+ * Enable or disable Display Stream Compression on the peripheral.
  *
  * Return: 0 on success or a negative error code on failure.
  */
-int mipi_dsi_compression_mode(struct mipi_dsi_device *dsi, bool enable)
+int mipi_dsi_compression_mode_ext(struct mipi_dsi_device *dsi, bool enable,
+ enum mipi_dsi_compression_algo algo,
+ unsigned int pps_selector)
 {
-   /* Note: Needs updating for non-default PPS or algorithm */
-   u8 tx[2] = { enable << 0, 0 };
+   u8 tx[2] = { };
struct mipi_dsi_msg msg = {
.channel = dsi->channel,
.type = MIPI_DSI_COMPRESSION_MODE,
.tx_len = sizeof(tx),
.tx_buf = tx,
};
-   int ret = mipi_dsi_device_transfer(dsi, &msg);
+   int ret;
+
+   if (algo > 3 || pps_selector > 3)
+   return -EINVAL;
+
+   tx[0] = (enable << 0) |
+   (algo << 1) |
+   (pps_selector << 4);
+
+   ret = mipi_dsi_device_transfer(dsi, &msg);
 
return (ret < 0) ? ret : 0;
 }
+EXPORT_SYMBOL(mipi_dsi_compression_mode_ext);
+
+/**
+ * mipi_dsi_compression_mode() - enable/disable DSC on the peripheral
+ * @dsi: DSI peripheral device
+ * @enable: Whether to enable or disable the DSC
+ *
+ * Enable or disable Display Stream Compression on the peripheral using the
+ * default Picture Parameter Set and VESA DSC 1.1 algorithm.
+ *
+ * Return: 0 on success or a negative error code on failure.
+ */
+int mipi_dsi_compression_mode(struct mipi_dsi_device *dsi, bool enable)
+{
+   return mipi_dsi_compression_mode_ext(dsi, enable, 
MIPI_DSI_COMPRESSION_DSC, 0);
+}
 EXPORT_SYMBOL(mipi_dsi_compression_mode);
 
 /**
diff --git a/include/drm/drm_mipi_dsi.h b/include/drm/drm_mipi_dsi.h
index 3011d33eccbd..82b1cc434ea3 100644
--- a/include/drm/drm_mipi_dsi.h
+++ b/include/drm/drm_mipi_dsi.h
@@ -226,6 +226,12 @@ static inline int mipi_dsi_pixel_format_to_bpp(enum 
mipi_dsi_pixel_format fmt)
return -EINVAL;
 }
 
+enum mipi_dsi_compression_algo {
+   MIPI_DSI_COMPRESSION_DSC = 0,
+   MIPI_DSI_COMPRESSION_VENDOR = 3,
+   /* other two values are reserved, DSI 1.3 */
+};
+
 struct mipi_dsi_device *
 mipi_dsi_device_register_full(struct mipi_dsi_host *host,
  const struct mipi_dsi_device_info *info);
@@ -242,6 +248,9 @@ int mipi_dsi_turn_on_peripheral(struct mipi_dsi_device 
*dsi);
 int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi,
u16 value);
 int mipi_dsi_compression_mode(struct mipi_dsi_device *dsi, bool enable);
+int mipi_dsi_compression_mode_ext(struct mipi_dsi_device *dsi, bool enable,
+ enum mipi_dsi_compression_algo algo,
+ unsigned int pps_selector);
 int mipi_dsi_picture_parameter_set(struct mipi_dsi_device *dsi,
   const struct drm_dsc_picture_parameter_set 
*pps);
 

-- 
2.39.2



[PATCH v4 4/4] drm: panel: Add LG sw43408 panel driver

2024-04-02 Thread Dmitry Baryshkov
From: Sumit Semwal 

LG SW43408 is 1080x2160, 4-lane MIPI-DSI panel, used in some Pixel3
phones.

Signed-off-by: Sumit Semwal 
[vinod: Add DSC support]
Signed-off-by: Vinod Koul 
[caleb: cleanup and support turning off the panel]
Signed-off-by: Caleb Connolly 
[DB: partially rewrote the driver and fixed DSC programming]
Reviewed-by: Marijn Suijten 
Signed-off-by: Dmitry Baryshkov 
---
 MAINTAINERS  |   8 +
 drivers/gpu/drm/panel/Kconfig|  11 ++
 drivers/gpu/drm/panel/Makefile   |   1 +
 drivers/gpu/drm/panel/panel-lg-sw43408.c | 323 +++
 4 files changed, 343 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index d36c19c1bf81..4cc43c16e07e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -6789,6 +6789,14 @@ S:   Maintained
 F: Documentation/devicetree/bindings/display/panel/jadard,jd9365da-h3.yaml
 F: drivers/gpu/drm/panel/panel-jadard-jd9365da-h3.c
 
+DRM DRIVER FOR LG SW43408 PANELS
+M: Sumit Semwal 
+M: Caleb Connolly 
+S: Maintained
+T: git git://anongit.freedesktop.org/drm/drm-misc
+F: Documentation/devicetree/bindings/display/panel/lg,sw43408.yaml
+F: drivers/gpu/drm/panel/panel-lg-sw43408.c
+
 DRM DRIVER FOR LOGICVC DISPLAY CONTROLLER
 M: Paul Kocialkowski 
 S: Supported
diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig
index 6dc451f58a3e..a55e9437c8cf 100644
--- a/drivers/gpu/drm/panel/Kconfig
+++ b/drivers/gpu/drm/panel/Kconfig
@@ -335,6 +335,17 @@ config DRM_PANEL_LG_LG4573
  Say Y here if you want to enable support for LG4573 RGB panel.
  To compile this driver as a module, choose M here.
 
+config DRM_PANEL_LG_SW43408
+   tristate "LG SW43408 panel"
+   depends on OF
+   depends on DRM_MIPI_DSI
+   depends on BACKLIGHT_CLASS_DEVICE
+   help
+ Say Y here if you want to enable support for LG sw43408 panel.
+ The panel has a 1080x2160 resolution and uses
+ 24 bit RGB per pixel. It provides a MIPI DSI interface to
+ the host and has a built-in LED backlight.
+
 config DRM_PANEL_MAGNACHIP_D53E6EA8966
tristate "Magnachip D53E6EA8966 DSI panel"
depends on OF && SPI
diff --git a/drivers/gpu/drm/panel/Makefile b/drivers/gpu/drm/panel/Makefile
index 24a02655d726..0b40b010e8e7 100644
--- a/drivers/gpu/drm/panel/Makefile
+++ b/drivers/gpu/drm/panel/Makefile
@@ -34,6 +34,7 @@ obj-$(CONFIG_DRM_PANEL_LEADTEK_LTK050H3146W) += 
panel-leadtek-ltk050h3146w.o
 obj-$(CONFIG_DRM_PANEL_LEADTEK_LTK500HD1829) += panel-leadtek-ltk500hd1829.o
 obj-$(CONFIG_DRM_PANEL_LG_LB035Q02) += panel-lg-lb035q02.o
 obj-$(CONFIG_DRM_PANEL_LG_LG4573) += panel-lg-lg4573.o
+obj-$(CONFIG_DRM_PANEL_LG_SW43408) += panel-lg-sw43408.o
 obj-$(CONFIG_DRM_PANEL_MAGNACHIP_D53E6EA8966) += panel-magnachip-d53e6ea8966.o
 obj-$(CONFIG_DRM_PANEL_NEC_NL8048HL11) += panel-nec-nl8048hl11.o
 obj-$(CONFIG_DRM_PANEL_NEWVISION_NV3051D) += panel-newvision-nv3051d.o
diff --git a/drivers/gpu/drm/panel/panel-lg-sw43408.c 
b/drivers/gpu/drm/panel/panel-lg-sw43408.c
new file mode 100644
index ..6fcdaa5cf6c5
--- /dev/null
+++ b/drivers/gpu/drm/panel/panel-lg-sw43408.c
@@ -0,0 +1,323 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2019-2024 Linaro Ltd
+ * Author: Sumit Semwal 
+ *  Dmitry Baryshkov 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define NUM_SUPPLIES 2
+
+struct sw43408_panel {
+   struct drm_panel base;
+   struct mipi_dsi_device *link;
+
+   struct regulator_bulk_data supplies[NUM_SUPPLIES];
+
+   struct gpio_desc *reset_gpio;
+
+   struct drm_dsc_config dsc;
+};
+
+static inline struct sw43408_panel *to_panel_info(struct drm_panel *panel)
+{
+   return container_of(panel, struct sw43408_panel, base);
+}
+
+static int sw43408_unprepare(struct drm_panel *panel)
+{
+   struct sw43408_panel *ctx = to_panel_info(panel);
+   int ret;
+
+   ret = mipi_dsi_dcs_set_display_off(ctx->link);
+   if (ret < 0)
+   dev_err(panel->dev, "set_display_off cmd failed ret = %d\n", 
ret);
+
+   ret = mipi_dsi_dcs_enter_sleep_mode(ctx->link);
+   if (ret < 0)
+   dev_err(panel->dev, "enter_sleep cmd failed ret = %d\n", ret);
+
+   msleep(100);
+
+   gpiod_set_value(ctx->reset_gpio, 1);
+
+   return regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+}
+
+static int sw43408_program(struct drm_panel *panel)
+{
+   struct sw43408_panel *ctx = to_panel_info(panel);
+   struct drm_dsc_picture_parameter_set pps;
+
+   mipi_dsi_dcs_write_seq(ctx->link, MIPI_DCS_SET_GAMMA_CURVE, 0x02);
+
+   mipi_dsi_dcs_set_tear_on(ctx->link, MIPI_DSI_DCS_TEAR_MODE_VBLANK);
+
+   mipi_dsi_dcs_write_seq(ctx->link, 0x53, 0x0c, 0x30);
+   mipi_dsi_dcs_write_seq(ctx->link, 0x55, 0x00, 0x70, 0xdf, 0x00, 0x70, 
0xdf);
+  

[PATCH v4 2/4] drm/mipi-dsi: use correct return type for the DSC functions

2024-04-02 Thread Dmitry Baryshkov
The functions mipi_dsi_compression_mode() and
mipi_dsi_picture_parameter_set() return 0-or-error rather than a buffer
size. Follow example of other similar MIPI DSI functions and use int
return type instead of size_t.

Fixes: f4dea1aaa9a1 ("drm/dsi: add helpers for DSI compression mode and PPS 
packets")
Reviewed-by: Marijn Suijten 
Signed-off-by: Dmitry Baryshkov 
---
 drivers/gpu/drm/drm_mipi_dsi.c | 6 +++---
 include/drm/drm_mipi_dsi.h | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c
index ef6e416522f8..9874ff6d4718 100644
--- a/drivers/gpu/drm/drm_mipi_dsi.c
+++ b/drivers/gpu/drm/drm_mipi_dsi.c
@@ -654,7 +654,7 @@ EXPORT_SYMBOL(mipi_dsi_set_maximum_return_packet_size);
  *
  * Return: 0 on success or a negative error code on failure.
  */
-ssize_t mipi_dsi_compression_mode(struct mipi_dsi_device *dsi, bool enable)
+int mipi_dsi_compression_mode(struct mipi_dsi_device *dsi, bool enable)
 {
/* Note: Needs updating for non-default PPS or algorithm */
u8 tx[2] = { enable << 0, 0 };
@@ -679,8 +679,8 @@ EXPORT_SYMBOL(mipi_dsi_compression_mode);
  *
  * Return: 0 on success or a negative error code on failure.
  */
-ssize_t mipi_dsi_picture_parameter_set(struct mipi_dsi_device *dsi,
-  const struct 
drm_dsc_picture_parameter_set *pps)
+int mipi_dsi_picture_parameter_set(struct mipi_dsi_device *dsi,
+  const struct drm_dsc_picture_parameter_set 
*pps)
 {
struct mipi_dsi_msg msg = {
.channel = dsi->channel,
diff --git a/include/drm/drm_mipi_dsi.h b/include/drm/drm_mipi_dsi.h
index c0aec0d4d664..3011d33eccbd 100644
--- a/include/drm/drm_mipi_dsi.h
+++ b/include/drm/drm_mipi_dsi.h
@@ -241,9 +241,9 @@ int mipi_dsi_shutdown_peripheral(struct mipi_dsi_device 
*dsi);
 int mipi_dsi_turn_on_peripheral(struct mipi_dsi_device *dsi);
 int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi,
u16 value);
-ssize_t mipi_dsi_compression_mode(struct mipi_dsi_device *dsi, bool enable);
-ssize_t mipi_dsi_picture_parameter_set(struct mipi_dsi_device *dsi,
-  const struct 
drm_dsc_picture_parameter_set *pps);
+int mipi_dsi_compression_mode(struct mipi_dsi_device *dsi, bool enable);
+int mipi_dsi_picture_parameter_set(struct mipi_dsi_device *dsi,
+  const struct drm_dsc_picture_parameter_set 
*pps);
 
 ssize_t mipi_dsi_generic_write(struct mipi_dsi_device *dsi, const void 
*payload,
   size_t size);

-- 
2.39.2



[PATCH v4 0/4] drm/panel: add support for LG SW43408 panel

2024-04-02 Thread Dmitry Baryshkov
The LG SW43408 panel is used on Google Pixel3 devices. For a long time
we could not submit the driver, as the panel was not coming up from the
reset. The panel seems to be picky about some of the delays during init
and it also uses non-standard payload for MIPI_DSI_COMPRESSION_MODE.

Signed-off-by: Dmitry Baryshkov 
---
Changes in v4:
- Fix order of mipi_dsi_compression_mode_ext() args (Marijn)
- Expanded kerneldoc coments for this function (Marijn)
- And added arguments validation (Marijn)
- In the panel driver send the COMPRESSION_MODE in LPM mode like it was
  done originally
- Expanded the .clock maths to show the reason behind the value (Marijn)
- Moved the mode out of the match data (Marijn)
- Link to v3: 
https://lore.kernel.org/r/20240402-lg-sw43408-panel-v3-0-144f17a11...@linaro.org

Changes in v3:
- Fixed return type of MIPI DSC functions
- Replaced mipi_dsi_compression_mode_raw() with
  mipi_dsi_compression_mode_ext() (Marijn)
- Link to v2: 
https://lore.kernel.org/r/20240330-lg-sw43408-panel-v2-0-293a58717...@linaro.org

Changes in v2:
- Removed formatting char from schema (Krzysztof)
- Moved additionalProperties after required (Krzysztof)
- Added example to the schema (Krzysztof)
- Removed obsolete comment in the commit message (Marijn)
- Moved DSC params to the panel struct (Marijn)
- Changed dsc_en to be an array (Marijn)
- Added comment regiarding slice_width and slice_count (Marijn)
- Link to v1: 
https://lore.kernel.org/r/20240330-lg-sw43408-panel-v1-0-f5580fc9f...@linaro.org

---
Dmitry Baryshkov (2):
  drm/mipi-dsi: use correct return type for the DSC functions
  drm/mipi-dsi: add mipi_dsi_compression_mode_ext()

Sumit Semwal (2):
  dt-bindings: panel: Add LG SW43408 MIPI-DSI panel
  drm: panel: Add LG sw43408 panel driver

 .../bindings/display/panel/lg,sw43408.yaml |  62 
 MAINTAINERS|   8 +
 drivers/gpu/drm/drm_mipi_dsi.c |  45 ++-
 drivers/gpu/drm/panel/Kconfig  |  11 +
 drivers/gpu/drm/panel/Makefile |   1 +
 drivers/gpu/drm/panel/panel-lg-sw43408.c   | 323 +
 include/drm/drm_mipi_dsi.h |  15 +-
 7 files changed, 453 insertions(+), 12 deletions(-)
---
base-commit: a6bd6c997f5a0e2667d4d82fef8c970108f2
change-id: 20240330-lg-sw43408-panel-b552f411c53e

Best regards,
-- 
Dmitry Baryshkov 



[PATCH v4 1/4] dt-bindings: panel: Add LG SW43408 MIPI-DSI panel

2024-04-02 Thread Dmitry Baryshkov
From: Sumit Semwal 

LG SW43408 is 1080x2160, 4-lane MIPI-DSI panel present on Google Pixel 3
phones.

Signed-off-by: Vinod Koul 
Signed-off-by: Sumit Semwal 
[caleb: convert to yaml]
Signed-off-by: Caleb Connolly 
Reviewed-by: Krzysztof Kozlowski 
Signed-off-by: Dmitry Baryshkov 
---
 .../bindings/display/panel/lg,sw43408.yaml | 62 ++
 1 file changed, 62 insertions(+)

diff --git a/Documentation/devicetree/bindings/display/panel/lg,sw43408.yaml 
b/Documentation/devicetree/bindings/display/panel/lg,sw43408.yaml
new file mode 100644
index ..1e08648f5bc7
--- /dev/null
+++ b/Documentation/devicetree/bindings/display/panel/lg,sw43408.yaml
@@ -0,0 +1,62 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/display/panel/lg,sw43408.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: LG SW43408 1080x2160 DSI panel
+
+maintainers:
+  - Caleb Connolly 
+
+description:
+  This panel is used on the Pixel 3, it is a 60hz OLED panel which
+  required DSC (Display Stream Compression) and has rounded corners.
+
+allOf:
+  - $ref: panel-common.yaml#
+
+properties:
+  compatible:
+items:
+  - const: lg,sw43408
+
+  reg: true
+  port: true
+  vddi-supply: true
+  vpnl-supply: true
+  reset-gpios: true
+
+required:
+  - compatible
+  - vddi-supply
+  - vpnl-supply
+  - reset-gpios
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+
+dsi {
+#address-cells = <1>;
+#size-cells = <0>;
+
+panel@0 {
+compatible = "lg,sw43408";
+reg = <0>;
+
+vddi-supply = <&vreg_l14a_1p88>;
+vpnl-supply = <&vreg_l28a_3p0>;
+
+reset-gpios = <&tlmm 6 GPIO_ACTIVE_LOW>;
+
+port {
+endpoint {
+remote-endpoint = <&mdss_dsi0_out>;
+};
+};
+};
+};
+...

-- 
2.39.2



Re: [PATCH v3 4/4] drm: panel: Add LG sw43408 panel driver

2024-04-02 Thread Dmitry Baryshkov
On Tue, Apr 02, 2024 at 11:17:52PM +0200, Marijn Suijten wrote:
> On 2024-04-02 02:51:15, Dmitry Baryshkov wrote:
> > From: Sumit Semwal 
> > 
> > LG SW43408 is 1080x2160, 4-lane MIPI-DSI panel, used in some Pixel3
> > phones.
> 
> @60Hz?

With the current settings and timings I'm only getting 30 Hz. I have to
double the mode->clock to get 60.

> 
> > 
> > Signed-off-by: Sumit Semwal 
> > [vinod: Add DSC support]
> > Signed-off-by: Vinod Koul 
> > [caleb: cleanup and support turning off the panel]
> > Signed-off-by: Caleb Connolly 
> > [DB: partially rewrote the driver and fixed DSC programming]
> > Signed-off-by: Dmitry Baryshkov 
> 
> Some small nits but I think this deserves a:
> 
> Reviewed-by: Marijn Suijten 
> 
> > ---
> >  MAINTAINERS  |   8 +
> >  drivers/gpu/drm/panel/Kconfig|  11 ++
> >  drivers/gpu/drm/panel/Makefile   |   1 +
> >  drivers/gpu/drm/panel/panel-lg-sw43408.c | 326 
> > +++
> >  4 files changed, 346 insertions(+)
> > 
> > diff --git a/MAINTAINERS b/MAINTAINERS
> > index d36c19c1bf81..4cc43c16e07e 100644
> > --- a/MAINTAINERS
> > +++ b/MAINTAINERS
> > @@ -6789,6 +6789,14 @@ S:   Maintained
> >  F: Documentation/devicetree/bindings/display/panel/jadard,jd9365da-h3.yaml
> >  F: drivers/gpu/drm/panel/panel-jadard-jd9365da-h3.c
> >  
> > +DRM DRIVER FOR LG SW43408 PANELS
> > +M: Sumit Semwal 
> > +M: Caleb Connolly 
> > +S: Maintained
> > +T: git git://anongit.freedesktop.org/drm/drm-misc
> > +F: Documentation/devicetree/bindings/display/panel/lg,sw43408.yaml
> > +F: drivers/gpu/drm/panel/panel-lg-sw43408.c
> > +
> >  DRM DRIVER FOR LOGICVC DISPLAY CONTROLLER
> >  M: Paul Kocialkowski 
> >  S: Supported
> > diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig
> > index 6dc451f58a3e..a55e9437c8cf 100644
> > --- a/drivers/gpu/drm/panel/Kconfig
> > +++ b/drivers/gpu/drm/panel/Kconfig
> > @@ -335,6 +335,17 @@ config DRM_PANEL_LG_LG4573
> >   Say Y here if you want to enable support for LG4573 RGB panel.
> >   To compile this driver as a module, choose M here.
> >  
> > +config DRM_PANEL_LG_SW43408
> > +   tristate "LG SW43408 panel"
> > +   depends on OF
> > +   depends on DRM_MIPI_DSI
> > +   depends on BACKLIGHT_CLASS_DEVICE
> > +   help
> > + Say Y here if you want to enable support for LG sw43408 panel.
> > + The panel has a 1080x2160 resolution and uses
> > + 24 bit RGB per pixel. It provides a MIPI DSI interface to
> > + the host and has a built-in LED backlight.
> > +
> >  config DRM_PANEL_MAGNACHIP_D53E6EA8966
> > tristate "Magnachip D53E6EA8966 DSI panel"
> > depends on OF && SPI
> > diff --git a/drivers/gpu/drm/panel/Makefile b/drivers/gpu/drm/panel/Makefile
> > index 24a02655d726..0b40b010e8e7 100644
> > --- a/drivers/gpu/drm/panel/Makefile
> > +++ b/drivers/gpu/drm/panel/Makefile
> > @@ -34,6 +34,7 @@ obj-$(CONFIG_DRM_PANEL_LEADTEK_LTK050H3146W) += 
> > panel-leadtek-ltk050h3146w.o
> >  obj-$(CONFIG_DRM_PANEL_LEADTEK_LTK500HD1829) += 
> > panel-leadtek-ltk500hd1829.o
> >  obj-$(CONFIG_DRM_PANEL_LG_LB035Q02) += panel-lg-lb035q02.o
> >  obj-$(CONFIG_DRM_PANEL_LG_LG4573) += panel-lg-lg4573.o
> > +obj-$(CONFIG_DRM_PANEL_LG_SW43408) += panel-lg-sw43408.o
> >  obj-$(CONFIG_DRM_PANEL_MAGNACHIP_D53E6EA8966) += 
> > panel-magnachip-d53e6ea8966.o
> >  obj-$(CONFIG_DRM_PANEL_NEC_NL8048HL11) += panel-nec-nl8048hl11.o
> >  obj-$(CONFIG_DRM_PANEL_NEWVISION_NV3051D) += panel-newvision-nv3051d.o
> > diff --git a/drivers/gpu/drm/panel/panel-lg-sw43408.c 
> > b/drivers/gpu/drm/panel/panel-lg-sw43408.c
> > new file mode 100644
> > index ..c7611bfa796b
> > --- /dev/null
> > +++ b/drivers/gpu/drm/panel/panel-lg-sw43408.c
> > @@ -0,0 +1,326 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * Copyright (C) 2019-2024 Linaro Ltd
> > + * Author: Sumit Semwal 
> > + *  Dmitry Baryshkov 
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include 
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#define NUM_SUPPLIES 2
> > +
> > +struct sw43408_panel {
> > +   struct drm_panel base;
> > +   struct mipi_dsi_device *link;
> > +
> > +   const struct drm_display_mode *mode;
> > +
> > +   struct regulator_bulk_data supplies[NUM_SUPPLIES];
> > +
> > +   struct gpio_desc *reset_gpio;
> > +
> > +   struct drm_dsc_config dsc;
> > +};
> > +
> > +static inline struct sw43408_panel *to_panel_info(struct drm_panel *panel)
> > +{
> > +   return container_of(panel, struct sw43408_panel, base);
> > +}
> > +
> > +static int sw43408_unprepare(struct drm_panel *panel)
> > +{
> > +   struct sw43408_panel *ctx = to_panel_info(panel);
> > +   int ret;
> > +
> > +   ret = mipi_dsi_dcs_set_display_off(ctx->link);
> > +   if (ret < 0)
> > +   dev_err(panel->dev, "set_display_off cmd failed ret = %d\n", 
> > ret);
> > +
> > +   ret = mipi_dsi_dcs_enter_sleep_mode(ctx->lin

Re: [PATCH v3 3/4] drm/mipi-dsi: add mipi_dsi_compression_mode_ext()

2024-04-02 Thread Dmitry Baryshkov
On Tue, Apr 02, 2024 at 11:09:29PM +0200, Marijn Suijten wrote:
> On 2024-04-02 02:51:14, Dmitry Baryshkov wrote:
> > Add the extended version of mipi_dsi_compression_mode(). It provides
> > a way to specify the algorithm and PPS selector.
> > 
> > Signed-off-by: Dmitry Baryshkov 
> > ---
> >  drivers/gpu/drm/drm_mipi_dsi.c | 33 +++--
> >  include/drm/drm_mipi_dsi.h |  9 +
> >  2 files changed, 36 insertions(+), 6 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c
> > index 9874ff6d4718..0ecbc811eb7a 100644
> > --- a/drivers/gpu/drm/drm_mipi_dsi.c
> > +++ b/drivers/gpu/drm/drm_mipi_dsi.c
> > @@ -645,19 +645,24 @@ int mipi_dsi_set_maximum_return_packet_size(struct 
> > mipi_dsi_device *dsi,
> >  EXPORT_SYMBOL(mipi_dsi_set_maximum_return_packet_size);
> >  
> >  /**
> > - * mipi_dsi_compression_mode() - enable/disable DSC on the peripheral
> > + * mipi_dsi_compression_mode_ext() - enable/disable DSC on the peripheral
> >   * @dsi: DSI peripheral device
> >   * @enable: Whether to enable or disable the DSC
> > + * @algo: Selected algorithm
> > + * @pps_selector: The PPS selector
> 
> Not a big fan of paraphrasing the parameter name, it adds no value.  How about
> describing what this parameter means and what it does?:
> 
>   PPS table index to use.  Corresponds to a table pre-programmed on the 
> peripheral
>   or a table programmed with 
> &drm_dsc_picture_parameter_set.pps_identifier.
> 
> (That should be a valid kernel-doc cross-reference to the field)

I don't think such meaning is defined in the standard. In the end, the
pps_identifier is 8-bit wide, while this field has just 2 bits and 4
possible values. The standards are pretty vague about this field. 

> 
> >   *
> > - * Enable or disable Display Stream Compression on the peripheral using the
> > - * default Picture Parameter Set and VESA DSC 1.1 algorithm.
> > + * Enable or disable Display Stream Compression on the peripheral.
> >   *
> >   * Return: 0 on success or a negative error code on failure.
> >   */
> > -int mipi_dsi_compression_mode(struct mipi_dsi_device *dsi, bool enable)
> > +int mipi_dsi_compression_mode_ext(struct mipi_dsi_device *dsi, bool enable,
> > + enum mipi_dsi_compression_algo algo,
> > + unsigned int pps_selector)
> >  {
> > -   /* Note: Needs updating for non-default PPS or algorithm */
> > -   u8 tx[2] = { enable << 0, 0 };
> > +   u8 data = (enable << 0) |
> > +   (algo << 1) |
> > +   (pps_selector << 4);
> 
> Do we need some size validation (if > 3 return -EINVAL)?  FIELD_PREP() might 
> be
> too heavy though.

Ack, let's add it.

> 
> > +   u8 tx[2] = { data, 0 };
> > struct mipi_dsi_msg msg = {
> > .channel = dsi->channel,
> > .type = MIPI_DSI_COMPRESSION_MODE,
> > @@ -668,6 +673,22 @@ int mipi_dsi_compression_mode(struct mipi_dsi_device 
> > *dsi, bool enable)
> >  
> > return (ret < 0) ? ret : 0;
> >  }
> > +EXPORT_SYMBOL(mipi_dsi_compression_mode_ext);
> > +
> > +/**
> > + * mipi_dsi_compression_mode() - enable/disable DSC on the peripheral
> > + * @dsi: DSI peripheral device
> > + * @enable: Whether to enable or disable the DSC
> > + *
> > + * Enable or disable Display Stream Compression on the peripheral using the
> > + * default Picture Parameter Set and VESA DSC 1.1 algorithm.
> > + *
> > + * Return: 0 on success or a negative error code on failure.
> > + */
> > +int mipi_dsi_compression_mode(struct mipi_dsi_device *dsi, bool enable)
> > +{
> > +   return mipi_dsi_compression_mode_ext(dsi, enable, 0, 
> > MIPI_DSI_COMPRESSION_DSC);
> 
> I hope the compiler complains here that it should be 
> MIPI_DSI_COMPRESSION_DSC,0

Nope, it didn't. Both are integers.

> 
> (Enum algo first, int pps_selector last)
> 
> > +}
> >  EXPORT_SYMBOL(mipi_dsi_compression_mode);
> >  
> >  /**
> > diff --git a/include/drm/drm_mipi_dsi.h b/include/drm/drm_mipi_dsi.h
> > index 3011d33eccbd..78cb7b688b1d 100644
> > --- a/include/drm/drm_mipi_dsi.h
> > +++ b/include/drm/drm_mipi_dsi.h
> > @@ -226,6 +226,12 @@ static inline int mipi_dsi_pixel_format_to_bpp(enum 
> > mipi_dsi_pixel_format fmt)
> > return -EINVAL;
> >  }
> >  
> > +enum mipi_dsi_compression_algo {
> > +   MIPI_DSI_COMPRESSION_DSC = 0,
> 
> Add 1.1?  Or does it also allow 1.2 (when the version is also set via PPS)?

I have only DSI 1.3 at hand, which only talks about 1.1. I think 1.2 is
allowed by inheritance. That's why I skipped the version here.

> 
> > +   MIPI_DSI_COMPRESSION_VENDOR = 3,
> > +   /* other two values are reserved, DSI 1.3 */
> > +};
> > +
> >  struct mipi_dsi_device *
> >  mipi_dsi_device_register_full(struct mipi_dsi_host *host,
> >   const struct mipi_dsi_device_info *info);
> > @@ -242,6 +248,9 @@ int mipi_dsi_turn_on_peripheral(struct mipi_dsi_device 
> > *dsi);
> >  int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_dev

Re: [PATCH v3 1/4] dt-bindings: panel: Add LG SW43408 MIPI-DSI panel

2024-04-02 Thread Dmitry Baryshkov
On Tue, Apr 02, 2024 at 10:59:11PM +0200, Marijn Suijten wrote:
> On 2024-04-02 10:23:22, Dmitry Baryshkov wrote:
> > On Tue, 2 Apr 2024 at 09:31, Krzysztof Kozlowski
> >  wrote:
> > >
> > > On 02/04/2024 01:51, Dmitry Baryshkov wrote:
> > > > From: Sumit Semwal 
> > > >
> > > > LG SW43408 is 1080x2160, 4-lane MIPI-DSI panel present on Google Pixel 3
> > > > phones.
> > > >
> > > > Signed-off-by: Vinod Koul 
> > > > Signed-off-by: Sumit Semwal 
> > > > [caleb: convert to yaml]
> > > > Signed-off-by: Caleb Connolly 
> > > > Signed-off-by: Dmitry Baryshkov 
> > > > ---
> > >
> > > Tags missing.
> > >
> > > `b4 trailers -u`
> > 
> > Excuse me, I keep on forgetting it.
> 
> Does a similar thing exist for adding Cc: tags for all reviewers/replyers to 
> an
> earlier version, even if said reviewer didn't yet provide R-b/A-b or other 
> tags?
> 
> I'd like to have the next revisions in my inbox as well after leaving
> comments :)

Unfortunately I don't know such option.

> 
> Thanks! - Marijn

-- 
With best wishes
Dmitry


Re: [PATCH 3/3] drm: panel: Add LG sw43408 panel driver

2024-04-02 Thread Dmitry Baryshkov
On Tue, 2 Apr 2024 at 23:57, Marijn Suijten
 wrote:
>
> On 2024-04-01 22:11:48, Dmitry Baryshkov wrote:
> > On Mon, 1 Apr 2024 at 13:29, Marijn Suijten
> >  wrote:
> > >
> > > On 2024-03-30 16:37:08, Dmitry Baryshkov wrote:
> > > > On Sat, 30 Mar 2024 at 12:27, Marijn Suijten
> > > >  wrote:
> > > > >
> > > > > On 2024-03-30 05:59:30, Dmitry Baryshkov wrote:
> > > > > > From: Sumit Semwal 
> > > > > >
> > > > > > LG SW43408 is 1080x2160, 4-lane MIPI-DSI panel, used in some Pixel3
> > > > > > phones.
> > > > > >
> > > > > > Whatever init sequence we have for this panel isn't capable of
> > > > > > initialising it completely, toggling the reset gpio ever causes the
> > > > > > panel to die. Until this is resolved we avoid resetting the panel. 
> > > > > > The
> > > > >
> > > > > Are you sure it is avoided?  This patch seems to be toggling 
> > > > > reset_gpio in
> > > > > sw43408_prepare()?
> > > > >
> > > > > > disable/unprepare functions only put the panel to sleep mode and
> > > > > > disable the backlight.
> > > > > >
> > > > > > Signed-off-by: Sumit Semwal 
> > > > > > [vinod: Add DSC support]
> > > > > > Signed-off-by: Vinod Koul 
> > > > > > [caleb: cleanup and support turning off the panel]
> > > > > > Signed-off-by: Caleb Connolly 
> > > > > > [DB: partially rewrote the driver and fixed DSC programming]
> > > > > > Signed-off-by: Dmitry Baryshkov 
> > > > > > ---
> > > > > >  MAINTAINERS  |   8 +
> > > > > >  drivers/gpu/drm/panel/Kconfig|  11 ++
> > > > > >  drivers/gpu/drm/panel/Makefile   |   1 +
> > > > > >  drivers/gpu/drm/panel/panel-lg-sw43408.c | 322 
> > > > > > +++
> > > > > >  4 files changed, 342 insertions(+)
> > > > > >
> > > > > > diff --git a/MAINTAINERS b/MAINTAINERS
> > > > > > index 4b511a55101c..f4cf7ee97376 100644
> > > > > > --- a/MAINTAINERS
> > > > > > +++ b/MAINTAINERS
> > > > > > @@ -6755,6 +6755,14 @@ S: Maintained
> > > > > >  F:   
> > > > > > Documentation/devicetree/bindings/display/panel/jadard,jd9365da-h3.yaml
> > > > > >  F:   drivers/gpu/drm/panel/panel-jadard-jd9365da-h3.c
> > > > > >
> > > > > > +DRM DRIVER FOR LG SW43408 PANELS
> > > > > > +M:   Sumit Semwal 
> > > > > > +M:   Caleb Connolly 
> > > > > > +S:   Maintained
> > > > > > +T:   git git://anongit.freedesktop.org/drm/drm-misc
> > > > > > +F:   
> > > > > > Documentation/devicetree/bindings/display/panel/lg,sw43408.yaml
> > > > > > +F:   drivers/gpu/drm/panel/panel-lg-sw43408.c
> > > > > > +
> > > > > >  DRM DRIVER FOR LOGICVC DISPLAY CONTROLLER
> > > > > >  M:   Paul Kocialkowski 
> > > > > >  S:   Supported
> > > > > > diff --git a/drivers/gpu/drm/panel/Kconfig 
> > > > > > b/drivers/gpu/drm/panel/Kconfig
> > > > > > index d037b3b8b999..f94c702735cb 100644
> > > > > > --- a/drivers/gpu/drm/panel/Kconfig
> > > > > > +++ b/drivers/gpu/drm/panel/Kconfig
> > > > > > @@ -335,6 +335,17 @@ config DRM_PANEL_LG_LG4573
> > > > > > Say Y here if you want to enable support for LG4573 RGB 
> > > > > > panel.
> > > > > > To compile this driver as a module, choose M here.
> > > > > >
> > > > > > +config DRM_PANEL_LG_SW43408
> > > > > > + tristate "LG SW43408 panel"
> > > > > > + depends on OF
> > > > > > + depends on DRM_MIPI_DSI
> > > > > > + depends on BACKLIGHT_CLASS_DEVICE
> > > > > > + help
> > > > > > +   Say Y here if you want to enable support for LG sw43408 
> > > > > > panel.
> > > > > > +   The panel has a 1080x2160 resolution and uses
> > > > > > +   24 bit RGB per pixel. It provides a MIPI DSI interface to
> > > > > > +   the host and has a built-in LED backlight.
> > > > > > +
> > > > > >  config DRM_PANEL_MAGNACHIP_D53E6EA8966
> > > > > >   tristate "Magnachip D53E6EA8966 DSI panel"
> > > > > >   depends on OF && SPI
> > > > > > diff --git a/drivers/gpu/drm/panel/Makefile 
> > > > > > b/drivers/gpu/drm/panel/Makefile
> > > > > > index f156d7fa0bcc..a75687d13caf 100644
> > > > > > --- a/drivers/gpu/drm/panel/Makefile
> > > > > > +++ b/drivers/gpu/drm/panel/Makefile
> > > > > > @@ -34,6 +34,7 @@ obj-$(CONFIG_DRM_PANEL_LEADTEK_LTK050H3146W) += 
> > > > > > panel-leadtek-ltk050h3146w.o
> > > > > >  obj-$(CONFIG_DRM_PANEL_LEADTEK_LTK500HD1829) += 
> > > > > > panel-leadtek-ltk500hd1829.o
> > > > > >  obj-$(CONFIG_DRM_PANEL_LG_LB035Q02) += panel-lg-lb035q02.o
> > > > > >  obj-$(CONFIG_DRM_PANEL_LG_LG4573) += panel-lg-lg4573.o
> > > > > > +obj-$(CONFIG_DRM_PANEL_LG_SW43408) += panel-lg-sw43408.o
> > > > > >  obj-$(CONFIG_DRM_PANEL_MAGNACHIP_D53E6EA8966) += 
> > > > > > panel-magnachip-d53e6ea8966.o
> > > > > >  obj-$(CONFIG_DRM_PANEL_NEC_NL8048HL11) += panel-nec-nl8048hl11.o
> > > > > >  obj-$(CONFIG_DRM_PANEL_NEWVISION_NV3051D) += 
> > > > > > panel-newvision-nv3051d.o
> > > > > > diff --git a/drivers/gpu/drm/panel/panel-lg-sw43408.c 
> > > > > > b/drivers/gpu/drm/panel/panel-lg-sw43408.c
> > > > > > new file mode 100644
> > > > > > index ..365d25e14d54
> > 

[linux-next:master] BUILD REGRESSION c0b832517f627ead3388c6f0c74e8ac10ad5774b

2024-04-02 Thread kernel test robot
tree/branch: 
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
branch HEAD: c0b832517f627ead3388c6f0c74e8ac10ad5774b  Add linux-next specific 
files for 20240402

Error/Warning reports:

https://lore.kernel.org/oe-kbuild-all/202404021504.ytp51bl3-...@intel.com
https://lore.kernel.org/oe-kbuild-all/202404021556.0jvcnc13-...@intel.com
https://lore.kernel.org/oe-kbuild-all/202404021638.qkhbdq4e-...@intel.com
https://lore.kernel.org/oe-kbuild-all/202404021700.lbyyzgfd-...@intel.com
https://lore.kernel.org/oe-kbuild-all/202404022106.mywpypit-...@intel.com

Error/Warning: (recently discovered and may have been fixed)

ERROR: modpost: "__drm_atomic_helper_private_obj_duplicate_state" 
[drivers/gpu/drm/display/drm_display_helper.ko] undefined!
ERROR: modpost: "drm_kms_helper_hotplug_event" 
[drivers/gpu/drm/display/drm_display_helper.ko] undefined!
arch/csky/include/asm/cmpxchg.h:138:25: error: implicit declaration of function 
'cmpxchg_emu_u8' [-Werror=implicit-function-declaration]
arch/csky/include/asm/cmpxchg.h:141:25: error: implicit declaration of function 
'cmpxchg_emu_u16' [-Werror=implicit-function-declaration]
arch/riscv/include/asm/cmpxchg.h:329:23: warning: assignment to 'const struct 
gre_protocol *' from 'uintptr_t' {aka 'long unsigned int'} makes pointer from 
integer without a cast [-Wint-conversion]
arch/riscv/include/asm/cmpxchg.h:329:23: warning: assignment to 'struct 
bdi_writeback *' from 'uintptr_t' {aka 'long unsigned int'} makes pointer from 
integer without a cast [-Wint-conversion]
arch/riscv/include/asm/cmpxchg.h:329:23: warning: assignment to 'struct 
rtrs_clt_path *' from 'uintptr_t' {aka 'long unsigned int'} makes pointer from 
integer without a cast [-Wint-conversion]
arch/riscv/include/asm/cmpxchg.h:329:23: warning: assignment to 'struct 
tty_struct *' from 'uintptr_t' {aka 'long unsigned int'} makes pointer from 
integer without a cast [-Wint-conversion]
arch/riscv/include/asm/cmpxchg.h:329:23: warning: assignment to 
'z_erofs_next_pcluster_t' {aka 'void *'} from 'uintptr_t' {aka 'long unsigned 
int'} makes pointer from integer without a cast [-Wint-conversion]
cfi_probe.c:(.xiptext+0xdb): dangerous relocation: windowed longcall crosses 
1GB boundary; return may fail: __kmalloc_noprof
cfi_util.c:(.xiptext+0x40b): dangerous relocation: windowed longcall crosses 
1GB boundary; return may fail: __kmalloc_noprof
drivers/gpu/drm/display/drm_dp_mst_topology.c:5074:(.text+0x4da0): undefined 
reference to `drm_kms_helper_hotplug_event'
drivers/gpu/drm/display/drm_dp_mst_topology.c:5088:(.text+0x40a8): undefined 
reference to `__drm_atomic_helper_private_obj_duplicate_state'
drivers/gpu/drm/lima/lima_drv.c:387:13: error: cast to smaller integer type 
'enum lima_gpu_id' from 'const void *' [-Werror,-Wvoid-pointer-to-enum-cast]
drivers/gpu/drm/panthor/panthor_sched.c:2048:6: error: variable 'csg_mod_mask' 
set but not used [-Werror,-Wunused-but-set-variable]
drivers/gpu/drm/pl111/pl111_versatile.c:488:24: error: cast to smaller integer 
type 'enum versatile_clcd' from 'const void *' 
[-Werror,-Wvoid-pointer-to-enum-cast]
drivers/gpu/drm/qxl/qxl_cmd.c:424:6: error: variable 'count' set but not used 
[-Werror,-Wunused-but-set-variable]
drivers/gpu/drm/qxl/qxl_ioctl.c:148:14: error: variable 'num_relocs' set but 
not used [-Werror,-Wunused-but-set-variable]
drivers/s390/char/hmcdrv_cache.c:221:13: error: '__section__' attribute only 
applies to functions, global variables, Objective-C methods, and Objective-C 
properties
drivers/s390/char/hmcdrv_cache.c:221:13: error: 'section' attribute only 
applies to functions, global variables, Objective-C methods, and Objective-C 
properties
drivers/s390/char/hmcdrv_cache.c:221:13: error: non-extern declaration of 
'__pcpu_unique__alloc_tag_cntr' follows extern declaration
drivers/s390/char/hmcdrv_ftp.c:196:21: error: '__section__' attribute only 
applies to functions, global variables, Objective-C methods, and Objective-C 
properties
drivers/s390/char/hmcdrv_ftp.c:196:21: error: 'section' attribute only applies 
to functions, global variables, Objective-C methods, and Objective-C properties
drivers/s390/char/hmcdrv_ftp.c:196:21: error: non-extern declaration of 
'__pcpu_unique__alloc_tag_cntr' follows extern declaration
drivers/s390/char/hmcdrv_ftp.c:196:21: error: non-extern declaration of 
'_alloc_tag_cntr' follows extern declaration
drivers/s390/char/hmcdrv_ftp.c:196:21: error: weak declaration cannot have 
internal linkage
drm_dp_helper.c:(.text+0x36e8): undefined reference to 
`devm_backlight_device_register'
drm_dp_mst_topology.c:(.text+0x350c): undefined reference to 
`__

[RFC PATCH net-next v8 14/14] selftests: add ncdevmem, netcat for devmem TCP

2024-04-02 Thread Mina Almasry
ncdevmem is a devmem TCP netcat. It works similarly to netcat, but it
sends and receives data using the devmem TCP APIs. It uses udmabuf as
the dmabuf provider. It is compatible with a regular netcat running on
a peer, or a ncdevmem running on a peer.

In addition to normal netcat support, ncdevmem has a validation mode,
where it sends a specific pattern and validates this pattern on the
receiver side to ensure data integrity.

Suggested-by: Stanislav Fomichev 
Signed-off-by: Mina Almasry 

---

v6:
- Updated to bind 8 queues.
- Added RSS configuration.
- Added some more tests for the netlink API.

Changes in v1:
- Many more general cleanups (Willem).
- Removed driver reset (Jakub).
- Removed hardcoded if index (Paolo).

RFC v2:
- General cleanups (Willem).

---
 tools/testing/selftests/net/.gitignore |   1 +
 tools/testing/selftests/net/Makefile   |   5 +
 tools/testing/selftests/net/ncdevmem.c | 546 +
 3 files changed, 552 insertions(+)
 create mode 100644 tools/testing/selftests/net/ncdevmem.c

diff --git a/tools/testing/selftests/net/.gitignore 
b/tools/testing/selftests/net/.gitignore
index d996a0ab0765..d11814a1b5cf 100644
--- a/tools/testing/selftests/net/.gitignore
+++ b/tools/testing/selftests/net/.gitignore
@@ -17,6 +17,7 @@ ipv6_flowlabel
 ipv6_flowlabel_mgr
 log.txt
 msg_zerocopy
+ncdevmem
 nettest
 psock_fanout
 psock_snd
diff --git a/tools/testing/selftests/net/Makefile 
b/tools/testing/selftests/net/Makefile
index cb418a2346bc..7a1c9ccecb83 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -5,6 +5,10 @@ CFLAGS =  -Wall -Wl,--no-as-needed -O2 -g
 CFLAGS += -I../../../../usr/include/ $(KHDR_INCLUDES)
 # Additional include paths needed by kselftest.h
 CFLAGS += -I../
+CFLAGS += -I../../../net/ynl/generated/
+CFLAGS += -I../../../net/ynl/lib/
+
+LDLIBS += ../../../net/ynl/lib/ynl.a ../../../net/ynl/generated/protos.a
 
 TEST_PROGS := run_netsocktests run_afpackettests test_bpf.sh netdevice.sh \
  rtnetlink.sh xfrm_policy.sh test_blackhole_dev.sh
@@ -92,6 +96,7 @@ TEST_PROGS += test_bridge_backup_port.sh
 TEST_PROGS += fdb_flush.sh
 TEST_PROGS += fq_band_pktlimit.sh
 TEST_PROGS += vlan_hw_filter.sh
+TEST_GEN_FILES += ncdevmem
 
 TEST_FILES := settings
 TEST_FILES += in_netns.sh lib.sh net_helper.sh setup_loopback.sh setup_veth.sh
diff --git a/tools/testing/selftests/net/ncdevmem.c 
b/tools/testing/selftests/net/ncdevmem.c
new file mode 100644
index ..11bfe3e1125b
--- /dev/null
+++ b/tools/testing/selftests/net/ncdevmem.c
@@ -0,0 +1,546 @@
+// SPDX-License-Identifier: GPL-2.0
+#define _GNU_SOURCE
+#define __EXPORTED_HEADERS__
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#define __iovec_defined
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "netdev-user.h"
+#include 
+
+#define PAGE_SHIFT 12
+#define TEST_PREFIX "ncdevmem"
+#define NUM_PAGES 16000
+
+#ifndef MSG_SOCK_DEVMEM
+#define MSG_SOCK_DEVMEM 0x200
+#endif
+
+/*
+ * tcpdevmem netcat. Works similarly to netcat but does device memory TCP
+ * instead of regular TCP. Uses udmabuf to mock a dmabuf provider.
+ *
+ * Usage:
+ *
+ * On server:
+ * ncdevmem -s  -c  -f eth1 -d 3 -n :06:00.0 -l \
+ * -p 5201 -v 7
+ *
+ * On client:
+ * yes $(echo -e \\x01\\x02\\x03\\x04\\x05\\x06) | \
+ * tr \\n \\0 | \
+ * head -c 5G | \
+ * nc  5201 -p 5201
+ *
+ * Note this is compatible with regular netcat. i.e. the sender or receiver can
+ * be replaced with regular netcat to test the RX or TX path in isolation.
+ */
+
+static char *server_ip = "192.168.1.4";
+static char *client_ip = "192.168.1.2";
+static char *port = "5201";
+static size_t do_validation;
+static int start_queue = 8;
+static int num_queues = 8;
+static char *ifname = "eth1";
+static unsigned int ifindex = 3;
+static char *nic_pci_addr = ":06:00.0";
+static unsigned int iterations;
+static unsigned int dmabuf_id;
+
+void print_bytes(void *ptr, size_t size)
+{
+   unsigned char *p = ptr;
+   int i;
+
+   for (i = 0; i < size; i++)
+   printf("%02hhX ", p[i]);
+   printf("\n");
+}
+
+void print_nonzero_bytes(void *ptr, size_t size)
+{
+   unsigned char *p = ptr;
+   unsigned int i;
+
+   for (i = 0; i < size; i++)
+   putchar(p[i]);
+   printf("\n");
+}
+
+void validate_buffer(void *line, size_t size)
+{
+   static unsigned char seed = 1;
+   unsigned char *ptr = line;
+   int errors = 0;
+   size_t i;
+
+   for (i = 0; i < size; i++) {
+   if (ptr[i] != seed) {
+   fprintf(stderr,
+   "Failed validation: expected=%u, actual=%u, 
index=%lu\n",
+   seed, ptr[i], i);
+   

[RFC PATCH net-next v8 13/14] net: add devmem TCP documentation

2024-04-02 Thread Mina Almasry
Add documentation outlining the usage and details of devmem TCP.

Signed-off-by: Mina Almasry 

---

v8:
- Applied docs suggestions (Randy). Thanks!

v7:
- Applied docs suggestions (Jakub).

v2:

- Missing spdx (simon)
- add to index.rst (simon)


fix docs

---
 Documentation/networking/devmem.rst | 256 
 Documentation/networking/index.rst  |   1 +
 2 files changed, 257 insertions(+)
 create mode 100644 Documentation/networking/devmem.rst

diff --git a/Documentation/networking/devmem.rst 
b/Documentation/networking/devmem.rst
new file mode 100644
index ..e4e978fbcdbd
--- /dev/null
+++ b/Documentation/networking/devmem.rst
@@ -0,0 +1,256 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=
+Device Memory TCP
+=
+
+
+Intro
+=
+
+Device memory TCP (devmem TCP) enables receiving data directly into device
+memory (dmabuf). The feature is currently implemented for TCP sockets.
+
+
+Opportunity
+---
+
+A large number of data transfers have device memory as the source and/or
+destination. Accelerators drastically increased the prevalence of such
+transfers.  Some examples include:
+
+- Distributed training, where ML accelerators, such as GPUs on different hosts,
+  exchange data.
+
+- Distributed raw block storage applications transfer large amounts of data 
with
+  remote SSDs. Much of this data does not require host processing.
+
+Typically the Device-to-Device data transfers in the network are implemented as
+the following low-level operations: Device-to-Host copy, Host-to-Host network
+transfer, and Host-to-Device copy.
+
+The flow involving host copies is suboptimal, especially for bulk data 
transfers,
+and can put significant strains on system resources such as host memory
+bandwidth and PCIe bandwidth.
+
+Devmem TCP optimizes this use case by implementing socket APIs that enable
+the user to receive incoming network packets directly into device memory.
+
+Packet payloads go directly from the NIC to device memory.
+
+Packet headers go to host memory and are processed by the TCP/IP stack
+normally. The NIC must support header split to achieve this.
+
+Advantages:
+
+- Alleviate host memory bandwidth pressure, compared to existing
+  network-transfer + device-copy semantics.
+
+- Alleviate PCIe bandwidth pressure, by limiting data transfer to the lowest
+  level of the PCIe tree, compared to the traditional path which sends data
+  through the root complex.
+
+
+More Info
+-
+
+  slides, video
+https://netdevconf.org/0x17/sessions/talk/device-memory-tcp.html
+
+  patchset
+[RFC PATCH v6 00/12] Device Memory TCP
+
https://lore.kernel.org/netdev/20240305020153.2787423-1-almasrym...@google.com/
+
+
+Interface
+=
+
+Example
+---
+
+tools/testing/selftests/net/ncdevmem.c:do_server shows an example of setting up
+the RX path of this API.
+
+NIC Setup
+-
+
+Header split, flow steering, & RSS are required features for devmem TCP.
+
+Header split is used to split incoming packets into a header buffer in host
+memory, and a payload buffer in device memory.
+
+Flow steering & RSS are used to ensure that only flows targeting devmem land on
+an RX queue bound to devmem.
+
+Enable header split & flow steering::
+
+   # enable header split
+   ethtool -G eth1 tcp-data-split on
+
+
+   # enable flow steering
+   ethtool -K eth1 ntuple on
+
+Configure RSS to steer all traffic away from the target RX queue (queue 15 in
+this example)::
+
+   ethtool --set-rxfh-indir eth1 equal 15
+
+
+The user must bind a dmabuf to any number of RX queues on a given NIC using
+the netlink API::
+
+   /* Bind dmabuf to NIC RX queue 15 */
+   struct netdev_queue *queues;
+   queues = malloc(sizeof(*queues) * 1);
+
+   queues[0]._present.type = 1;
+   queues[0]._present.idx = 1;
+   queues[0].type = NETDEV_RX_QUEUE_TYPE_RX;
+   queues[0].idx = 15;
+
+   *ys = ynl_sock_create(&ynl_netdev_family, &yerr);
+
+   req = netdev_bind_rx_req_alloc();
+   netdev_bind_rx_req_set_ifindex(req, 1 /* ifindex */);
+   netdev_bind_rx_req_set_dmabuf_fd(req, dmabuf_fd);
+   __netdev_bind_rx_req_set_queues(req, queues, n_queue_index);
+
+   rsp = netdev_bind_rx(*ys, req);
+
+   dmabuf_id = rsp->dmabuf_id;
+
+
+The netlink API returns a dmabuf_id: a unique ID that refers to this dmabuf
+that has been bound.
+
+Socket Setup
+
+
+The socket must be flow steered to the dmabuf bound RX queue::
+
+   ethtool -N eth1 flow-type tcp4 ... queue 15,
+
+
+Receiving data
+--
+
+The user application must signal to the kernel that it is capable of receiving
+devmem data by passing the MSG_SOCK_DEVMEM flag to recvmsg::
+
+   ret = recvmsg(fd, &msg, MSG_SOCK_DEVMEM);
+
+Applications that do not specify the MSG_SOCK_DEVMEM flag will receive an 
EFAULT
+on devmem data.
+
+Devmem data is received directly into the dmabuf bound to the NIC in 'NIC
+Setup', and the ker

[RFC PATCH net-next v8 12/14] net: add SO_DEVMEM_DONTNEED setsockopt to release RX frags

2024-04-02 Thread Mina Almasry
Add an interface for the user to notify the kernel that it is done
reading the devmem dmabuf frags returned as cmsg. The kernel will
drop the reference on the frags to make them available for reuse.

Signed-off-by: Willem de Bruijn 
Signed-off-by: Kaiyuan Zhang 
Signed-off-by: Mina Almasry 

---

v7:
- Updated SO_DEVMEM_* uapi to use the next available entry (Arnd).

v6:
- Squash in locking optimizations from eduma...@google.com. With his
  changes we lock the xarray once per sock_devmem_dontneed operation
  rather than once per frag.

Changes in v1:
- devmemtoken -> dmabuf_token (David).
- Use napi_pp_put_page() for refcounting (Yunsheng).
- Fix build error with missing socket options on other asms.

---
 arch/alpha/include/uapi/asm/socket.h  |  1 +
 arch/mips/include/uapi/asm/socket.h   |  1 +
 arch/parisc/include/uapi/asm/socket.h |  1 +
 arch/sparc/include/uapi/asm/socket.h  |  1 +
 include/uapi/asm-generic/socket.h |  1 +
 include/uapi/linux/uio.h  |  4 ++
 net/core/sock.c   | 61 +++
 7 files changed, 70 insertions(+)

diff --git a/arch/alpha/include/uapi/asm/socket.h 
b/arch/alpha/include/uapi/asm/socket.h
index ef4656a41058..251b73c5481e 100644
--- a/arch/alpha/include/uapi/asm/socket.h
+++ b/arch/alpha/include/uapi/asm/socket.h
@@ -144,6 +144,7 @@
 #define SCM_DEVMEM_LINEAR  SO_DEVMEM_LINEAR
 #define SO_DEVMEM_DMABUF   79
 #define SCM_DEVMEM_DMABUF  SO_DEVMEM_DMABUF
+#define SO_DEVMEM_DONTNEED 80
 
 #if !defined(__KERNEL__)
 
diff --git a/arch/mips/include/uapi/asm/socket.h 
b/arch/mips/include/uapi/asm/socket.h
index 414807d55e33..8ab7582291ab 100644
--- a/arch/mips/include/uapi/asm/socket.h
+++ b/arch/mips/include/uapi/asm/socket.h
@@ -155,6 +155,7 @@
 #define SCM_DEVMEM_LINEAR  SO_DEVMEM_LINEAR
 #define SO_DEVMEM_DMABUF   79
 #define SCM_DEVMEM_DMABUF  SO_DEVMEM_DMABUF
+#define SO_DEVMEM_DONTNEED 80
 
 #if !defined(__KERNEL__)
 
diff --git a/arch/parisc/include/uapi/asm/socket.h 
b/arch/parisc/include/uapi/asm/socket.h
index 2b817efd4544..38fc0b188e08 100644
--- a/arch/parisc/include/uapi/asm/socket.h
+++ b/arch/parisc/include/uapi/asm/socket.h
@@ -136,6 +136,7 @@
 #define SCM_DEVMEM_LINEAR  SO_DEVMEM_LINEAR
 #define SO_DEVMEM_DMABUF   79
 #define SCM_DEVMEM_DMABUF  SO_DEVMEM_DMABUF
+#define SO_DEVMEM_DONTNEED 80
 
 #if !defined(__KERNEL__)
 
diff --git a/arch/sparc/include/uapi/asm/socket.h 
b/arch/sparc/include/uapi/asm/socket.h
index 00248fc68977..57084ed2f3c4 100644
--- a/arch/sparc/include/uapi/asm/socket.h
+++ b/arch/sparc/include/uapi/asm/socket.h
@@ -137,6 +137,7 @@
 #define SCM_DEVMEM_LINEARSO_DEVMEM_LINEAR
 #define SO_DEVMEM_DMABUF 0x0058
 #define SCM_DEVMEM_DMABUFSO_DEVMEM_DMABUF
+#define SO_DEVMEM_DONTNEED   0x0059
 
 #if !defined(__KERNEL__)
 
diff --git a/include/uapi/asm-generic/socket.h 
b/include/uapi/asm-generic/socket.h
index 25a2f5255f52..1acb77780f10 100644
--- a/include/uapi/asm-generic/socket.h
+++ b/include/uapi/asm-generic/socket.h
@@ -135,6 +135,7 @@
 #define SO_PASSPIDFD   76
 #define SO_PEERPIDFD   77
 
+#define SO_DEVMEM_DONTNEED 97
 #define SO_DEVMEM_LINEAR   98
 #define SCM_DEVMEM_LINEAR  SO_DEVMEM_LINEAR
 #define SO_DEVMEM_DMABUF   99
diff --git a/include/uapi/linux/uio.h b/include/uapi/linux/uio.h
index 3a22ddae376a..d17f8fcd93ec 100644
--- a/include/uapi/linux/uio.h
+++ b/include/uapi/linux/uio.h
@@ -33,6 +33,10 @@ struct dmabuf_cmsg {
 */
 };
 
+struct dmabuf_token {
+   __u32 token_start;
+   __u32 token_count;
+};
 /*
  * UIO_MAXIOV shall be at least 16 1003.1g (5.4.1.1)
  */
diff --git a/net/core/sock.c b/net/core/sock.c
index 5ed411231fc7..04e14f9c4e24 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1049,6 +1049,63 @@ static int sock_reserve_memory(struct sock *sk, int 
bytes)
return 0;
 }
 
+#ifdef CONFIG_PAGE_POOL
+static noinline_for_stack int
+sock_devmem_dontneed(struct sock *sk, sockptr_t optval, unsigned int optlen)
+{
+   unsigned int num_tokens, i, j, k, netmem_num = 0;
+   struct dmabuf_token *tokens;
+   netmem_ref netmems[16];
+   int ret;
+
+   if (sk->sk_type != SOCK_STREAM || sk->sk_protocol != IPPROTO_TCP)
+   return -EBADF;
+
+   if (optlen % sizeof(struct dmabuf_token) ||
+   optlen > sizeof(*tokens) * 128)
+   return -EINVAL;
+
+   tokens = kvmalloc_array(128, sizeof(*tokens), GFP_KERNEL);
+   if (!tokens)
+   return -ENOMEM;
+
+   num_tokens = optlen / sizeof(struct dmabuf_token);
+   if (copy_from_sockptr(tokens, optval, optlen))
+   return -EFAULT;
+
+   ret = 0;
+
+   xa_lock_bh(&sk->sk_user_frags);
+   for (i = 0; i < num_tokens; i++) {
+   for (j = 0; j < tokens[i].token_count; j++) {
+   netmem_ref netmem = (__force netmem_ref)__xa_erase(
+   &

[RFC PATCH net-next v8 11/14] tcp: RX path for devmem TCP

2024-04-02 Thread Mina Almasry
In tcp_recvmsg_locked(), detect if the skb being received by the user
is a devmem skb. In this case - if the user provided the MSG_SOCK_DEVMEM
flag - pass it to tcp_recvmsg_devmem() for custom handling.

tcp_recvmsg_devmem() copies any data in the skb header to the linear
buffer, and returns a cmsg to the user indicating the number of bytes
returned in the linear buffer.

tcp_recvmsg_devmem() then loops over the unaccessible devmem skb frags,
and returns to the user a cmsg_devmem indicating the location of the
data in the dmabuf device memory. cmsg_devmem contains this information:

1. the offset into the dmabuf where the payload starts. 'frag_offset'.
2. the size of the frag. 'frag_size'.
3. an opaque token 'frag_token' to return to the kernel when the buffer
is to be released.

The pages awaiting freeing are stored in the newly added
sk->sk_user_frags, and each page passed to userspace is get_page()'d.
This reference is dropped once the userspace indicates that it is
done reading this page.  All pages are released when the socket is
destroyed.

Signed-off-by: Willem de Bruijn 
Signed-off-by: Kaiyuan Zhang 
Signed-off-by: Mina Almasry 

---

v7:
- Updated the SO_DEVMEM_* uapi to use the next available entries (Arnd).
- Updated dmabuf_cmsg struct to be __u64 padded (Arnd).
- Squashed fix from Eric to initialize sk_user_frags for passive
  sockets (Eric).

v6
- skb->dmabuf -> skb->readable (Pavel)
- Fixed asm definitions of SO_DEVMEM_LINEAR/SO_DEVMEM_DMABUF not found
  on some archs.
- Squashed in locking optimizations from eduma...@google.com. With this
  change we lock the xarray once per per tcp_recvmsg_dmabuf() rather
  than once per frag in xa_alloc().

Changes in v1:
- Added dmabuf_id to dmabuf_cmsg (David/Stan).
- Devmem -> dmabuf (David).
- Change tcp_recvmsg_dmabuf() check to skb->dmabuf (Paolo).
- Use __skb_frag_ref() & napi_pp_put_page() for refcounting (Yunsheng).

RFC v3:
- Fixed issue with put_cmsg() failing silently.

---
 arch/alpha/include/uapi/asm/socket.h  |   5 +
 arch/mips/include/uapi/asm/socket.h   |   5 +
 arch/parisc/include/uapi/asm/socket.h |   5 +
 arch/sparc/include/uapi/asm/socket.h  |   5 +
 include/linux/socket.h|   1 +
 include/net/netmem.h  |  13 ++
 include/net/sock.h|   2 +
 include/uapi/asm-generic/socket.h |   5 +
 include/uapi/linux/uio.h  |  13 ++
 net/ipv4/tcp.c| 248 +-
 net/ipv4/tcp_ipv4.c   |   9 +
 net/ipv4/tcp_minisocks.c  |   2 +
 12 files changed, 308 insertions(+), 5 deletions(-)

diff --git a/arch/alpha/include/uapi/asm/socket.h 
b/arch/alpha/include/uapi/asm/socket.h
index e94f621903fe..ef4656a41058 100644
--- a/arch/alpha/include/uapi/asm/socket.h
+++ b/arch/alpha/include/uapi/asm/socket.h
@@ -140,6 +140,11 @@
 #define SO_PASSPIDFD   76
 #define SO_PEERPIDFD   77
 
+#define SO_DEVMEM_LINEAR   78
+#define SCM_DEVMEM_LINEAR  SO_DEVMEM_LINEAR
+#define SO_DEVMEM_DMABUF   79
+#define SCM_DEVMEM_DMABUF  SO_DEVMEM_DMABUF
+
 #if !defined(__KERNEL__)
 
 #if __BITS_PER_LONG == 64
diff --git a/arch/mips/include/uapi/asm/socket.h 
b/arch/mips/include/uapi/asm/socket.h
index 60ebaed28a4c..414807d55e33 100644
--- a/arch/mips/include/uapi/asm/socket.h
+++ b/arch/mips/include/uapi/asm/socket.h
@@ -151,6 +151,11 @@
 #define SO_PASSPIDFD   76
 #define SO_PEERPIDFD   77
 
+#define SO_DEVMEM_LINEAR   78
+#define SCM_DEVMEM_LINEAR  SO_DEVMEM_LINEAR
+#define SO_DEVMEM_DMABUF   79
+#define SCM_DEVMEM_DMABUF  SO_DEVMEM_DMABUF
+
 #if !defined(__KERNEL__)
 
 #if __BITS_PER_LONG == 64
diff --git a/arch/parisc/include/uapi/asm/socket.h 
b/arch/parisc/include/uapi/asm/socket.h
index be264c2b1a11..2b817efd4544 100644
--- a/arch/parisc/include/uapi/asm/socket.h
+++ b/arch/parisc/include/uapi/asm/socket.h
@@ -132,6 +132,11 @@
 #define SO_PASSPIDFD   0x404A
 #define SO_PEERPIDFD   0x404B
 
+#define SO_DEVMEM_LINEAR   78
+#define SCM_DEVMEM_LINEAR  SO_DEVMEM_LINEAR
+#define SO_DEVMEM_DMABUF   79
+#define SCM_DEVMEM_DMABUF  SO_DEVMEM_DMABUF
+
 #if !defined(__KERNEL__)
 
 #if __BITS_PER_LONG == 64
diff --git a/arch/sparc/include/uapi/asm/socket.h 
b/arch/sparc/include/uapi/asm/socket.h
index 682da3714686..00248fc68977 100644
--- a/arch/sparc/include/uapi/asm/socket.h
+++ b/arch/sparc/include/uapi/asm/socket.h
@@ -133,6 +133,11 @@
 #define SO_PASSPIDFD 0x0055
 #define SO_PEERPIDFD 0x0056
 
+#define SO_DEVMEM_LINEAR 0x0057
+#define SCM_DEVMEM_LINEARSO_DEVMEM_LINEAR
+#define SO_DEVMEM_DMABUF 0x0058
+#define SCM_DEVMEM_DMABUFSO_DEVMEM_DMABUF
+
 #if !defined(__KERNEL__)
 
 
diff --git a/include/linux/socket.h b/include/linux/socket.h
index 139c330ccf2c..f11ab541439e 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -326,6 +326,7 @@ struct ucred {
  *

[RFC PATCH net-next v8 10/14] net: add support for skbs with unreadable frags

2024-04-02 Thread Mina Almasry
For device memory TCP, we expect the skb headers to be available in host
memory for access, and we expect the skb frags to be in device memory
and unaccessible to the host. We expect there to be no mixing and
matching of device memory frags (unaccessible) with host memory frags
(accessible) in the same skb.

Add a skb->devmem flag which indicates whether the frags in this skb
are device memory frags or not.

__skb_fill_netmem_desc() now checks frags added to skbs for net_iov,
and marks the skb as skb->devmem accordingly.

Add checks through the network stack to avoid accessing the frags of
devmem skbs and avoid coalescing devmem skbs with non devmem skbs.

Signed-off-by: Willem de Bruijn 
Signed-off-by: Kaiyuan Zhang 
Signed-off-by: Mina Almasry 


---

v6
- skb->dmabuf -> skb->readable (Pavel). Pavel's original suggestion was
  to remove the skb->dmabuf flag entirely, but when I looked into it
  closely, I found the issue that if we remove the flag we have to
  dereference the shinfo(skb) pointer to obtain the first frag, which
  can cause a performance regression if it dirties the cache line when
  the shinfo(skb) was not really needed. Instead, I converted the
  skb->dmabuf flag into a generic skb->readable flag which can be
  re-used by io_uring.

Changes in v1:
- Rename devmem -> dmabuf (David).
- Flip skb_frags_not_readable (Jakub).

---
 include/linux/skbuff.h | 18 +--
 include/net/tcp.h  |  5 +--
 net/core/datagram.c|  6 
 net/core/gro.c |  5 ++-
 net/core/skbuff.c  | 73 --
 net/ipv4/tcp.c |  3 ++
 net/ipv4/tcp_input.c   | 13 ++--
 net/ipv4/tcp_output.c  |  5 ++-
 net/packet/af_packet.c |  4 +--
 9 files changed, 111 insertions(+), 21 deletions(-)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index fb4c2cf441f4..adaa9d643ba3 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -816,6 +816,7 @@ typedef unsigned char *sk_buff_data_t;
  * @csum_level: indicates the number of consecutive checksums found in
  * the packet minus one that have been verified as
  * CHECKSUM_UNNECESSARY (max 3)
+ * @readable: indicates that all the fragments in this skb are readable.
  * @dst_pending_confirm: need to confirm neighbour
  * @decrypted: Decrypted SKB
  * @slow_gro: state present at GRO time, slower prepare step required
@@ -999,7 +1000,7 @@ struct sk_buff {
 #if IS_ENABLED(CONFIG_IP_SCTP)
__u8csum_not_inet:1;
 #endif
-
+   __u8readable:1;
 #if defined(CONFIG_NET_SCHED) || defined(CONFIG_NET_XGRESS)
__u16   tc_index;   /* traffic control index */
 #endif
@@ -1791,6 +1792,12 @@ static inline void skb_zcopy_downgrade_managed(struct 
sk_buff *skb)
__skb_zcopy_downgrade_managed(skb);
 }
 
+/* Return true if frags in this skb are readable by the host. */
+static inline bool skb_frags_readable(const struct sk_buff *skb)
+{
+   return skb->readable;
+}
+
 static inline void skb_mark_not_on_list(struct sk_buff *skb)
 {
skb->next = NULL;
@@ -2507,10 +2514,17 @@ static inline void skb_len_add(struct sk_buff *skb, int 
delta)
 static inline void __skb_fill_netmem_desc(struct sk_buff *skb, int i,
  netmem_ref netmem, int off, int size)
 {
-   struct page *page = netmem_to_page(netmem);
+   struct page *page;
 
__skb_fill_netmem_desc_noacc(skb_shinfo(skb), i, netmem, off, size);
 
+   if (netmem_is_net_iov(netmem)) {
+   skb->readable = false;
+   return;
+   }
+
+   page = netmem_to_page(netmem);
+
/* Propagate page pfmemalloc to the skb if we can. The problem is
 * that not all callers have unique ownership of the page but rely
 * on page_is_pfmemalloc doing the right thing(tm).
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 9ab5b37e9d53..7b8e7dae49da 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -1062,7 +1062,7 @@ static inline int tcp_skb_mss(const struct sk_buff *skb)
 
 static inline bool tcp_skb_can_collapse_to(const struct sk_buff *skb)
 {
-   return likely(!TCP_SKB_CB(skb)->eor);
+   return likely(!TCP_SKB_CB(skb)->eor && skb_frags_readable(skb));
 }
 
 static inline bool tcp_skb_can_collapse(const struct sk_buff *to,
@@ -1070,7 +1070,8 @@ static inline bool tcp_skb_can_collapse(const struct 
sk_buff *to,
 {
return likely(tcp_skb_can_collapse_to(to) &&
  mptcp_skb_can_collapse(to, from) &&
- skb_pure_zcopy_same(to, from));
+ skb_pure_zcopy_same(to, from) &&
+ skb_frags_readable(to) == skb_frags_readable(from));
 }
 
 /* Events passed to congestion control interface */
diff --git a/net/core/datagram.c b/net/core/datagram.c
index e614cfd8e14a..b29f881df0e8 100644
--- a/net/core/datagram.c
+++ b/net/core/datagram.c
@@ -407,6 +

[RFC PATCH net-next v8 09/14] net: support non paged skb frags

2024-04-02 Thread Mina Almasry
Make skb_frag_page() fail in the case where the frag is not backed
by a page, and fix its relevant callers to handle this case.

Signed-off-by: Mina Almasry 


---

v6:
- Rebased on top of the merged netmem changes.

Changes in v1:
- Fix illegal_highdma() (Yunsheng).
- Rework napi_pp_put_page() slightly to reduce code churn (Willem).

---
 include/linux/skbuff.h | 53 +++---
 net/core/dev.c |  3 ++-
 net/core/gro.c |  3 ++-
 net/core/skbuff.c  | 11 +
 net/ipv4/esp4.c|  2 +-
 net/ipv4/tcp.c |  3 +++
 net/ipv6/esp6.c|  2 +-
 7 files changed, 65 insertions(+), 12 deletions(-)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index c9659e9d843e..fb4c2cf441f4 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -3472,17 +3472,53 @@ static inline void skb_frag_off_copy(skb_frag_t *fragto,
fragto->offset = fragfrom->offset;
 }
 
+/* Returns true if the skb_frag contains a net_iov. */
+static inline bool skb_frag_is_net_iov(const skb_frag_t *frag)
+{
+   return netmem_is_net_iov(frag->netmem);
+}
+
+/**
+ * skb_frag_net_iov - retrieve the net_iov referred to by fragment
+ * @frag: the fragment
+ *
+ * Returns the &struct net_iov associated with @frag. Returns NULL if this
+ * frag has no associated net_iov.
+ */
+static inline struct net_iov *skb_frag_net_iov(const skb_frag_t *frag)
+{
+   if (!skb_frag_is_net_iov(frag))
+   return NULL;
+
+   return netmem_to_net_iov(frag->netmem);
+}
+
 /**
  * skb_frag_page - retrieve the page referred to by a paged fragment
  * @frag: the paged fragment
  *
- * Returns the &struct page associated with @frag.
+ * Returns the &struct page associated with @frag. Returns NULL if this frag
+ * has no associated page.
  */
 static inline struct page *skb_frag_page(const skb_frag_t *frag)
 {
+   if (skb_frag_is_net_iov(frag))
+   return NULL;
+
return netmem_to_page(frag->netmem);
 }
 
+/**
+ * skb_frag_netmem - retrieve the netmem referred to by a fragment
+ * @frag: the fragment
+ *
+ * Returns the &netmem_ref associated with @frag.
+ */
+static inline netmem_ref skb_frag_netmem(const skb_frag_t *frag)
+{
+   return frag->netmem;
+}
+
 /**
  * __skb_frag_ref - take an addition reference on a paged fragment.
  * @frag: the paged fragment
@@ -3513,25 +3549,23 @@ int skb_cow_data_for_xdp(struct page_pool *pool, struct 
sk_buff **pskb,
 bool napi_pp_put_page(netmem_ref netmem, bool napi_safe);
 
 static inline void
-skb_page_unref(const struct sk_buff *skb, struct page *page, bool napi_safe)
+skb_page_unref(const struct sk_buff *skb, netmem_ref netmem, bool napi_safe)
 {
 #ifdef CONFIG_PAGE_POOL
-   if (skb->pp_recycle && napi_pp_put_page(page_to_netmem(page), 
napi_safe))
+   if (skb->pp_recycle && napi_pp_put_page(netmem, napi_safe))
return;
 #endif
-   put_page(page);
+   put_page(netmem_to_page(netmem));
 }
 
 static inline void
 napi_frag_unref(skb_frag_t *frag, bool recycle, bool napi_safe)
 {
-   struct page *page = skb_frag_page(frag);
-
 #ifdef CONFIG_PAGE_POOL
-   if (recycle && napi_pp_put_page(page_to_netmem(page), napi_safe))
+   if (recycle && napi_pp_put_page(skb_frag_netmem(frag), napi_safe))
return;
 #endif
-   put_page(page);
+   put_page(skb_frag_page(frag));
 }
 
 /**
@@ -3571,6 +3605,9 @@ static inline void skb_frag_unref(struct sk_buff *skb, 
int f)
  */
 static inline void *skb_frag_address(const skb_frag_t *frag)
 {
+   if (!skb_frag_page(frag))
+   return NULL;
+
return page_address(skb_frag_page(frag)) + skb_frag_off(frag);
 }
 
diff --git a/net/core/dev.c b/net/core/dev.c
index 7ef8def6ec43..94adc63957d1 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -3416,8 +3416,9 @@ static int illegal_highdma(struct net_device *dev, struct 
sk_buff *skb)
if (!(dev->features & NETIF_F_HIGHDMA)) {
for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
+   struct page *page = skb_frag_page(frag);
 
-   if (PageHighMem(skb_frag_page(frag)))
+   if (page && PageHighMem(page))
return 1;
}
}
diff --git a/net/core/gro.c b/net/core/gro.c
index ee30d4f0c038..eef20c82c5c3 100644
--- a/net/core/gro.c
+++ b/net/core/gro.c
@@ -380,7 +380,8 @@ static inline void skb_gro_reset_offset(struct sk_buff 
*skb, u32 nhoff)
pinfo = skb_shinfo(skb);
frag0 = &pinfo->frags[0];
 
-   if (pinfo->nr_frags && !PageHighMem(skb_frag_page(frag0)) &&
+   if (pinfo->nr_frags && skb_frag_page(frag0) &&
+   !PageHighMem(skb_frag_page(frag0)) &&
(!NET_IP_ALIGN || !((skb_frag_off(frag0) + nhoff) & 3))) {
NAPI_GRO_CB(skb)->frag0 = skb_frag_address(frag0);
NAPI_GRO_CB(skb

[RFC PATCH net-next v8 08/14] memory-provider: dmabuf devmem memory provider

2024-04-02 Thread Mina Almasry
Implement a memory provider that allocates dmabuf devmem in the form of
net_iov.

The provider receives a reference to the struct netdev_dmabuf_binding
via the pool->mp_priv pointer. The driver needs to set this pointer for
the provider in the net_iov.

The provider obtains a reference on the netdev_dmabuf_binding which
guarantees the binding and the underlying mapping remains alive until
the provider is destroyed.

Usage of PP_FLAG_DMA_MAP is required for this memory provide such that
the page_pool can provide the driver with the dma-addrs of the devmem.

Support for PP_FLAG_DMA_SYNC_DEV is omitted for simplicity & p.order !=
0.

Signed-off-by: Willem de Bruijn 
Signed-off-by: Kaiyuan Zhang 
Signed-off-by: Mina Almasry 

---

v8:
- Use skb_frag_size instead of frag->bv_len to fix patch-by-patch build
  error

v6:
- refactor new memory provider functions into net/core/devmem.c (Pavel)

v2:
- Disable devmem for p.order != 0

v1:
- static_branch check in page_is_page_pool_iov() (Willem & Paolo).
- PP_DEVMEM -> PP_IOV (David).
- Require PP_FLAG_DMA_MAP (Jakub).

---
 include/net/netmem.h| 15 ++
 include/net/page_pool/helpers.h | 22 +
 include/net/page_pool/types.h   |  2 +
 net/core/devmem.c   | 83 +
 net/core/page_pool.c| 38 +++
 5 files changed, 138 insertions(+), 22 deletions(-)

diff --git a/include/net/netmem.h b/include/net/netmem.h
index 74eeaa34883e..34aa1c80c1ca 100644
--- a/include/net/netmem.h
+++ b/include/net/netmem.h
@@ -126,6 +126,21 @@ static inline struct page *netmem_to_page(netmem_ref 
netmem)
return (__force struct page *)netmem;
 }
 
+static inline struct net_iov *netmem_to_net_iov(netmem_ref netmem)
+{
+   if (netmem_is_net_iov(netmem))
+   return (struct net_iov *)((__force unsigned long)netmem &
+ ~NET_IOV);
+
+   DEBUG_NET_WARN_ON_ONCE(true);
+   return NULL;
+}
+
+static inline netmem_ref net_iov_to_netmem(struct net_iov *niov)
+{
+   return (__force netmem_ref)((unsigned long)niov | NET_IOV);
+}
+
 static inline netmem_ref page_to_netmem(struct page *page)
 {
return (__force netmem_ref)page;
diff --git a/include/net/page_pool/helpers.h b/include/net/page_pool/helpers.h
index c6a55eddefae..eb736506c3ce 100644
--- a/include/net/page_pool/helpers.h
+++ b/include/net/page_pool/helpers.h
@@ -453,4 +453,26 @@ static inline void page_pool_nid_changed(struct page_pool 
*pool, int new_nid)
page_pool_update_nid(pool, new_nid);
 }
 
+static inline void page_pool_set_pp_info(struct page_pool *pool,
+netmem_ref netmem)
+{
+   netmem_set_pp(netmem, pool);
+   netmem_or_pp_magic(netmem, PP_SIGNATURE);
+
+   /* Ensuring all pages have been split into one fragment initially:
+* page_pool_set_pp_info() is only called once for every page when it
+* is allocated from the page allocator and page_pool_fragment_page()
+* is dirtying the same cache line as the page->pp_magic above, so
+* the overhead is negligible.
+*/
+   page_pool_fragment_netmem(netmem, 1);
+   if (pool->has_init_callback)
+   pool->slow.init_callback(netmem, pool->slow.init_arg);
+}
+
+static inline void page_pool_clear_pp_info(netmem_ref netmem)
+{
+   netmem_clear_pp_magic(netmem);
+   netmem_set_pp(netmem, NULL);
+}
 #endif /* _NET_PAGE_POOL_HELPERS_H */
diff --git a/include/net/page_pool/types.h b/include/net/page_pool/types.h
index f04af1613f59..5b58c9e185a4 100644
--- a/include/net/page_pool/types.h
+++ b/include/net/page_pool/types.h
@@ -141,6 +141,8 @@ struct pp_memory_provider_params {
void *mp_priv;
 };
 
+extern const struct memory_provider_ops dmabuf_devmem_ops;
+
 struct page_pool {
struct page_pool_params_fast p;
 
diff --git a/net/core/devmem.c b/net/core/devmem.c
index c25ede5f6fb9..01337de7d6a4 100644
--- a/net/core/devmem.c
+++ b/net/core/devmem.c
@@ -204,6 +204,7 @@ int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, 
u32 rxq_idx,
 * the driver may read this config while it's creating its * rx-queues.
 * WRITE_ONCE() here to match the READ_ONCE() in the driver.
 */
+   WRITE_ONCE(rxq->mp_params.mp_ops, &dmabuf_devmem_ops);
WRITE_ONCE(rxq->mp_params.mp_priv, binding);
 
err = net_devmem_restart_rx_queue(dev, rxq_idx);
@@ -340,3 +341,85 @@ int net_devmem_bind_dmabuf(struct net_device *dev, 
unsigned int dmabuf_fd,
return err;
 }
 #endif
+
+/*** "Dmabuf devmem memory provider" ***/
+
+static int mp_dmabuf_devmem_init(struct page_pool *pool)
+{
+   struct net_devmem_dmabuf_binding *binding = pool->mp_priv;
+
+   if (!binding)
+   return -EINVAL;
+
+   if (!(pool->p.flags & PP_FLAG_DMA_MAP))
+   return -EOPNOTSUPP;
+
+   if (pool->p.flags & PP_FLAG_DMA_SYNC_DEV)
+   return -EOPNOTSUPP;
+
+ 

[RFC PATCH net-next v8 07/14] page_pool: devmem support

2024-04-02 Thread Mina Almasry
Convert netmem to be a union of struct page and struct netmem. Overload
the LSB of struct netmem* to indicate that it's a net_iov, otherwise
it's a page.

Currently these entries in struct page are rented by the page_pool and
used exclusively by the net stack:

struct {
unsigned long pp_magic;
struct page_pool *pp;
unsigned long _pp_mapping_pad;
unsigned long dma_addr;
atomic_long_t pp_ref_count;
};

Mirror these (and only these) entries into struct net_iov and implement
netmem helpers that can access these common fields regardless of
whether the underlying type is page or net_iov.

Implement checks for net_iov in netmem helpers which delegate to mm
APIs, to ensure net_iov are never passed to the mm stack.

Signed-off-by: Mina Almasry 

---

v7:
- Remove static_branch_unlikely from netmem_to_net_iov(). We're getting
  better results from the fast path in bench_page_pool_simple tests
  without the static_branch_unlikely, and the addition of
  static_branch_unlikely doesn't improve performance of devmem TCP.

  Additionally only check netmem_to_net_iov() if
  CONFIG_DMA_SHARED_BUFFER is enabled, otherwise dmabuf net_iovs cannot
  exist anyway.

  net-next base: 8 cycle fast path.
  with static_branch_unlikely: 10 cycle fast path.
  without static_branch_unlikely: 9 cycle fast path.
  CONFIG_DMA_SHARED_BUFFER disabled: 8 cycle fast path as baseline.

  Performance of devmem TCP is at 95% line rate is regardless of
  static_branch_unlikely or not.

v6:
- Rebased on top of the merged netmem_ref type.
- Rebased on top of the merged skb_pp_frag_ref() changes.

v5:
- Use netmem instead of page* with LSB set.
- Use pp_ref_count for refcounting net_iov.
- Removed many of the custom checks for netmem.

v1:
- Disable fragmentation support for iov properly.
- fix napi_pp_put_page() path (Yunsheng).
- Use pp_frag_count for devmem refcounting.

Cc: linux...@kvack.org
Cc: Matthew Wilcox 

---
 include/net/netmem.h| 141 ++--
 include/net/page_pool/helpers.h |  25 +++---
 net/core/devmem.c   |   3 +
 net/core/page_pool.c|  26 +++---
 net/core/skbuff.c   |  23 +++---
 5 files changed, 172 insertions(+), 46 deletions(-)

diff --git a/include/net/netmem.h b/include/net/netmem.h
index 5f1c728618f2..74eeaa34883e 100644
--- a/include/net/netmem.h
+++ b/include/net/netmem.h
@@ -9,14 +9,51 @@
 #define _NET_NETMEM_H
 
 #include 
+#include 
 
 /* net_iov */
 
+DECLARE_STATIC_KEY_FALSE(page_pool_mem_providers);
+
+/*  We overload the LSB of the struct page pointer to indicate whether it's
+ *  a page or net_iov.
+ */
+#define NET_IOV 0x01UL
+
 struct net_iov {
+   unsigned long __unused_padding;
+   unsigned long pp_magic;
+   struct page_pool *pp;
struct dmabuf_genpool_chunk_owner *owner;
unsigned long dma_addr;
+   atomic_long_t pp_ref_count;
 };
 
+/* These fields in struct page are used by the page_pool and net stack:
+ *
+ * struct {
+ * unsigned long pp_magic;
+ * struct page_pool *pp;
+ * unsigned long _pp_mapping_pad;
+ * unsigned long dma_addr;
+ * atomic_long_t pp_ref_count;
+ * };
+ *
+ * We mirror the page_pool fields here so the page_pool can access these fields
+ * without worrying whether the underlying fields belong to a page or net_iov.
+ *
+ * The non-net stack fields of struct page are private to the mm stack and must
+ * never be mirrored to net_iov.
+ */
+#define NET_IOV_ASSERT_OFFSET(pg, iov) \
+   static_assert(offsetof(struct page, pg) == \
+ offsetof(struct net_iov, iov))
+NET_IOV_ASSERT_OFFSET(pp_magic, pp_magic);
+NET_IOV_ASSERT_OFFSET(pp, pp);
+NET_IOV_ASSERT_OFFSET(dma_addr, dma_addr);
+NET_IOV_ASSERT_OFFSET(pp_ref_count, pp_ref_count);
+#undef NET_IOV_ASSERT_OFFSET
+
 static inline struct dmabuf_genpool_chunk_owner *
 net_iov_owner(const struct net_iov *niov)
 {
@@ -69,20 +106,26 @@ net_iov_binding(const struct net_iov *niov)
  */
 typedef unsigned long __bitwise netmem_ref;
 
+static inline bool netmem_is_net_iov(const netmem_ref netmem)
+{
+#if defined(CONFIG_PAGE_POOL) && defined(CONFIG_DMA_SHARED_BUFFER)
+   return (__force unsigned long)netmem & NET_IOV;
+#else
+   return false;
+#endif
+}
+
 /* This conversion fails (returns NULL) if the netmem_ref is not struct page
  * backed.
- *
- * Currently struct page is the only possible netmem, and this helper never
- * fails.
  */
 static inline struct page *netmem_to_page(netmem_ref netmem)
 {
+   if (WARN_ON_ONCE(netmem_is_net_iov(netmem)))
+   return NULL;
+
return (__force struct page *)netmem;
 }
 
-/* Converting from page to netmem is always safe, because a page can always be
- * a netmem.
- */
 static inline netmem_ref page_to_netmem(struct page *page)
 {
return (__force netmem_ref)page;
@@ -90,17 +133,103 @@ static inline netmem_ref page_to_netmem(struct page *p

[RFC PATCH net-next v8 06/14] page_pool: convert to use netmem

2024-04-02 Thread Mina Almasry
Abstrace the memory type from the page_pool so we can later add support
for new memory types. Convert the page_pool to use the new netmem type
abstraction, rather than use struct page directly.

As of this patch the netmem type is a no-op abstraction: it's always a
struct page underneath. All the page pool internals are converted to
use struct netmem instead of struct page, and the page pool now exports
2 APIs:

1. The existing struct page API.
2. The new struct netmem API.

Keeping the existing API is transitional; we do not want to refactor all
the current drivers using the page pool at once.

The netmem abstraction is currently a no-op. The page_pool uses
page_to_netmem() to convert allocated pages to netmem, and uses
netmem_to_page() to convert the netmem back to pages to pass to mm APIs,

Follow up patches to this series add non-paged netmem support to the
page_pool. This change is factored out on its own to limit the code
churn to this 1 patch, for ease of code review.

Signed-off-by: Mina Almasry 

---

v8:
- Fix napi_pp_put_page() taking netmem instead of page to fix
  patch-by-patch build error.
- Add net/netmem.h include in this patch to fix patch-by-patch build
  error.

v6:

- Rebased on top of the merged netmem_ref type.

Cc: linux...@kvack.org
Cc: Matthew Wilcox 

---
 include/linux/skbuff.h   |   6 +-
 include/net/netmem.h |  15 ++
 include/net/page_pool/helpers.h  | 122 +
 include/net/page_pool/types.h|  18 +-
 include/trace/events/page_pool.h |  29 +--
 net/bpf/test_run.c   |   5 +-
 net/core/page_pool.c | 303 +--
 net/core/skbuff.c|   7 +-
 8 files changed, 304 insertions(+), 201 deletions(-)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index b7f1ecdaec38..c9659e9d843e 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -3510,13 +3510,13 @@ int skb_pp_cow_data(struct page_pool *pool, struct 
sk_buff **pskb,
unsigned int headroom);
 int skb_cow_data_for_xdp(struct page_pool *pool, struct sk_buff **pskb,
 struct bpf_prog *prog);
-bool napi_pp_put_page(struct page *page, bool napi_safe);
+bool napi_pp_put_page(netmem_ref netmem, bool napi_safe);
 
 static inline void
 skb_page_unref(const struct sk_buff *skb, struct page *page, bool napi_safe)
 {
 #ifdef CONFIG_PAGE_POOL
-   if (skb->pp_recycle && napi_pp_put_page(page, napi_safe))
+   if (skb->pp_recycle && napi_pp_put_page(page_to_netmem(page), 
napi_safe))
return;
 #endif
put_page(page);
@@ -3528,7 +3528,7 @@ napi_frag_unref(skb_frag_t *frag, bool recycle, bool 
napi_safe)
struct page *page = skb_frag_page(frag);
 
 #ifdef CONFIG_PAGE_POOL
-   if (recycle && napi_pp_put_page(page, napi_safe))
+   if (recycle && napi_pp_put_page(page_to_netmem(page), napi_safe))
return;
 #endif
put_page(page);
diff --git a/include/net/netmem.h b/include/net/netmem.h
index 33014370a885..5f1c728618f2 100644
--- a/include/net/netmem.h
+++ b/include/net/netmem.h
@@ -88,4 +88,19 @@ static inline netmem_ref page_to_netmem(struct page *page)
return (__force netmem_ref)page;
 }
 
+static inline int netmem_ref_count(netmem_ref netmem)
+{
+   return page_ref_count(netmem_to_page(netmem));
+}
+
+static inline unsigned long netmem_to_pfn(netmem_ref netmem)
+{
+   return page_to_pfn(netmem_to_page(netmem));
+}
+
+static inline netmem_ref netmem_compound_head(netmem_ref netmem)
+{
+   return page_to_netmem(compound_head(netmem_to_page(netmem)));
+}
+
 #endif /* _NET_NETMEM_H */
diff --git a/include/net/page_pool/helpers.h b/include/net/page_pool/helpers.h
index 1d397c1a0043..61814f91a458 100644
--- a/include/net/page_pool/helpers.h
+++ b/include/net/page_pool/helpers.h
@@ -53,6 +53,8 @@
 #define _NET_PAGE_POOL_HELPERS_H
 
 #include 
+#include 
+#include 
 
 #ifdef CONFIG_PAGE_POOL_STATS
 /* Deprecated driver-facing API, use netlink instead */
@@ -101,7 +103,7 @@ static inline struct page *page_pool_dev_alloc_pages(struct 
page_pool *pool)
  * Get a page fragment from the page allocator or page_pool caches.
  *
  * Return:
- * Return allocated page fragment, otherwise return NULL.
+ * Return allocated page fragment, otherwise return 0.
  */
 static inline struct page *page_pool_dev_alloc_frag(struct page_pool *pool,
unsigned int *offset,
@@ -112,22 +114,22 @@ static inline struct page 
*page_pool_dev_alloc_frag(struct page_pool *pool,
return page_pool_alloc_frag(pool, offset, size, gfp);
 }
 
-static inline struct page *page_pool_alloc(struct page_pool *pool,
-  unsigned int *offset,
-  unsigned int *size, gfp_t gfp)
+static inline netmem_ref page_pool_alloc(struct page_pool *pool,
+unsigned int *offset,
+ 

[RFC PATCH net-next v8 05/14] netdev: netdevice devmem allocator

2024-04-02 Thread Mina Almasry
Implement netdev devmem allocator. The allocator takes a given struct
netdev_dmabuf_binding as input and allocates net_iov from that
binding.

The allocation simply delegates to the binding's genpool for the
allocation logic and wraps the returned memory region in a net_iov
struct.

Signed-off-by: Willem de Bruijn 
Signed-off-by: Kaiyuan Zhang 
Signed-off-by: Mina Almasry 

---

v8:
- Rename netdev_dmabuf_binding -> net_devmem_dmabuf_binding to avoid
  patch-by-patch build error.
- Move niov->pp_magic/pp/pp_ref_counter usage to later patch to avoid
  patch-by-patch build error.

v7:
- netdev_ -> net_devmem_* naming (Yunsheng).

v6:
- Add comment on net_iov_dma_addr to explain why we don't use
  niov->dma_addr (Pavel)
- Refactor new functions into net/core/devmem.c (Pavel)

v1:
- Rename devmem -> dmabuf (David).

---
 include/net/devmem.h | 13 +
 include/net/netmem.h | 40 
 net/core/devmem.c| 36 
 3 files changed, 89 insertions(+)

diff --git a/include/net/devmem.h b/include/net/devmem.h
index fa03bdabdffd..cd3186f5d1fb 100644
--- a/include/net/devmem.h
+++ b/include/net/devmem.h
@@ -68,7 +68,20 @@ int net_devmem_bind_dmabuf(struct net_device *dev, unsigned 
int dmabuf_fd,
 void net_devmem_unbind_dmabuf(struct net_devmem_dmabuf_binding *binding);
 int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,
struct net_devmem_dmabuf_binding *binding);
+struct net_iov *
+net_devmem_alloc_dmabuf(struct net_devmem_dmabuf_binding *binding);
+void net_devmem_free_dmabuf(struct net_iov *ppiov);
 #else
+static inline struct net_iov *
+net_devmem_alloc_dmabuf(struct net_devmem_dmabuf_binding *binding)
+{
+   return NULL;
+}
+
+static inline void net_devmem_free_dmabuf(struct net_iov *ppiov)
+{
+}
+
 static inline void
 __net_devmem_dmabuf_binding_free(struct net_devmem_dmabuf_binding *binding)
 {
diff --git a/include/net/netmem.h b/include/net/netmem.h
index 72e932a1a948..33014370a885 100644
--- a/include/net/netmem.h
+++ b/include/net/netmem.h
@@ -14,8 +14,48 @@
 
 struct net_iov {
struct dmabuf_genpool_chunk_owner *owner;
+   unsigned long dma_addr;
 };
 
+static inline struct dmabuf_genpool_chunk_owner *
+net_iov_owner(const struct net_iov *niov)
+{
+   return niov->owner;
+}
+
+static inline unsigned int net_iov_idx(const struct net_iov *niov)
+{
+   return niov - net_iov_owner(niov)->niovs;
+}
+
+/* This returns the absolute dma_addr_t calculated from
+ * net_iov_owner(niov)->owner->base_dma_addr, not the page_pool-owned
+ * niov->dma_addr.
+ *
+ * The absolute dma_addr_t is a dma_addr_t that is always uncompressed.
+ *
+ * The page_pool-owner niov->dma_addr is the absolute dma_addr compressed into
+ * an unsigned long. Special handling is done when the unsigned long is 32-bit
+ * but the dma_addr_t is 64-bit.
+ *
+ * In general code looking for the dma_addr_t should use net_iov_dma_addr(),
+ * while page_pool code looking for the unsigned long dma_addr which mirrors
+ * the field in struct page should use niov->dma_addr.
+ */
+static inline dma_addr_t net_iov_dma_addr(const struct net_iov *niov)
+{
+   struct dmabuf_genpool_chunk_owner *owner = net_iov_owner(niov);
+
+   return owner->base_dma_addr +
+  ((dma_addr_t)net_iov_idx(niov) << PAGE_SHIFT);
+}
+
+static inline struct net_devmem_dmabuf_binding *
+net_iov_binding(const struct net_iov *niov)
+{
+   return net_iov_owner(niov)->binding;
+}
+
 /* netmem */
 
 /**
diff --git a/net/core/devmem.c b/net/core/devmem.c
index 02a6abaecf40..268fc8455a6d 100644
--- a/net/core/devmem.c
+++ b/net/core/devmem.c
@@ -103,6 +103,42 @@ static int net_devmem_restart_rx_queue(struct net_device 
*dev, int rxq_idx)
return err;
 }
 
+struct net_iov *
+net_devmem_alloc_dmabuf(struct net_devmem_dmabuf_binding *binding)
+{
+   struct dmabuf_genpool_chunk_owner *owner;
+   unsigned long dma_addr;
+   struct net_iov *niov;
+   ssize_t offset;
+   ssize_t index;
+
+   dma_addr = gen_pool_alloc_owner(binding->chunk_pool, PAGE_SIZE,
+   (void **)&owner);
+   if (!dma_addr)
+   return NULL;
+
+   offset = dma_addr - owner->base_dma_addr;
+   index = offset / PAGE_SIZE;
+   niov = &owner->niovs[index];
+
+   niov->dma_addr = 0;
+
+   net_devmem_dmabuf_binding_get(binding);
+
+   return niov;
+}
+
+void net_devmem_free_dmabuf(struct net_iov *niov)
+{
+   struct net_devmem_dmabuf_binding *binding = net_iov_binding(niov);
+   unsigned long dma_addr = net_iov_dma_addr(niov);
+
+   if (gen_pool_has_addr(binding->chunk_pool, dma_addr, PAGE_SIZE))
+   gen_pool_free(binding->chunk_pool, dma_addr, PAGE_SIZE);
+
+   net_devmem_dmabuf_binding_put(binding);
+}
+
 /* Protected by rtnl_lock() */
 static DEFINE_XARRAY_FLAGS(net_devmem_dmabuf_bindings, XA_FLAGS_ALLOC1);
 
-- 
2.44.0.47

[RFC PATCH net-next v8 04/14] netdev: support binding dma-buf to netdevice

2024-04-02 Thread Mina Almasry
Add a netdev_dmabuf_binding struct which represents the
dma-buf-to-netdevice binding. The netlink API will bind the dma-buf to
rx queues on the netdevice. On the binding, the dma_buf_attach
& dma_buf_map_attachment will occur. The entries in the sg_table from
mapping will be inserted into a genpool to make it ready
for allocation.

The chunks in the genpool are owned by a dmabuf_chunk_owner struct which
holds the dma-buf offset of the base of the chunk and the dma_addr of
the chunk. Both are needed to use allocations that come from this chunk.

We create a new type that represents an allocation from the genpool:
net_iov. We setup the net_iov allocation size in the
genpool to PAGE_SIZE for simplicity: to match the PAGE_SIZE normally
allocated by the page pool and given to the drivers.

The user can unbind the dmabuf from the netdevice by closing the netlink
socket that established the binding. We do this so that the binding is
automatically unbound even if the userspace process crashes.

The binding and unbinding leaves an indicator in struct netdev_rx_queue
that the given queue is bound, but the binding doesn't take effect until
the driver actually reconfigures its queues, and re-initializes its page
pool.

The netdev_dmabuf_binding struct is refcounted, and releases its
resources only when all the refs are released.

Signed-off-by: Willem de Bruijn 
Signed-off-by: Kaiyuan Zhang 
Signed-off-by: Mina Almasry 

---

v8:
- move dmabuf_devmem_ops usage to later patch to avoid patch-by-patch
  build error.

v7:
- Use IS_ERR() instead of IS_ERR_OR_NULL() for the dma_buf_get() return
  value.
- Changes netdev_* naming in devmem.c to net_devmem_* (Yunsheng).
- DMA_BIDIRECTIONAL -> DMA_FROM_DEVICE (Yunsheng).
- Added a comment around recovering of the old rx queue in
  net_devmem_restart_rx_queue(), and added freeing of old_mem if the
  restart of the old queue fails. (Yunsheng).
- Use kernel-family sock-priv (Jakub).
- Put pp_memory_provider_params in netdev_rx_queue instead of the
  dma-buf specific binding (Pavel & David).
- Move queue management ops to queue_mgmt_ops instead of netdev_ops
  (Jakub).
- Remove excess whitespaces (Jakub).
- Use genlmsg_iput (Jakub).

v6:
- Validate rx queue index
- Refactor new functions into devmem.c (Pavel)

v5:
- Renamed page_pool_iov to net_iov, and moved that support to devmem.h
  or netmem.h.

v1:

- Introduce devmem.h instead of bloating netdevice.h (Jakub)
- ENOTSUPP -> EOPNOTSUPP (checkpatch.pl I think)
- Remove unneeded rcu protection for binding->list (rtnl protected)
- Removed extraneous err_binding_put: label.
- Removed dma_addr += len (Paolo).
- Don't override err on netdev_bind_dmabuf_to_queue failure.
- Rename devmem -> dmabuf (David).
- Add id to dmabuf binding (David/Stan).
- Fix missing xa_destroy bound_rq_list.
- Use queue api to reset bound RX queues (Jakub).
- Update netlink API for rx-queue type (tx/re) (Jakub).

RFC v3:
- Support multi rx-queue binding

---
 Documentation/netlink/specs/netdev.yaml |   4 +
 include/net/devmem.h| 111 +
 include/net/netdev_rx_queue.h   |   2 +
 include/net/netmem.h|  10 +
 include/net/page_pool/types.h   |   5 +
 net/core/Makefile   |   2 +-
 net/core/dev.c  |   3 +
 net/core/devmem.c   | 303 
 net/core/netdev-genl-gen.c  |   4 +
 net/core/netdev-genl-gen.h  |   4 +
 net/core/netdev-genl.c  | 105 +++-
 11 files changed, 550 insertions(+), 3 deletions(-)
 create mode 100644 include/net/devmem.h
 create mode 100644 net/core/devmem.c

diff --git a/Documentation/netlink/specs/netdev.yaml 
b/Documentation/netlink/specs/netdev.yaml
index 275d1faa87a6..bf4e58dfe9dd 100644
--- a/Documentation/netlink/specs/netdev.yaml
+++ b/Documentation/netlink/specs/netdev.yaml
@@ -550,6 +550,10 @@ operations:
 - tx-packets
 - tx-bytes
 
+kernel-family:
+  headers: [ "linux/list.h"]
+  sock-priv: struct list_head
+
 mcast-groups:
   list:
 -
diff --git a/include/net/devmem.h b/include/net/devmem.h
new file mode 100644
index ..fa03bdabdffd
--- /dev/null
+++ b/include/net/devmem.h
@@ -0,0 +1,111 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Device memory TCP support
+ *
+ * Authors:Mina Almasry 
+ * Willem de Bruijn 
+ * Kaiyuan Zhang 
+ *
+ */
+#ifndef _NET_DEVMEM_H
+#define _NET_DEVMEM_H
+
+struct net_devmem_dmabuf_binding {
+   struct dma_buf *dmabuf;
+   struct dma_buf_attachment *attachment;
+   struct sg_table *sgt;
+   struct net_device *dev;
+   struct gen_pool *chunk_pool;
+
+   /* The user holds a ref (via the netlink API) for as long as they want
+* the binding to remain alive. Each page pool using this binding holds
+* a ref to keep the binding alive. Each allocated net_iov holds a
+* ref.
+*
+* The bind

[RFC PATCH net-next v8 03/14] net: netdev netlink api to bind dma-buf to a net device

2024-04-02 Thread Mina Almasry
API takes the dma-buf fd as input, and binds it to the netdevice. The
user can specify the rx queues to bind the dma-buf to.

Suggested-by: Stanislav Fomichev 
Signed-off-by: Mina Almasry 

---

v7:
- Use flags: [ admin-perm ] instead of a CAP_NET_ADMIN check.

Changes in v1:
- Add rx-queue-type to distingish rx from tx (Jakub)
- Return dma-buf ID from netlink API (David, Stan)

Changes in RFC-v3:
- Support binding multiple rx rx-queues

---
 Documentation/netlink/specs/netdev.yaml | 53 +
 include/uapi/linux/netdev.h | 19 +
 net/core/netdev-genl-gen.c  | 19 +
 net/core/netdev-genl-gen.h  |  2 +
 net/core/netdev-genl.c  |  6 +++
 tools/include/uapi/linux/netdev.h   | 19 +
 6 files changed, 118 insertions(+)

diff --git a/Documentation/netlink/specs/netdev.yaml 
b/Documentation/netlink/specs/netdev.yaml
index 76352dbd2be4..275d1faa87a6 100644
--- a/Documentation/netlink/specs/netdev.yaml
+++ b/Documentation/netlink/specs/netdev.yaml
@@ -268,6 +268,45 @@ attribute-sets:
 name: napi-id
 doc: ID of the NAPI instance which services this queue.
 type: u32
+  -
+name: queue-dmabuf
+attributes:
+  -
+name: type
+doc: rx or tx queue
+type: u8
+enum: queue-type
+  -
+name: idx
+doc: queue index
+type: u32
+
+  -
+name: bind-dmabuf
+attributes:
+  -
+name: ifindex
+doc: netdev ifindex to bind the dma-buf to.
+type: u32
+checks:
+  min: 1
+  -
+name: queues
+doc: receive queues to bind the dma-buf to.
+type: nest
+nested-attributes: queue-dmabuf
+multi-attr: true
+  -
+name: dmabuf-fd
+doc: dmabuf file descriptor to bind.
+type: u32
+  -
+name: dmabuf-id
+doc: id of the dmabuf binding
+type: u32
+checks:
+  min: 1
+
 
   -
 name: qstats
@@ -457,6 +496,20 @@ operations:
   attributes:
 - ifindex
 reply: *queue-get-op
+-
+  name: bind-rx
+  doc: Bind dmabuf to netdev
+  attribute-set: bind-dmabuf
+  flags: [ admin-perm ]
+  do:
+request:
+  attributes:
+- ifindex
+- dmabuf-fd
+- queues
+reply:
+  attributes:
+- dmabuf-id
 -
   name: napi-get
   doc: Get information about NAPI instances configured on the system.
diff --git a/include/uapi/linux/netdev.h b/include/uapi/linux/netdev.h
index bb65ee840cda..c5b959a0ed6c 100644
--- a/include/uapi/linux/netdev.h
+++ b/include/uapi/linux/netdev.h
@@ -136,6 +136,24 @@ enum {
NETDEV_A_QUEUE_MAX = (__NETDEV_A_QUEUE_MAX - 1)
 };
 
+enum {
+   NETDEV_A_QUEUE_DMABUF_TYPE = 1,
+   NETDEV_A_QUEUE_DMABUF_IDX,
+
+   __NETDEV_A_QUEUE_DMABUF_MAX,
+   NETDEV_A_QUEUE_DMABUF_MAX = (__NETDEV_A_QUEUE_DMABUF_MAX - 1)
+};
+
+enum {
+   NETDEV_A_BIND_DMABUF_IFINDEX = 1,
+   NETDEV_A_BIND_DMABUF_QUEUES,
+   NETDEV_A_BIND_DMABUF_DMABUF_FD,
+   NETDEV_A_BIND_DMABUF_DMABUF_ID,
+
+   __NETDEV_A_BIND_DMABUF_MAX,
+   NETDEV_A_BIND_DMABUF_MAX = (__NETDEV_A_BIND_DMABUF_MAX - 1)
+};
+
 enum {
NETDEV_A_QSTATS_IFINDEX = 1,
NETDEV_A_QSTATS_QUEUE_TYPE,
@@ -162,6 +180,7 @@ enum {
NETDEV_CMD_PAGE_POOL_CHANGE_NTF,
NETDEV_CMD_PAGE_POOL_STATS_GET,
NETDEV_CMD_QUEUE_GET,
+   NETDEV_CMD_BIND_RX,
NETDEV_CMD_NAPI_GET,
NETDEV_CMD_QSTATS_GET,
 
diff --git a/net/core/netdev-genl-gen.c b/net/core/netdev-genl-gen.c
index 8d8ace9ef87f..bbaaa1b36b5b 100644
--- a/net/core/netdev-genl-gen.c
+++ b/net/core/netdev-genl-gen.c
@@ -27,6 +27,11 @@ const struct nla_policy 
netdev_page_pool_info_nl_policy[NETDEV_A_PAGE_POOL_IFIND
[NETDEV_A_PAGE_POOL_IFINDEX] = NLA_POLICY_FULL_RANGE(NLA_U32, 
&netdev_a_page_pool_ifindex_range),
 };
 
+const struct nla_policy 
netdev_queue_dmabuf_nl_policy[NETDEV_A_QUEUE_DMABUF_IDX + 1] = {
+   [NETDEV_A_QUEUE_DMABUF_TYPE] = NLA_POLICY_MAX(NLA_U8, 1),
+   [NETDEV_A_QUEUE_DMABUF_IDX] = { .type = NLA_U32, },
+};
+
 /* NETDEV_CMD_DEV_GET - do */
 static const struct nla_policy netdev_dev_get_nl_policy[NETDEV_A_DEV_IFINDEX + 
1] = {
[NETDEV_A_DEV_IFINDEX] = NLA_POLICY_MIN(NLA_U32, 1),
@@ -58,6 +63,13 @@ static const struct nla_policy 
netdev_queue_get_dump_nl_policy[NETDEV_A_QUEUE_IF
[NETDEV_A_QUEUE_IFINDEX] = NLA_POLICY_MIN(NLA_U32, 1),
 };
 
+/* NETDEV_CMD_BIND_RX - do */
+static const struct nla_policy 
netdev_bind_rx_nl_policy[NETDEV_A_BIND_DMABUF_DMABUF_FD + 1] = {
+   [NETDEV_A_BIND_DMABUF_IFINDEX] = NLA_POLICY_MIN(NLA_U32, 1),
+   [NETDEV_A_BIND_DMABUF_DMABUF_FD] = { .type = NLA_U32, },
+   [NETDEV_A_BIND_DMABUF_QUEUES] = 
NLA_POLICY_NESTED(netdev_queue_dmabuf_nl_policy),
+};
+
 /* NETDEV_CMD_NAPI_GET - do */
 static const struct nla_policy netdev_nap

[RFC PATCH net-next v8 02/14] net: page_pool: create hooks for custom page providers

2024-04-02 Thread Mina Almasry
From: Jakub Kicinski 

The page providers which try to reuse the same pages will
need to hold onto the ref, even if page gets released from
the pool - as in releasing the page from the pp just transfers
the "ownership" reference from pp to the provider, and provider
will wait for other references to be gone before feeding this
page back into the pool.

Signed-off-by: Jakub Kicinski 
Signed-off-by: Mina Almasry 

---

This is implemented by Jakub in his RFC:
https://lore.kernel.org/netdev/f8270765-a27b-6ccf-33ea-cda097168...@redhat.com/T/

I take no credit for the idea or implementation; I only added minor
edits to make this workable with device memory TCP, and removed some
hacky test code. This is a critical dependency of device memory TCP
and thus I'm pulling it into this series to make it revewable and
mergeable.

RFC v3 -> v1
- Removed unusued mem_provider. (Yunsheng).
- Replaced memory_provider & mp_priv with netdev_rx_queue (Jakub).

---
 include/net/page_pool/types.h | 12 ++
 net/core/page_pool.c  | 43 +++
 2 files changed, 50 insertions(+), 5 deletions(-)

diff --git a/include/net/page_pool/types.h b/include/net/page_pool/types.h
index 5e43a08d3231..ffe5f31fb0da 100644
--- a/include/net/page_pool/types.h
+++ b/include/net/page_pool/types.h
@@ -52,6 +52,7 @@ struct pp_alloc_cache {
  * @dev:   device, for DMA pre-mapping purposes
  * @netdev:netdev this pool will serve (leave as NULL if none or multiple)
  * @napi:  NAPI which is the sole consumer of pages, otherwise NULL
+ * @queue: struct netdev_rx_queue this page_pool is being created for.
  * @dma_dir:   DMA mapping direction
  * @max_len:   max DMA sync memory size for PP_FLAG_DMA_SYNC_DEV
  * @offset:DMA sync address offset for PP_FLAG_DMA_SYNC_DEV
@@ -64,6 +65,7 @@ struct page_pool_params {
int nid;
struct device   *dev;
struct napi_struct *napi;
+   struct netdev_rx_queue *queue;
enum dma_data_direction dma_dir;
unsigned intmax_len;
unsigned intoffset;
@@ -126,6 +128,13 @@ struct page_pool_stats {
 };
 #endif
 
+struct memory_provider_ops {
+   int (*init)(struct page_pool *pool);
+   void (*destroy)(struct page_pool *pool);
+   struct page *(*alloc_pages)(struct page_pool *pool, gfp_t gfp);
+   bool (*release_page)(struct page_pool *pool, struct page *page);
+};
+
 struct page_pool {
struct page_pool_params_fast p;
 
@@ -176,6 +185,9 @@ struct page_pool {
 */
struct ptr_ring ring;
 
+   void *mp_priv;
+   const struct memory_provider_ops *mp_ops;
+
 #ifdef CONFIG_PAGE_POOL_STATS
/* recycle stats are per-cpu to avoid locking */
struct page_pool_recycle_stats __percpu *recycle_stats;
diff --git a/net/core/page_pool.c b/net/core/page_pool.c
index dd364d738c00..795b7ff1c01f 100644
--- a/net/core/page_pool.c
+++ b/net/core/page_pool.c
@@ -25,6 +25,8 @@
 
 #include "page_pool_priv.h"
 
+static DEFINE_STATIC_KEY_FALSE(page_pool_mem_providers);
+
 #define DEFER_TIME (msecs_to_jiffies(1000))
 #define DEFER_WARN_INTERVAL (60 * HZ)
 
@@ -177,6 +179,7 @@ static int page_pool_init(struct page_pool *pool,
  int cpuid)
 {
unsigned int ring_qsize = 1024; /* Default */
+   int err;
 
memcpy(&pool->p, ¶ms->fast, sizeof(pool->p));
memcpy(&pool->slow, ¶ms->slow, sizeof(pool->slow));
@@ -248,10 +251,25 @@ static int page_pool_init(struct page_pool *pool,
/* Driver calling page_pool_create() also call page_pool_destroy() */
refcount_set(&pool->user_cnt, 1);
 
+   if (pool->mp_ops) {
+   err = pool->mp_ops->init(pool);
+   if (err) {
+   pr_warn("%s() mem-provider init failed %d\n", __func__,
+   err);
+   goto free_ptr_ring;
+   }
+
+   static_branch_inc(&page_pool_mem_providers);
+   }
+
if (pool->p.flags & PP_FLAG_DMA_MAP)
get_device(pool->p.dev);
 
return 0;
+
+free_ptr_ring:
+   ptr_ring_cleanup(&pool->ring, NULL);
+   return err;
 }
 
 static void page_pool_uninit(struct page_pool *pool)
@@ -546,7 +564,10 @@ struct page *page_pool_alloc_pages(struct page_pool *pool, 
gfp_t gfp)
return page;
 
/* Slow-path: cache empty, do real allocation */
-   page = __page_pool_alloc_pages_slow(pool, gfp);
+   if (static_branch_unlikely(&page_pool_mem_providers) && pool->mp_ops)
+   page = pool->mp_ops->alloc_pages(pool, gfp);
+   else
+   page = __page_pool_alloc_pages_slow(pool, gfp);
return page;
 }
 EXPORT_SYMBOL(page_pool_alloc_pages);
@@ -603,10 +624,13 @@ void __page_pool_release_page_dma(struct page_pool *pool, 
struct page *page)
 void page_pool_return_page(struct page_pool *pool, struct page *page)
 {
int 

[RFC PATCH net-next v8 01/14] queue_api: define queue api

2024-04-02 Thread Mina Almasry
This API enables the net stack to reset the queues used for devmem TCP.

Signed-off-by: Mina Almasry 

---
 include/linux/netdevice.h   |  3 +++
 include/net/netdev_queues.h | 27 +++
 2 files changed, 30 insertions(+)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 7d12b5a9380f..a0bd542d143a 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -1957,6 +1957,7 @@ enum netdev_reg_state {
  * @sysfs_rx_queue_group:  Space for optional per-rx queue attributes
  * @rtnl_link_ops: Rtnl_link_ops
  * @stat_ops:  Optional ops for queue-aware statistics
+ * @queue_mgmt_ops:Optional ops for queue management
  *
  * @gso_max_size:  Maximum size of generic segmentation offload
  * @tso_max_size:  Device (as in HW) limit on the max TSO request size
@@ -2339,6 +2340,8 @@ struct net_device {
 
const struct netdev_stat_ops *stat_ops;
 
+   const struct netdev_queue_mgmt_ops *queue_mgmt_ops;
+
/* for setting kernel sock attribute on TCP connection setup */
 #define GSO_MAX_SEGS   65535u
 #define GSO_LEGACY_MAX_SIZE65536u
diff --git a/include/net/netdev_queues.h b/include/net/netdev_queues.h
index 1ec408585373..337df0860ae6 100644
--- a/include/net/netdev_queues.h
+++ b/include/net/netdev_queues.h
@@ -60,6 +60,33 @@ struct netdev_stat_ops {
   struct netdev_queue_stats_tx *tx);
 };
 
+/**
+ * struct netdev_queue_mgmt_ops - netdev ops for queue management
+ *
+ * @ndo_queue_mem_alloc: Allocate memory for an RX queue. The memory returned
+ *  in the form of a void* can be passed to
+ *  ndo_queue_mem_free() for freeing or to ndo_queue_start
+ *  to create an RX queue with this memory.
+ *
+ * @ndo_queue_mem_free:Free memory from an RX queue.
+ *
+ * @ndo_queue_start:   Start an RX queue at the specified index.
+ *
+ * @ndo_queue_stop:Stop the RX queue at the specified index.
+ */
+struct netdev_queue_mgmt_ops {
+   void *  (*ndo_queue_mem_alloc)(struct net_device *dev,
+  int idx);
+   void(*ndo_queue_mem_free)(struct net_device *dev,
+ void *queue_mem);
+   int (*ndo_queue_start)(struct net_device *dev,
+  int idx,
+  void *queue_mem);
+   int (*ndo_queue_stop)(struct net_device *dev,
+ int idx,
+ void **out_queue_mem);
+};
+
 /**
  * DOC: Lockless queue stopping / waking helpers.
  *
-- 
2.44.0.478.gd926399ef9-goog



[RFC PATCH net-next v8 00/14] Device Memory TCP

2024-04-02 Thread Mina Almasry
RFC v8:
===

Major Changes:
--

- Fixed build error generated by patch-by-patch build.
- Applied docs suggestions from Randy.

RFC v7:
===

Major Changes:
--

This revision largely rebases on top of net-next and addresses the feedback
RFCv6 received from folks, namely Jakub, Yunsheng, Arnd, David, & Pavel.

The series remains in RFC because the queue-API ndos defined in this
series are not yet implemented. I have a GVE implementation I carry out
of tree for my testing. A upstreamable GVE implementation is in the
works. Aside from that, in my estimation all the patches are ready for
review/merge. Please do take a look.

As usual the full devmem TCP changes including the full GVE driver
implementation is here:

https://github.com/mina/linux/commits/tcpdevmem-v7/

Detailed changelog:

- Use admin-perm in netlink API.
- Addressed feedback from Jakub with regards to netlink API
  implementation.
- Renamed devmem.c functions to something more appropriate for that
  file.
- Improve the performance seen through the page_pool benchmark.
- Fix the value definition of all the SO_DEVMEM_* uapi.
- Various fixes to documentation.

Perf - page-pool benchmark:
---

Improved performance of bench_page_pool_simple.ko tests compared to v6:

https://pastebin.com/raw/v5dYRg8L

  net-next base: 8 cycle fast path.
  RFC v6: 10 cycle fast path.
  RFC v7: 9 cycle fast path.
  RFC v7 with CONFIG_DMA_SHARED_BUFFER disabled: 8 cycle fast path,
 same as baseline.

Perf - Devmem TCP benchmark:
-

Perf is about the same regardless of the changes in v7, namely the
removal of the static_branch_unlikely to improve the page_pool benchmark
performance:

189/200gbps bi-directional throughput with RX devmem TCP and regular TCP
TX i.e. ~95% line rate.

RFC v6:
===

Major Changes:
--

This revision largely rebases on top of net-next and addresses the little
feedback RFCv5 received.

The series remains in RFC because the queue-API ndos defined in this
series are not yet implemented. I have a GVE implementation I carry out
of tree for my testing. A upstreamable GVE implementation is in the
works. Aside from that, in my estimation all the patches are ready for
review/merge. Please do take a look.

As usual the full devmem TCP changes including the full GVE driver
implementation is here:

https://github.com/mina/linux/commits/tcpdevmem-v6/

This version also comes with some performance data recorded in the cover
letter (see below changelog).

Detailed changelog:

- Rebased on top of the merged netmem_ref changes.

- Converted skb->dmabuf to skb->readable (Pavel). Pavel's original
  suggestion was to remove the skb->dmabuf flag entirely, but when I
  looked into it closely, I found the issue that if we remove the flag
  we have to dereference the shinfo(skb) pointer to obtain the first
  frag to tell whether an skb is readable or not. This can cause a
  performance regression if it dirties the cache line when the
  shinfo(skb) was not really needed. Instead, I converted the skb->dmabuf
  flag into a generic skb->readable flag which can be re-used by io_uring
  0-copy RX.

- Squashed a few locking optimizations from Eric Dumazet in the RX path
  and the DEVMEM_DONTNEED setsockopt.

- Expanded the tests a bit. Added validation for invalid scenarios and
  added some more coverage.

Perf - page-pool benchmark:
---

bench_page_pool_simple.ko tests with and without these changes:
https://pastebin.com/raw/ncHDwAbn

AFAIK the number that really matters in the perf tests is the
'tasklet_page_pool01_fast_path Per elem'. This one measures at about 8
cycles without the changes but there is some 1 cycle noise in some
results.

With the patches this regresses to 9 cycles with the changes but there
is 1 cycle noise occasionally running this test repeatedly.

Lastly I tried disable the static_branch_unlikely() in
netmem_is_net_iov() check. To my surprise disabling the
static_branch_unlikely() check reduces the fast path back to 8 cycles,
but the 1 cycle noise remains.

Perf - Devmem TCP benchmark:
-

189/200gbps bi-directional throughput with RX devmem TCP and regular TCP
TX i.e. ~95% line rate.

Major changes in RFC v5:


1. Rebased on top of 'Abstract page from net stack' series and used the
   new netmem type to refer to LSB set pointers instead of re-using
   struct page.

2. Downgraded this series back to RFC and called it RFC v5. This is
   because this series is now dependent on 'Abstract page from net
   stack'[1] and the queue API. Both are removed from the series to
   reduce the patch # and those bits are fairly independent or
   pre-requisite work.

3. Reworked the page_pool devmem support to use netmem and for some
   more unified handling.

4. Reworked the reference counting of net_iov (renamed from
   page_pool_iov) to use pp_re

Re: [PATCH 1/4] gpu/drm: Add SPDX-license-Identifier tag

2024-04-02 Thread Joe Perches
On Tue, 2024-04-02 at 22:43 +, Nicolas Devos wrote:
> This commit fixes following checkpatch warning:
> WARNING: Missing or malformed SPDX-License-Identifier tag

NAK without specific agreement from Intel.

The existing license in the file is neither GPL nor MIT

> 
> Signed-off-by: Nicolas Devos 
> ---
>  drivers/gpu/drm/drm_connector.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c
> index b0516505f7ae..40350256b1f6 100644
> --- a/drivers/gpu/drm/drm_connector.c
> +++ b/drivers/gpu/drm/drm_connector.c
> @@ -1,3 +1,4 @@
> +// SPDX-License-Identifier: GPL-2.0 or MIT
>  /*
>   * Copyright (c) 2016 Intel Corporation
>   *



linux-next: build failure after merge of the drm-misc tree

2024-04-02 Thread Stephen Rothwell
Hi all,

After merging the drm-misc tree, today's linux-next build
(x86_64_allmodconfig) failed like this:

In file included from drivers/gpu/drm/panthor/panthor_fw.c:19:
drivers/gpu/drm/panthor/panthor_fw.c: In function 'panthor_job_irq_suspend':
drivers/gpu/drm/panthor/panthor_device.h:326:13: error: unused variable 
'cookie' [-Werror=unused-variable]
  326 | int cookie; 
\
  | ^~
drivers/gpu/drm/panthor/panthor_fw.c:979:1: note: in expansion of macro 
'PANTHOR_IRQ_HANDLER'
  979 | PANTHOR_IRQ_HANDLER(job, JOB, panthor_job_irq_handler);
  | ^~~
drivers/gpu/drm/panthor/panthor_fw.c: In function 'panthor_job_irq_resume':
drivers/gpu/drm/panthor/panthor_device.h:336:13: error: unused variable 
'cookie' [-Werror=unused-variable]
  336 | int cookie; 
\
  | ^~
drivers/gpu/drm/panthor/panthor_fw.c:979:1: note: in expansion of macro 
'PANTHOR_IRQ_HANDLER'
  979 | PANTHOR_IRQ_HANDLER(job, JOB, panthor_job_irq_handler);
  | ^~~
cc1: all warnings being treated as errors
In file included from drivers/gpu/drm/panthor/panthor_gpu.c:19:
drivers/gpu/drm/panthor/panthor_gpu.c: In function 'panthor_gpu_irq_suspend':
drivers/gpu/drm/panthor/panthor_device.h:326:13: error: unused variable 
'cookie' [-Werror=unused-variable]
  326 | int cookie; 
\
  | ^~
drivers/gpu/drm/panthor/panthor_gpu.c:166:1: note: in expansion of macro 
'PANTHOR_IRQ_HANDLER'
  166 | PANTHOR_IRQ_HANDLER(gpu, GPU, panthor_gpu_irq_handler);
  | ^~~
drivers/gpu/drm/panthor/panthor_gpu.c: In function 'panthor_gpu_irq_resume':
drivers/gpu/drm/panthor/panthor_device.h:336:13: error: unused variable 
'cookie' [-Werror=unused-variable]
  336 | int cookie; 
\
  | ^~
drivers/gpu/drm/panthor/panthor_gpu.c:166:1: note: in expansion of macro 
'PANTHOR_IRQ_HANDLER'
  166 | PANTHOR_IRQ_HANDLER(gpu, GPU, panthor_gpu_irq_handler);
  | ^~~
cc1: all warnings being treated as errors
In file included from drivers/gpu/drm/panthor/panthor_mmu.c:30:
drivers/gpu/drm/panthor/panthor_mmu.c: In function 'panthor_mmu_irq_suspend':
drivers/gpu/drm/panthor/panthor_device.h:326:13: error: unused variable 
'cookie' [-Werror=unused-variable]
  326 | int cookie; 
\
  | ^~
drivers/gpu/drm/panthor/panthor_mmu.c:1689:1: note: in expansion of macro 
'PANTHOR_IRQ_HANDLER'
 1689 | PANTHOR_IRQ_HANDLER(mmu, MMU, panthor_mmu_irq_handler);
  | ^~~
drivers/gpu/drm/panthor/panthor_mmu.c: In function 'panthor_mmu_irq_resume':
drivers/gpu/drm/panthor/panthor_device.h:336:13: error: unused variable 
'cookie' [-Werror=unused-variable]
  336 | int cookie; 
\
  | ^~
drivers/gpu/drm/panthor/panthor_mmu.c:1689:1: note: in expansion of macro 
'PANTHOR_IRQ_HANDLER'
 1689 | PANTHOR_IRQ_HANDLER(mmu, MMU, panthor_mmu_irq_handler);
  | ^~~
cc1: all warnings being treated as errors

Caused by commit

  962f88b9c916 ("drm/panthor: Drop the dev_enter/exit() sections in 
_irq_suspend/resume()")

I have used the drm-misc tree from next-20240402 for today.

-- 
Cheers,
Stephen Rothwell


pgphtSsyRPklj.pgp
Description: OpenPGP digital signature


[PATCH 4/5] drm/vmwgfx: Fix crtc's atomic check conditional

2024-04-02 Thread Zack Rusin
The conditional was supposed to prevent enabling of a crtc state
without a set primary plane. Accidently it also prevented disabling
crtc state with a set primary plane. Neither is correct.

Fix the conditional and just driver-warn when a crtc state has been
enabled without a primary plane which will help debug broken userspace.

Fixes IGT's kms_atomic_interruptible and kms_atomic_transition tests.

Signed-off-by: Zack Rusin 
Fixes: 06ec41909e31 ("drm/vmwgfx: Add and connect CRTC helper functions")
Cc: Broadcom internal kernel review list 
Cc: dri-devel@lists.freedesktop.org
Cc:  # v4.12+
---
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
index e33e5993d8fc..13b2820cae51 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -931,6 +931,7 @@ int vmw_du_cursor_plane_atomic_check(struct drm_plane 
*plane,
 int vmw_du_crtc_atomic_check(struct drm_crtc *crtc,
 struct drm_atomic_state *state)
 {
+   struct vmw_private *vmw = vmw_priv(crtc->dev);
struct drm_crtc_state *new_state = drm_atomic_get_new_crtc_state(state,
 crtc);
struct vmw_display_unit *du = vmw_crtc_to_du(new_state->crtc);
@@ -938,9 +939,13 @@ int vmw_du_crtc_atomic_check(struct drm_crtc *crtc,
bool has_primary = new_state->plane_mask &
   drm_plane_mask(crtc->primary);
 
-   /* We always want to have an active plane with an active CRTC */
-   if (has_primary != new_state->enable)
-   return -EINVAL;
+   /*
+* This is fine in general, but broken userspace might expect
+* some actual rendering so give a clue as why it's blank.
+*/
+   if (new_state->enable && !has_primary)
+   drm_dbg_driver(&vmw->drm,
+  "CRTC without a primary plane will be blank.\n");
 
 
if (new_state->connector_mask != connector_mask &&
-- 
2.40.1



[PATCH 5/5] drm/vmwgfx: Sort primary plane formats by order of preference

2024-04-02 Thread Zack Rusin
The table of primary plane formats wasn't sorted at all, leading to
applications picking our least desirable formats by defaults.

Sort the primary plane formats according to our order of preference.
Fixes IGT's kms_atomic plane-invalid-params which assumes that the
preferred format is a 32bpp format.

Signed-off-by: Zack Rusin 
Fixes: 36cc79bc9077 ("drm/vmwgfx: Add universal plane support")
Cc: Broadcom internal kernel review list 
Cc: dri-devel@lists.freedesktop.org
Cc:  # v4.12+
---
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.h 
b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.h
index bf9931e3a728..bf24f2f0dcfc 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.h
@@ -233,10 +233,10 @@ struct vmw_framebuffer_bo {
 
 
 static const uint32_t __maybe_unused vmw_primary_plane_formats[] = {
-   DRM_FORMAT_XRGB1555,
-   DRM_FORMAT_RGB565,
DRM_FORMAT_XRGB,
DRM_FORMAT_ARGB,
+   DRM_FORMAT_RGB565,
+   DRM_FORMAT_XRGB1555,
 };
 
 static const uint32_t __maybe_unused vmw_cursor_plane_formats[] = {
-- 
2.40.1



[PATCH 3/5] drm/vmwgfx: Fix prime import/export

2024-04-02 Thread Zack Rusin
vmwgfx never supported prime import of external buffers. Furthermore the
driver exposes two different objects to userspace: vmw_surface's and
gem buffers but prime import/export only worked with vmw_surfaces.

Because gem buffers are used through the dumb_buffer interface this meant
that the driver created buffers couldn't have been prime exported or
imported.

Fix prime import/export. Makes IGT's kms_prime pass.

Signed-off-by: Zack Rusin 
Fixes: 8afa13a0583f ("drm/vmwgfx: Implement DRIVER_GEM")
Cc:  # v6.6+
---
 drivers/gpu/drm/vmwgfx/vmwgfx_blit.c   | 35 +++--
 drivers/gpu/drm/vmwgfx/vmwgfx_bo.c |  7 ++--
 drivers/gpu/drm/vmwgfx/vmwgfx_bo.h |  2 +
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c|  1 +
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h|  3 ++
 drivers/gpu/drm/vmwgfx/vmwgfx_gem.c| 32 
 drivers/gpu/drm/vmwgfx/vmwgfx_prime.c  | 15 +++-
 drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c | 44 +++---
 8 files changed, 117 insertions(+), 22 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c
index c52c7bf1485b..717d624e9a05 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c
@@ -456,8 +456,10 @@ int vmw_bo_cpu_blit(struct ttm_buffer_object *dst,
.no_wait_gpu = false
};
u32 j, initial_line = dst_offset / dst_stride;
-   struct vmw_bo_blit_line_data d;
+   struct vmw_bo_blit_line_data d = {0};
int ret = 0;
+   struct page **dst_pages = NULL;
+   struct page **src_pages = NULL;
 
/* Buffer objects need to be either pinned or reserved: */
if (!(dst->pin_count))
@@ -477,12 +479,35 @@ int vmw_bo_cpu_blit(struct ttm_buffer_object *dst,
return ret;
}
 
+   if (!src->ttm->pages && src->ttm->sg) {
+   src_pages = kvmalloc_array(src->ttm->num_pages,
+  sizeof(struct page *), GFP_KERNEL);
+   if (!src_pages)
+   return -ENOMEM;
+   ret = drm_prime_sg_to_page_array(src->ttm->sg, src_pages,
+src->ttm->num_pages);
+   if (ret)
+   goto out;
+   }
+   if (!dst->ttm->pages && dst->ttm->sg) {
+   dst_pages = kvmalloc_array(dst->ttm->num_pages,
+  sizeof(struct page *), GFP_KERNEL);
+   if (!dst_pages) {
+   ret = -ENOMEM;
+   goto out;
+   }
+   ret = drm_prime_sg_to_page_array(dst->ttm->sg, dst_pages,
+dst->ttm->num_pages);
+   if (ret)
+   goto out;
+   }
+
d.mapped_dst = 0;
d.mapped_src = 0;
d.dst_addr = NULL;
d.src_addr = NULL;
-   d.dst_pages = dst->ttm->pages;
-   d.src_pages = src->ttm->pages;
+   d.dst_pages = dst->ttm->pages ? dst->ttm->pages : dst_pages;
+   d.src_pages = src->ttm->pages ? src->ttm->pages : src_pages;
d.dst_num_pages = PFN_UP(dst->resource->size);
d.src_num_pages = PFN_UP(src->resource->size);
d.dst_prot = ttm_io_prot(dst, dst->resource, PAGE_KERNEL);
@@ -504,6 +529,10 @@ int vmw_bo_cpu_blit(struct ttm_buffer_object *dst,
kunmap_atomic(d.src_addr);
if (d.dst_addr)
kunmap_atomic(d.dst_addr);
+   if (src_pages)
+   kvfree(src_pages);
+   if (dst_pages)
+   kvfree(dst_pages);
 
return ret;
 }
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
index bfd41ce3c8f4..e5eb21a471a6 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
@@ -377,7 +377,8 @@ static int vmw_bo_init(struct vmw_private *dev_priv,
 {
struct ttm_operation_ctx ctx = {
.interruptible = params->bo_type != ttm_bo_type_kernel,
-   .no_wait_gpu = false
+   .no_wait_gpu = false,
+   .resv = params->resv,
};
struct ttm_device *bdev = &dev_priv->bdev;
struct drm_device *vdev = &dev_priv->drm;
@@ -394,8 +395,8 @@ static int vmw_bo_init(struct vmw_private *dev_priv,
 
vmw_bo_placement_set(vmw_bo, params->domain, params->busy_domain);
ret = ttm_bo_init_reserved(bdev, &vmw_bo->tbo, params->bo_type,
-  &vmw_bo->placement, 0, &ctx, NULL,
-  NULL, destroy);
+  &vmw_bo->placement, 0, &ctx,
+  params->sg, params->resv, destroy);
if (unlikely(ret))
return ret;
 
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.h 
b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.h
index 0d496dc9c6af..f349642e6190 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.h
+

[PATCH 2/5] drm/vmwgfx: Implement virtual crc generation

2024-04-02 Thread Zack Rusin
crc checksums are used to validate the output. Normally they're part
of the actual display hardware but on virtual stack there's nothing
to automatically generate them.

Implement crc generation for the vmwgfx stack. This works only on
screen targets, where it's possibly to easily make sure that the
guest side contents of the surface matches the host sides output.

Just like the vblank support, crc generation can only be enabled via:
guestinfo.vmwgfx.vkms_enable = "TRUE"
option in the vmx file.

Makes IGT's kms_pipe_crc_basic pass and allows a huge number of other
IGT tests which require CRC generation of the output to actually run
on vmwgfx. Makes it possible to actually validate a lof of the kms and
drm functionality with vmwgfx.

Signed-off-by: Zack Rusin 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c  |   1 +
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h  |   2 +
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c  |  31 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.h  |  15 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_resource.c |  32 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c |  22 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c | 453 ++-
 drivers/gpu/drm/vmwgfx/vmwgfx_vkms.h |  28 +-
 8 files changed, 550 insertions(+), 34 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index e34c48fd25d4..89d3679d2608 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -1198,6 +1198,7 @@ static void vmw_driver_unload(struct drm_device *dev)
 
vmw_svga_disable(dev_priv);
 
+   vmw_vkms_cleanup(dev_priv);
vmw_kms_close(dev_priv);
vmw_overlay_close(dev_priv);
 
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h 
b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index 4f5d7d13c4aa..ddbceaa31b59 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -616,6 +616,7 @@ struct vmw_private {
uint32 *devcaps;
 
bool vkms_enabled;
+   struct workqueue_struct *crc_workq;
 
/*
 * mksGuestStat instance-descriptor and pid arrays
@@ -811,6 +812,7 @@ void vmw_resource_mob_attach(struct vmw_resource *res);
 void vmw_resource_mob_detach(struct vmw_resource *res);
 void vmw_resource_dirty_update(struct vmw_resource *res, pgoff_t start,
   pgoff_t end);
+int vmw_resource_clean(struct vmw_resource *res);
 int vmw_resources_clean(struct vmw_bo *vbo, pgoff_t start,
pgoff_t end, pgoff_t *num_prefault);
 
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
index e763cf0e6cfc..e33e5993d8fc 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -40,14 +40,14 @@
 
 void vmw_du_init(struct vmw_display_unit *du)
 {
-   hrtimer_init(&du->vkms.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
-   du->vkms.timer.function = &vmw_vkms_vblank_simulate;
+   vmw_vkms_crtc_init(&du->crtc);
 }
 
 void vmw_du_cleanup(struct vmw_display_unit *du)
 {
struct vmw_private *dev_priv = vmw_priv(du->primary.dev);
-   hrtimer_cancel(&du->vkms.timer);
+
+   vmw_vkms_crtc_cleanup(&du->crtc);
drm_plane_cleanup(&du->primary);
if (vmw_cmd_supported(dev_priv))
drm_plane_cleanup(&du->cursor.base);
@@ -963,6 +963,7 @@ int vmw_du_crtc_atomic_check(struct drm_crtc *crtc,
 void vmw_du_crtc_atomic_begin(struct drm_crtc *crtc,
  struct drm_atomic_state *state)
 {
+   vmw_vkms_crtc_atomic_begin(crtc, state);
 }
 
 /**
@@ -2029,6 +2030,29 @@ vmw_kms_create_hotplug_mode_update_property(struct 
vmw_private *dev_priv)
  "hotplug_mode_update", 0, 1);
 }
 
+static void
+vmw_atomic_commit_tail(struct drm_atomic_state *old_state)
+{
+   struct vmw_private *vmw = vmw_priv(old_state->dev);
+   struct drm_crtc *crtc;
+   struct drm_crtc_state *old_crtc_state;
+   int i;
+
+   drm_atomic_helper_commit_tail(old_state);
+
+   if (vmw->vkms_enabled) {
+   for_each_old_crtc_in_state(old_state, crtc, old_crtc_state, i) {
+   struct vmw_display_unit *du = vmw_crtc_to_du(crtc);
+   (void)old_crtc_state;
+   flush_work(&du->vkms.crc_generator_work);
+   }
+   }
+}
+
+static const struct drm_mode_config_helper_funcs vmw_mode_config_helpers = {
+   .atomic_commit_tail = vmw_atomic_commit_tail,
+};
+
 int vmw_kms_init(struct vmw_private *dev_priv)
 {
struct drm_device *dev = &dev_priv->drm;
@@ -2048,6 +2072,7 @@ int vmw_kms_init(struct vmw_private *dev_priv)
dev->mode_config.max_width = dev_priv->texture_max_width;
dev->mode_config.max_height = dev_priv->texture_max_height;
dev->mode_config.preferred_depth = dev_priv->assume_16bpp ? 16 : 32;
+   dev->mode_config.helper_private = &vmw_mode_config_helpers;
 
drm_mode_create_sug

[PATCH 1/5] drm/vmwgfx: Implement virtual kms

2024-04-02 Thread Zack Rusin
By default vmwgfx doesn't support vblanking or crc generation which
makes it impossible to use various IGT tests to validate vmwgfx.
Implement virtual kernel mode setting, which is mainly related to
simulated vblank support.

Code is very similar to amd's vkms and the vkms module itself, except
that it's integrated with vmwgfx three different output technologies -
legacy, screen object and screen targets.

Make IGT's kms_vblank pass on vmwgfx and allows a lot of other IGT
tests to run with vmwgfx.

Support for vkms needs to be manually enabled by adding:
guestinfo.vmwgfx.vkms_enable = "TRUE"
somewhere in the vmx file, otherwise it's off by default.

Signed-off-by: Zack Rusin 
---
 drivers/gpu/drm/vmwgfx/Makefile  |   2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c  |   3 +
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h  |   2 +
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c  |  15 ++-
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.h  |   9 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c  |  39 ++
 drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c |  28 ++--
 drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c |  22 +--
 drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c | 193 +++
 drivers/gpu/drm/vmwgfx/vmwgfx_vkms.h |  53 
 10 files changed, 302 insertions(+), 64 deletions(-)
 create mode 100644 drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c
 create mode 100644 drivers/gpu/drm/vmwgfx/vmwgfx_vkms.h

diff --git a/drivers/gpu/drm/vmwgfx/Makefile b/drivers/gpu/drm/vmwgfx/Makefile
index e94479d9cd5b..46a4ab688a7f 100644
--- a/drivers/gpu/drm/vmwgfx/Makefile
+++ b/drivers/gpu/drm/vmwgfx/Makefile
@@ -10,6 +10,6 @@ vmwgfx-y := vmwgfx_execbuf.o vmwgfx_gmr.o vmwgfx_kms.o 
vmwgfx_drv.o \
vmwgfx_simple_resource.o vmwgfx_va.o vmwgfx_blit.o \
vmwgfx_validation.o vmwgfx_page_dirty.o vmwgfx_streamoutput.o \
vmwgfx_devcaps.o ttm_object.o vmwgfx_system_manager.o \
-   vmwgfx_gem.o
+   vmwgfx_gem.o vmwgfx_vkms.o
 
 obj-$(CONFIG_DRM_VMWGFX) := vmwgfx.o
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index c7d90f96d16a..e34c48fd25d4 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -32,6 +32,7 @@
 #include "vmwgfx_binding.h"
 #include "vmwgfx_devcaps.h"
 #include "vmwgfx_mksstat.h"
+#include "vmwgfx_vkms.h"
 #include "ttm_object.h"
 
 #include 
@@ -910,6 +911,8 @@ static int vmw_driver_load(struct vmw_private *dev_priv, 
u32 pci_id)
 "Please switch to a supported graphics device to 
avoid problems.");
}
 
+   vmw_vkms_init(dev_priv);
+
ret = vmw_dma_select_mode(dev_priv);
if (unlikely(ret != 0)) {
drm_info(&dev_priv->drm,
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h 
b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index 01f41fbb9c3b..4f5d7d13c4aa 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -615,6 +615,8 @@ struct vmw_private {
 
uint32 *devcaps;
 
+   bool vkms_enabled;
+
/*
 * mksGuestStat instance-descriptor and pid arrays
 */
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
index 09214f9339b2..e763cf0e6cfc 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -27,6 +27,7 @@
 #include "vmwgfx_kms.h"
 
 #include "vmwgfx_bo.h"
+#include "vmwgfx_vkms.h"
 #include "vmw_surface_cache.h"
 
 #include 
@@ -37,9 +38,16 @@
 #include 
 #include 
 
+void vmw_du_init(struct vmw_display_unit *du)
+{
+   hrtimer_init(&du->vkms.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
+   du->vkms.timer.function = &vmw_vkms_vblank_simulate;
+}
+
 void vmw_du_cleanup(struct vmw_display_unit *du)
 {
struct vmw_private *dev_priv = vmw_priv(du->primary.dev);
+   hrtimer_cancel(&du->vkms.timer);
drm_plane_cleanup(&du->primary);
if (vmw_cmd_supported(dev_priv))
drm_plane_cleanup(&du->cursor.base);
@@ -957,13 +965,6 @@ void vmw_du_crtc_atomic_begin(struct drm_crtc *crtc,
 {
 }
 
-
-void vmw_du_crtc_atomic_flush(struct drm_crtc *crtc,
- struct drm_atomic_state *state)
-{
-}
-
-
 /**
  * vmw_du_crtc_duplicate_state - duplicate crtc state
  * @crtc: DRM crtc
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.h 
b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.h
index 4a2e3cac1c22..9e83a1553286 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.h
@@ -376,6 +376,12 @@ struct vmw_display_unit {
bool is_implicit;
int set_gui_x;
int set_gui_y;
+
+   struct {
+   struct hrtimer timer;
+   ktime_t period_ns;
+   struct drm_pending_vblank_event *event;
+   } vkms;
 };
 
 #define vmw_crtc_to_du(x) \
@@ -387,6 +393,7 @@ struct vmw_display_unit {
 /*
  * Shared display unit functions - vmwgfx_kms.c
  */
+void vmw_du_init(struct vmw_display_unit *du);
 void vmw_du_cleanup(struct vmw_display_unit *du);
 void

[PATCH 0/5] drm/vmwgfx: vblank and crc generation support

2024-04-02 Thread Zack Rusin
vmwgfx didn't have support for vblank or crc generation which made it
impossible to use a large number of IGT tests to properly test DRM
functionality in the driver.

This series add virtual vblank and crc generation support, which allows
running most of IGT and immediately helped fix a number of kms issues
in the driver.

Zack Rusin (5):
  drm/vmwgfx: Implement virtual kms
  drm/vmwgfx: Implement virtual crc generation
  drm/vmwgfx: Fix prime import/export
  drm/vmwgfx: Fix crtc's atomic check conditional
  drm/vmwgfx: Sort primary plane formats by order of preference

 drivers/gpu/drm/vmwgfx/Makefile|   2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_blit.c   |  35 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_bo.c |   7 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_bo.h |   2 +
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c|   5 +
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h|   7 +
 drivers/gpu/drm/vmwgfx/vmwgfx_gem.c|  32 ++
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c|  51 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.h|  26 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c|  39 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_prime.c  |  15 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_resource.c   |  32 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c   |  28 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c   |  42 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c |  44 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c   | 630 +
 drivers/gpu/drm/vmwgfx/vmwgfx_vkms.h   |  75 +++
 17 files changed, 963 insertions(+), 109 deletions(-)
 create mode 100644 drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c
 create mode 100644 drivers/gpu/drm/vmwgfx/vmwgfx_vkms.h

-- 
2.40.1



Re: Cross-device and cross-driver HMM support

2024-04-02 Thread Dave Airlie
On Wed, 27 Mar 2024 at 19:52, Thomas Hellström
 wrote:
>
> Hi!
>
> With our SVM mirror work we'll soon start looking at HMM cross-device
> support. The identified needs are
>
> 1) Instead of migrating foreign device memory to system when the
> current device is faulting, leave it in place...
> 1a) for access using internal interconnect,
> 1b) for access using PCIE p2p (probably mostly as a reference)
>
> 2) Request a foreign device to migrate memory range a..b of a CPU
> mm_struct to local shareable device memory on that foreign device.
>
> and we plan to add an infrastructure for this. Probably this can be
> done initially without too much (or any) changes to the hmm code
> itself.
>
> So the question is basically whether anybody is interested in a
> drm-wide solution for this and in that case also whether anybody sees
> the need for cross-driver support?
>
> Otherwise any objections against us starting out with an xe driver
> helper implementation that could be lifted to drm-level when needed?

I think you'd probably have a better chance of getting others to help
review it, if we started out outside the driver as much as possible.

I don't think gpuvm would have worked out as well if we'd just kept it
inside nouveau from the start, it at least forces you to think about
what should be driver specific here.

> Finally any suggestions or pointers to existing solutions for this?

I think nvidia's uvm might have some of this type of code, but no idea
how you'd even consider starting to use it as a reference,

Dave.


RE: [PATCH v2 4/4] drm: xlnx: zynqmp_dpsub: Add DP audio support

2024-04-02 Thread Klymenko, Anatoliy
Hi Tomi,

> -Original Message-
> From: Tomi Valkeinen 
> Sent: Tuesday, March 19, 2024 1:23 AM
> To: Lars-Peter Clausen ; Jaroslav Kysela
> ; Takashi Iwai ; Liam Girdwood
> ; Mark Brown ; Laurent
> Pinchart ; Maarten Lankhorst
> ; Maxime Ripard
> ; Thomas Zimmermann ;
> David Airlie ; Daniel Vetter ; Rob
> Herring ; Krzysztof Kozlowski
> ; Conor Dooley
> ; Simek, Michal 
> Cc: linux-so...@vger.kernel.org; linux-ker...@vger.kernel.org; dri-
> de...@lists.freedesktop.org; devicet...@vger.kernel.org; linux-arm-
> ker...@lists.infradead.org; Sagar, Vishal ;
> Klymenko, Anatoliy ; Péter Ujfalusi
> ; Tomi Valkeinen
> 
> Subject: [PATCH v2 4/4] drm: xlnx: zynqmp_dpsub: Add DP audio support
> 
> Caution: This message originated from an External Source. Use proper
> caution when opening attachments, clicking links, or responding.
> 
> 
> Add basic DisplayPort audio support.
> 
> Support non-live audio playback from two PCMs (DMA channels), and
> the
> volume control in the audio mixer.
> 
> As older dtb files may not have the audio DMA channels defined, the
> driver will just mark the audio support as disabled if the audio DMA is
> missing, and will continue with only display support.
> 
> Note: Reset doesn't seem to work (ZYNQMP_DISP_AUD_SOFT_RESET). If
> we do
> a reset, audio playback won't start again even if, afaics, we do set up
> all the necessary registers. So, at the moment, resetting the audio
> block in dp_dai_hw_free() is commented out.
> 
> Signed-off-by: Tomi Valkeinen 

Tested-by: Anatoliy Klymenko 

> ---
>  drivers/gpu/drm/xlnx/Kconfig|   9 +
>  drivers/gpu/drm/xlnx/Makefile   |   1 +
>  drivers/gpu/drm/xlnx/zynqmp_disp.c  |  50 
>  drivers/gpu/drm/xlnx/zynqmp_disp_regs.h |   7 +-
>  drivers/gpu/drm/xlnx/zynqmp_dp.c|  54 ++--
>  drivers/gpu/drm/xlnx/zynqmp_dp.h|   7 +
>  drivers/gpu/drm/xlnx/zynqmp_dp_audio.c  | 461
> 
>  drivers/gpu/drm/xlnx/zynqmp_dpsub.c |  39 +--
>  drivers/gpu/drm/xlnx/zynqmp_dpsub.h |  15 +-
>  9 files changed, 540 insertions(+), 103 deletions(-)
> 
> diff --git a/drivers/gpu/drm/xlnx/Kconfig b/drivers/gpu/drm/xlnx/Kconfig
> index 68ee897de9d7..d88cfbaf2863 100644
> --- a/drivers/gpu/drm/xlnx/Kconfig
> +++ b/drivers/gpu/drm/xlnx/Kconfig
> @@ -15,3 +15,12 @@ config DRM_ZYNQMP_DPSUB
>   This is a DRM/KMS driver for ZynqMP DisplayPort controller.
> Choose
>   this option if you have a Xilinx ZynqMP SoC with DisplayPort
>   subsystem.
> +
> +config DRM_ZYNQMP_DPSUB_AUDIO
> +   bool "ZynqMP DisplayPort Audio Support"
> +   depends on DRM_ZYNQMP_DPSUB
> +   depends on SND && SND_SOC
> +   select SND_SOC_GENERIC_DMAENGINE_PCM
> +   help
> + Choose this option to enable DisplayPort audio support in the
> ZynqMP
> + DisplayPort driver.
> diff --git a/drivers/gpu/drm/xlnx/Makefile
> b/drivers/gpu/drm/xlnx/Makefile
> index ea1422a39502..ab6e2ffd7e8d 100644
> --- a/drivers/gpu/drm/xlnx/Makefile
> +++ b/drivers/gpu/drm/xlnx/Makefile
> @@ -1,2 +1,3 @@
>  zynqmp-dpsub-y := zynqmp_disp.o zynqmp_dpsub.o zynqmp_dp.o
> zynqmp_kms.o
> +zynqmp-dpsub-$(CONFIG_DRM_ZYNQMP_DPSUB_AUDIO) +=
> zynqmp_dp_audio.o
>  obj-$(CONFIG_DRM_ZYNQMP_DPSUB) += zynqmp-dpsub.o
> diff --git a/drivers/gpu/drm/xlnx/zynqmp_disp.c
> b/drivers/gpu/drm/xlnx/zynqmp_disp.c
> index 407bc07cec69..d2bf0e2d0135 100644
> --- a/drivers/gpu/drm/xlnx/zynqmp_disp.c
> +++ b/drivers/gpu/drm/xlnx/zynqmp_disp.c
> @@ -130,7 +130,6 @@ struct zynqmp_disp_layer {
>   * @dpsub: Display subsystem
>   * @blend.base: Register I/O base address for the blender
>   * @avbuf.base: Register I/O base address for the audio/video buffer
> manager
> - * @audio.base: Registers I/O base address for the audio mixer
>   * @layers: Layers (planes)
>   */
>  struct zynqmp_disp {
> @@ -143,9 +142,6 @@ struct zynqmp_disp {
> struct {
> void __iomem *base;
> } avbuf;
> -   struct {
> -   void __iomem *base;
> -   } audio;
> 
> struct zynqmp_disp_layer layers[ZYNQMP_DPSUB_NUM_LAYERS];
>  };
> @@ -807,42 +803,6 @@ static void
> zynqmp_disp_blend_layer_disable(struct zynqmp_disp *disp,
> csc_zero_offsets);
>  }
> 
> -/* 
> -
> - * Audio Mixer
> - */
> -
> -static void zynqmp_disp_audio_write(struct zynqmp_disp *disp, int reg,
> u32 val)
> -{
> -   writel(val, disp->audio.base + reg);
> -}
> -
> -/**
> - * zynqmp_disp_audio_enable - Enable the audio mixer
> - * @disp: Display controller
> - *
> - * Enable the audio mixer by de-asserting the soft reset. The audio state
> is set to
> - * default values by the reset, set the default mixer volume explicitly.
> - */
> -static void zynqmp_disp_audio_enable(struct zynqmp_disp *disp)
> -{
> -   /* Clear the audio soft reset register as it's an non-reset flop. */
> -   zynqmp_disp_audio_write(d

[PATCH 3/4] gpu/drm: Prefer `unsigned int` over `unsigned`

2024-04-02 Thread Nicolas Devos
This commit fixes following checkpatch warning:
WARNING: Prefer 'unsigned int' to bare use of 'unsigned'

Signed-off-by: Nicolas Devos 
---
 drivers/gpu/drm/drm_connector.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c
index 6d8f0fc905f3..de71805aab2c 100644
--- a/drivers/gpu/drm/drm_connector.c
+++ b/drivers/gpu/drm/drm_connector.c
@@ -2076,7 +2076,7 @@ int drm_connector_attach_scaling_mode_property(struct 
drm_connector *connector,
struct drm_device *dev = connector->dev;
struct drm_property *scaling_mode_property;
int i;
-   const unsigned valid_scaling_mode_mask =
+   const unsigned int valid_scaling_mode_mask =
(1U << ARRAY_SIZE(drm_scaling_mode_enum_list)) - 1;
 
if (WARN_ON(hweight32(scaling_mode_mask) < 2 ||
-- 
2.42.0




[PATCH 2/4] gpu/drm: Remove unnecessary braces

2024-04-02 Thread Nicolas Devos
This commit fixes following checkpatch warnings:
WARNING: braces {} are not necessary for single statement blocks
WARNING: braces {} are not necessary for any arm of this statement

Signed-off-by: Nicolas Devos 
---
 drivers/gpu/drm/drm_connector.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c
index 40350256b1f6..6d8f0fc905f3 100644
--- a/drivers/gpu/drm/drm_connector.c
+++ b/drivers/gpu/drm/drm_connector.c
@@ -314,9 +314,8 @@ static int __drm_connector_init(struct drm_device *dev,
   config->tile_property,
   0);
 
-   if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
+   if (drm_core_check_feature(dev, DRIVER_ATOMIC))
drm_object_attach_property(&connector->base, 
config->prop_crtc_id, 0);
-   }
 
connector->debugfs_entry = NULL;
 out_put_type_id:
@@ -2818,9 +2817,9 @@ int drm_connector_set_obj_prop(struct drm_mode_object 
*obj,
struct drm_connector *connector = obj_to_connector(obj);
 
/* Do DPMS ourselves */
-   if (property == connector->dev->mode_config.dpms_property) {
+   if (property == connector->dev->mode_config.dpms_property)
ret = (*connector->funcs->dpms)(connector, (int)value);
-   } else if (connector->funcs->set_property)
+   else if (connector->funcs->set_property)
ret = connector->funcs->set_property(connector, property, 
value);
 
if (!ret)
-- 
2.42.0




[PATCH 0/4] gpu/drm: Fix checkpatch warnings in drm_connector.c

2024-04-02 Thread Nicolas Devos
Hello,

First time contributor here, I am getting familiar with the flow by
fixing some checkpatch warnings. This patch series fixes the warnings of
drivers/gpu/drm/drm_connector.c.

The result is 4 patches that each address a separate issue raised by
the checkpatch.pl script.

My initial attempt [1] was not accepted, this patch series addresses the
given review comments.

Please, let me know if something is not as expected.

[1]: https://lore.kernel.org/all/2024004450.7943-1-ndevos-...@pm.me/

Nicolas Devos (4):
  gpu/drm: Add SPDX-license-Identifier tag
  gpu/drm: Remove unnecessary braces
  gpu/drm: Prefer `unsigned int` over `unsigned`
  gpu/drm: Replace tabs with spaces in comments

 drivers/gpu/drm/drm_connector.c | 722 
 1 file changed, 361 insertions(+), 361 deletions(-)

-- 
2.42.0




[PATCH 4/4] gpu/drm: Replace tabs with spaces in comments

2024-04-02 Thread Nicolas Devos
This commit fixes following warnings found by checkpatch:
WARNING: please, no space before tabs

Signed-off-by: Nicolas Devos 
---
 drivers/gpu/drm/drm_connector.c | 712 
 1 file changed, 356 insertions(+), 356 deletions(-)

diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c
index de71805aab2c..d90b9ae6be3c 100644
--- a/drivers/gpu/drm/drm_connector.c
+++ b/drivers/gpu/drm/drm_connector.c
@@ -1150,70 +1150,70 @@ static const u32 dp_colorspaces =
  * DRM connectors have a few standardized properties:
  *
  * EDID:
- * Blob property which contains the current EDID read from the sink. This
- * is useful to parse sink identification information like vendor, model
- * and serial. Drivers should update this property by calling
- * drm_connector_update_edid_property(), usually after having parsed
- * the EDID using drm_add_edid_modes(). Userspace cannot change this
- * property.
- *
- * User-space should not parse the EDID to obtain information exposed via
- * other KMS properties (because the kernel might apply limits, quirks or
- * fixups to the EDID). For instance, user-space should not try to parse
- * mode lists from the EDID.
+ *  Blob property which contains the current EDID read from the sink. This
+ *  is useful to parse sink identification information like vendor, model
+ *  and serial. Drivers should update this property by calling
+ *  drm_connector_update_edid_property(), usually after having parsed
+ *  the EDID using drm_add_edid_modes(). Userspace cannot change this
+ *  property.
+ *
+ *  User-space should not parse the EDID to obtain information exposed via
+ *  other KMS properties (because the kernel might apply limits, quirks or
+ *  fixups to the EDID). For instance, user-space should not try to parse
+ *  mode lists from the EDID.
  * DPMS:
- * Legacy property for setting the power state of the connector. For atomic
- * drivers this is only provided for backwards compatibility with existing
- * drivers, it remaps to controlling the "ACTIVE" property on the CRTC the
- * connector is linked to. Drivers should never set this property directly,
- * it is handled by the DRM core by calling the &drm_connector_funcs.dpms
- * callback. For atomic drivers the remapping to the "ACTIVE" property is
- * implemented in the DRM core.
- *
- * Note that this property cannot be set through the MODE_ATOMIC ioctl,
- * userspace must use "ACTIVE" on the CRTC instead.
- *
- * WARNING:
- *
- * For userspace also running on legacy drivers the "DPMS" semantics are a
- * lot more complicated. First, userspace cannot rely on the "DPMS" value
- * returned by the GETCONNECTOR actually reflecting reality, because many
- * drivers fail to update it. For atomic drivers this is taken care of in
- * drm_atomic_helper_update_legacy_modeset_state().
- *
- * The second issue is that the DPMS state is only well-defined when the
- * connector is connected to a CRTC. In atomic the DRM core enforces that
- * "ACTIVE" is off in such a case, no such checks exists for "DPMS".
- *
- * Finally, when enabling an output using the legacy SETCONFIG ioctl then
- * "DPMS" is forced to ON. But see above, that might not be reflected in
- * the software value on legacy drivers.
- *
- * Summarizing: Only set "DPMS" when the connector is known to be enabled,
- * assume that a successful SETCONFIG call also sets "DPMS" to on, and
- * never read back the value of "DPMS" because it can be incorrect.
+ *  Legacy property for setting the power state of the connector. For 
atomic
+ *  drivers this is only provided for backwards compatibility with existing
+ *  drivers, it remaps to controlling the "ACTIVE" property on the CRTC the
+ *  connector is linked to. Drivers should never set this property 
directly,
+ *  it is handled by the DRM core by calling the &drm_connector_funcs.dpms
+ *  callback. For atomic drivers the remapping to the "ACTIVE" property is
+ *  implemented in the DRM core.
+ *
+ *  Note that this property cannot be set through the MODE_ATOMIC ioctl,
+ *  userspace must use "ACTIVE" on the CRTC instead.
+ *
+ *  WARNING:
+ *
+ *  For userspace also running on legacy drivers the "DPMS" semantics are a
+ *  lot more complicated. First, userspace cannot rely on the "DPMS" value
+ *  returned by the GETCONNECTOR actually reflecting reality, because many
+ *  drivers fail to update it. For atomic drivers this is taken care of in
+ *  drm_atomic_helper_update_legacy_modeset_state().
+ *
+ *  The second issue is that the DPMS state is only well-defined when the
+ *  connector is connected to a CRTC. In atomic the DRM core enforces that
+ *  "ACTIVE" is off in such a case, no such checks exists for "DPMS".
+ *
+ *  Finally, when enablin

[PATCH 1/4] gpu/drm: Add SPDX-license-Identifier tag

2024-04-02 Thread Nicolas Devos
This commit fixes following checkpatch warning:
WARNING: Missing or malformed SPDX-License-Identifier tag

Signed-off-by: Nicolas Devos 
---
 drivers/gpu/drm/drm_connector.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c
index b0516505f7ae..40350256b1f6 100644
--- a/drivers/gpu/drm/drm_connector.c
+++ b/drivers/gpu/drm/drm_connector.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0 or MIT
 /*
  * Copyright (c) 2016 Intel Corporation
  *
-- 
2.42.0




[PATCH 2/2] drm/panthor: Fix some kerneldoc warnings

2024-04-02 Thread Liviu Dudau
When compiling with W=1 the build process will flag empty comments,
misnamed documented variables and incorrect tagging of functions.
Fix them in one go.

Fixes: de8548813824 ("drm/panthor: Add the scheduler logical block")
Cc: Boris Brezillon 
Cc: Steven Price 
Signed-off-by: Liviu Dudau 
---
 drivers/gpu/drm/panthor/panthor_sched.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/panthor/panthor_sched.c 
b/drivers/gpu/drm/panthor/panthor_sched.c
index e5a710f190d2a8..a787f2fea33e98 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.c
+++ b/drivers/gpu/drm/panthor/panthor_sched.c
@@ -517,7 +517,7 @@ struct panthor_group {
/** @max_compute_cores: Maximum number of shader cores used for compute 
jobs. */
u8 max_compute_cores;
 
-   /** @max_compute_cores: Maximum number of shader cores used for 
fragment jobs. */
+   /** @max_fragment_cores: Maximum number of shader cores used for 
fragment jobs. */
u8 max_fragment_cores;
 
/** @max_tiler_cores: Maximum number of tiler cores used for tiler 
jobs. */
@@ -993,7 +993,7 @@ cs_slot_prog_locked(struct panthor_device *ptdev, u32 
csg_id, u32 cs_id)
 }
 
 /**
- * @cs_slot_reset_locked() - Reset a queue slot
+ * cs_slot_reset_locked() - Reset a queue slot
  * @ptdev: Device.
  * @csg_id: Group slot.
  * @cs_id: Queue slot.
@@ -1591,7 +1591,7 @@ static void sched_process_idle_event_locked(struct 
panthor_device *ptdev)
 }
 
 /**
- * panthor_sched_process_global_irq() - Process the scheduling part of a 
global IRQ
+ * sched_process_global_irq_locked() - Process the scheduling part of a global 
IRQ
  * @ptdev: Device.
  */
 static void sched_process_global_irq_locked(struct panthor_device *ptdev)
@@ -1660,8 +1660,6 @@ static const struct dma_fence_ops panthor_queue_fence_ops 
= {
.get_timeline_name = queue_fence_get_timeline_name,
 };
 
-/**
- */
 struct panthor_csg_slots_upd_ctx {
u32 update_mask;
u32 timedout_mask;
-- 
2.44.0



[PATCH 1/2] drm/panthor: Cleanup unused variable 'cookie'

2024-04-02 Thread Liviu Dudau
Commit 962f88b9c916 ("drm/panthor: Drop the dev_enter/exit() sections in
_irq_suspend/resume()") removed the code that used the 'cookie' variable
but left the declaration in place. Remove it.

Fixes: 962f88b9c916 ("drm/panthor: Drop the dev_enter/exit() sections in 
_irq_suspend/resume()")
Cc: Boris Brezillon 
Cc: Steven Price 
Signed-off-by: Liviu Dudau 
---
 drivers/gpu/drm/panthor/panthor_device.h | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/gpu/drm/panthor/panthor_device.h 
b/drivers/gpu/drm/panthor/panthor_device.h
index dc3e9c666b5bd4..2fdd671b38fd9b 100644
--- a/drivers/gpu/drm/panthor/panthor_device.h
+++ b/drivers/gpu/drm/panthor/panthor_device.h
@@ -323,8 +323,6 @@ static irqreturn_t panthor_ ## __name ## 
_irq_threaded_handler(int irq, void *da

\
 static inline void panthor_ ## __name ## _irq_suspend(struct panthor_irq 
*pirq)\
 {  
\
-   int cookie; 
\
-   
\
pirq->mask = 0; 
\
gpu_write(pirq->ptdev, __reg_prefix ## _INT_MASK, 0);   
\
synchronize_irq(pirq->irq); 
\
@@ -333,8 +331,6 @@ static inline void panthor_ ## __name ## 
_irq_suspend(struct panthor_irq *pirq)

\
 static inline void panthor_ ## __name ## _irq_resume(struct panthor_irq *pirq, 
u32 mask)   \
 {  
\
-   int cookie; 
\
-   
\
atomic_set(&pirq->suspended, false);
\
pirq->mask = mask;  
\
gpu_write(pirq->ptdev, __reg_prefix ## _INT_CLEAR, mask);   
\
-- 
2.44.0



Re: [PATCH v3 4/4] drm: panel: Add LG sw43408 panel driver

2024-04-02 Thread Marijn Suijten
On 2024-04-02 02:51:15, Dmitry Baryshkov wrote:
> From: Sumit Semwal 
> 
> LG SW43408 is 1080x2160, 4-lane MIPI-DSI panel, used in some Pixel3
> phones.

@60Hz?

> 
> Signed-off-by: Sumit Semwal 
> [vinod: Add DSC support]
> Signed-off-by: Vinod Koul 
> [caleb: cleanup and support turning off the panel]
> Signed-off-by: Caleb Connolly 
> [DB: partially rewrote the driver and fixed DSC programming]
> Signed-off-by: Dmitry Baryshkov 

Some small nits but I think this deserves a:

Reviewed-by: Marijn Suijten 

> ---
>  MAINTAINERS  |   8 +
>  drivers/gpu/drm/panel/Kconfig|  11 ++
>  drivers/gpu/drm/panel/Makefile   |   1 +
>  drivers/gpu/drm/panel/panel-lg-sw43408.c | 326 
> +++
>  4 files changed, 346 insertions(+)
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index d36c19c1bf81..4cc43c16e07e 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -6789,6 +6789,14 @@ S: Maintained
>  F:   Documentation/devicetree/bindings/display/panel/jadard,jd9365da-h3.yaml
>  F:   drivers/gpu/drm/panel/panel-jadard-jd9365da-h3.c
>  
> +DRM DRIVER FOR LG SW43408 PANELS
> +M:   Sumit Semwal 
> +M:   Caleb Connolly 
> +S:   Maintained
> +T:   git git://anongit.freedesktop.org/drm/drm-misc
> +F:   Documentation/devicetree/bindings/display/panel/lg,sw43408.yaml
> +F:   drivers/gpu/drm/panel/panel-lg-sw43408.c
> +
>  DRM DRIVER FOR LOGICVC DISPLAY CONTROLLER
>  M:   Paul Kocialkowski 
>  S:   Supported
> diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig
> index 6dc451f58a3e..a55e9437c8cf 100644
> --- a/drivers/gpu/drm/panel/Kconfig
> +++ b/drivers/gpu/drm/panel/Kconfig
> @@ -335,6 +335,17 @@ config DRM_PANEL_LG_LG4573
> Say Y here if you want to enable support for LG4573 RGB panel.
> To compile this driver as a module, choose M here.
>  
> +config DRM_PANEL_LG_SW43408
> + tristate "LG SW43408 panel"
> + depends on OF
> + depends on DRM_MIPI_DSI
> + depends on BACKLIGHT_CLASS_DEVICE
> + help
> +   Say Y here if you want to enable support for LG sw43408 panel.
> +   The panel has a 1080x2160 resolution and uses
> +   24 bit RGB per pixel. It provides a MIPI DSI interface to
> +   the host and has a built-in LED backlight.
> +
>  config DRM_PANEL_MAGNACHIP_D53E6EA8966
>   tristate "Magnachip D53E6EA8966 DSI panel"
>   depends on OF && SPI
> diff --git a/drivers/gpu/drm/panel/Makefile b/drivers/gpu/drm/panel/Makefile
> index 24a02655d726..0b40b010e8e7 100644
> --- a/drivers/gpu/drm/panel/Makefile
> +++ b/drivers/gpu/drm/panel/Makefile
> @@ -34,6 +34,7 @@ obj-$(CONFIG_DRM_PANEL_LEADTEK_LTK050H3146W) += 
> panel-leadtek-ltk050h3146w.o
>  obj-$(CONFIG_DRM_PANEL_LEADTEK_LTK500HD1829) += panel-leadtek-ltk500hd1829.o
>  obj-$(CONFIG_DRM_PANEL_LG_LB035Q02) += panel-lg-lb035q02.o
>  obj-$(CONFIG_DRM_PANEL_LG_LG4573) += panel-lg-lg4573.o
> +obj-$(CONFIG_DRM_PANEL_LG_SW43408) += panel-lg-sw43408.o
>  obj-$(CONFIG_DRM_PANEL_MAGNACHIP_D53E6EA8966) += 
> panel-magnachip-d53e6ea8966.o
>  obj-$(CONFIG_DRM_PANEL_NEC_NL8048HL11) += panel-nec-nl8048hl11.o
>  obj-$(CONFIG_DRM_PANEL_NEWVISION_NV3051D) += panel-newvision-nv3051d.o
> diff --git a/drivers/gpu/drm/panel/panel-lg-sw43408.c 
> b/drivers/gpu/drm/panel/panel-lg-sw43408.c
> new file mode 100644
> index ..c7611bfa796b
> --- /dev/null
> +++ b/drivers/gpu/drm/panel/panel-lg-sw43408.c
> @@ -0,0 +1,326 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright (C) 2019-2024 Linaro Ltd
> + * Author: Sumit Semwal 
> + *Dmitry Baryshkov 
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define NUM_SUPPLIES 2
> +
> +struct sw43408_panel {
> + struct drm_panel base;
> + struct mipi_dsi_device *link;
> +
> + const struct drm_display_mode *mode;
> +
> + struct regulator_bulk_data supplies[NUM_SUPPLIES];
> +
> + struct gpio_desc *reset_gpio;
> +
> + struct drm_dsc_config dsc;
> +};
> +
> +static inline struct sw43408_panel *to_panel_info(struct drm_panel *panel)
> +{
> + return container_of(panel, struct sw43408_panel, base);
> +}
> +
> +static int sw43408_unprepare(struct drm_panel *panel)
> +{
> + struct sw43408_panel *ctx = to_panel_info(panel);
> + int ret;
> +
> + ret = mipi_dsi_dcs_set_display_off(ctx->link);
> + if (ret < 0)
> + dev_err(panel->dev, "set_display_off cmd failed ret = %d\n", 
> ret);
> +
> + ret = mipi_dsi_dcs_enter_sleep_mode(ctx->link);
> + if (ret < 0)
> + dev_err(panel->dev, "enter_sleep cmd failed ret = %d\n", ret);
> +
> + msleep(100);
> +
> + gpiod_set_value(ctx->reset_gpio, 1);
> +
> + return regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
> +}
> +
> +static int sw43408_program(struct drm_panel *panel)
> +{
> + struct sw43408_panel *ctx = to_panel_info(panel);

Re: [PATCH v3 3/4] drm/mipi-dsi: add mipi_dsi_compression_mode_ext()

2024-04-02 Thread Marijn Suijten
On 2024-04-02 02:51:14, Dmitry Baryshkov wrote:
> Add the extended version of mipi_dsi_compression_mode(). It provides
> a way to specify the algorithm and PPS selector.
> 
> Signed-off-by: Dmitry Baryshkov 
> ---
>  drivers/gpu/drm/drm_mipi_dsi.c | 33 +++--
>  include/drm/drm_mipi_dsi.h |  9 +
>  2 files changed, 36 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c
> index 9874ff6d4718..0ecbc811eb7a 100644
> --- a/drivers/gpu/drm/drm_mipi_dsi.c
> +++ b/drivers/gpu/drm/drm_mipi_dsi.c
> @@ -645,19 +645,24 @@ int mipi_dsi_set_maximum_return_packet_size(struct 
> mipi_dsi_device *dsi,
>  EXPORT_SYMBOL(mipi_dsi_set_maximum_return_packet_size);
>  
>  /**
> - * mipi_dsi_compression_mode() - enable/disable DSC on the peripheral
> + * mipi_dsi_compression_mode_ext() - enable/disable DSC on the peripheral
>   * @dsi: DSI peripheral device
>   * @enable: Whether to enable or disable the DSC
> + * @algo: Selected algorithm
> + * @pps_selector: The PPS selector

Not a big fan of paraphrasing the parameter name, it adds no value.  How about
describing what this parameter means and what it does?:

PPS table index to use.  Corresponds to a table pre-programmed on the 
peripheral
or a table programmed with 
&drm_dsc_picture_parameter_set.pps_identifier.

(That should be a valid kernel-doc cross-reference to the field)

>   *
> - * Enable or disable Display Stream Compression on the peripheral using the
> - * default Picture Parameter Set and VESA DSC 1.1 algorithm.
> + * Enable or disable Display Stream Compression on the peripheral.
>   *
>   * Return: 0 on success or a negative error code on failure.
>   */
> -int mipi_dsi_compression_mode(struct mipi_dsi_device *dsi, bool enable)
> +int mipi_dsi_compression_mode_ext(struct mipi_dsi_device *dsi, bool enable,
> +   enum mipi_dsi_compression_algo algo,
> +   unsigned int pps_selector)
>  {
> - /* Note: Needs updating for non-default PPS or algorithm */
> - u8 tx[2] = { enable << 0, 0 };
> + u8 data = (enable << 0) |
> + (algo << 1) |
> + (pps_selector << 4);

Do we need some size validation (if > 3 return -EINVAL)?  FIELD_PREP() might be
too heavy though.

> + u8 tx[2] = { data, 0 };
>   struct mipi_dsi_msg msg = {
>   .channel = dsi->channel,
>   .type = MIPI_DSI_COMPRESSION_MODE,
> @@ -668,6 +673,22 @@ int mipi_dsi_compression_mode(struct mipi_dsi_device 
> *dsi, bool enable)
>  
>   return (ret < 0) ? ret : 0;
>  }
> +EXPORT_SYMBOL(mipi_dsi_compression_mode_ext);
> +
> +/**
> + * mipi_dsi_compression_mode() - enable/disable DSC on the peripheral
> + * @dsi: DSI peripheral device
> + * @enable: Whether to enable or disable the DSC
> + *
> + * Enable or disable Display Stream Compression on the peripheral using the
> + * default Picture Parameter Set and VESA DSC 1.1 algorithm.
> + *
> + * Return: 0 on success or a negative error code on failure.
> + */
> +int mipi_dsi_compression_mode(struct mipi_dsi_device *dsi, bool enable)
> +{
> + return mipi_dsi_compression_mode_ext(dsi, enable, 0, 
> MIPI_DSI_COMPRESSION_DSC);

I hope the compiler complains here that it should be MIPI_DSI_COMPRESSION_DSC,0

(Enum algo first, int pps_selector last)

> +}
>  EXPORT_SYMBOL(mipi_dsi_compression_mode);
>  
>  /**
> diff --git a/include/drm/drm_mipi_dsi.h b/include/drm/drm_mipi_dsi.h
> index 3011d33eccbd..78cb7b688b1d 100644
> --- a/include/drm/drm_mipi_dsi.h
> +++ b/include/drm/drm_mipi_dsi.h
> @@ -226,6 +226,12 @@ static inline int mipi_dsi_pixel_format_to_bpp(enum 
> mipi_dsi_pixel_format fmt)
>   return -EINVAL;
>  }
>  
> +enum mipi_dsi_compression_algo {
> + MIPI_DSI_COMPRESSION_DSC = 0,

Add 1.1?  Or does it also allow 1.2 (when the version is also set via PPS)?

> + MIPI_DSI_COMPRESSION_VENDOR = 3,
> + /* other two values are reserved, DSI 1.3 */
> +};
> +
>  struct mipi_dsi_device *
>  mipi_dsi_device_register_full(struct mipi_dsi_host *host,
> const struct mipi_dsi_device_info *info);
> @@ -242,6 +248,9 @@ int mipi_dsi_turn_on_peripheral(struct mipi_dsi_device 
> *dsi);
>  int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi,
>   u16 value);
>  int mipi_dsi_compression_mode(struct mipi_dsi_device *dsi, bool enable);
> +int mipi_dsi_compression_mode_ext(struct mipi_dsi_device *dsi, bool enable,
> +   unsigned int pps_selector,
> +   enum mipi_dsi_compression_algo algo);

Oh, this declaration is inverse from the definition...

- Marijn

>  int mipi_dsi_picture_parameter_set(struct mipi_dsi_device *dsi,
>  const struct drm_dsc_picture_parameter_set 
> *pps);
>  
> 
> -- 
> 2.39.2
> 


Re: [PATCH v3 2/4] drm/mipi-dsi: use correct return type for the DSC functions

2024-04-02 Thread Marijn Suijten
On 2024-04-02 02:51:13, Dmitry Baryshkov wrote:
> The functions mipi_dsi_compression_mode() and
> mipi_dsi_picture_parameter_set() return 0-or-error rather than a buffer
> size. Follow example of other similar MIPI DSI functions and use int
> return type instead of size_t.
> 
> Fixes: f4dea1aaa9a1 ("drm/dsi: add helpers for DSI compression mode and PPS 
> packets")
> Signed-off-by: Dmitry Baryshkov 

Reviewed-by: Marijn Suijten 

> ---
>  drivers/gpu/drm/drm_mipi_dsi.c | 6 +++---
>  include/drm/drm_mipi_dsi.h | 6 +++---
>  2 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c
> index ef6e416522f8..9874ff6d4718 100644
> --- a/drivers/gpu/drm/drm_mipi_dsi.c
> +++ b/drivers/gpu/drm/drm_mipi_dsi.c
> @@ -654,7 +654,7 @@ EXPORT_SYMBOL(mipi_dsi_set_maximum_return_packet_size);
>   *
>   * Return: 0 on success or a negative error code on failure.
>   */
> -ssize_t mipi_dsi_compression_mode(struct mipi_dsi_device *dsi, bool enable)
> +int mipi_dsi_compression_mode(struct mipi_dsi_device *dsi, bool enable)
>  {
>   /* Note: Needs updating for non-default PPS or algorithm */
>   u8 tx[2] = { enable << 0, 0 };
> @@ -679,8 +679,8 @@ EXPORT_SYMBOL(mipi_dsi_compression_mode);
>   *
>   * Return: 0 on success or a negative error code on failure.
>   */
> -ssize_t mipi_dsi_picture_parameter_set(struct mipi_dsi_device *dsi,
> -const struct 
> drm_dsc_picture_parameter_set *pps)
> +int mipi_dsi_picture_parameter_set(struct mipi_dsi_device *dsi,
> +const struct drm_dsc_picture_parameter_set 
> *pps)
>  {
>   struct mipi_dsi_msg msg = {
>   .channel = dsi->channel,
> diff --git a/include/drm/drm_mipi_dsi.h b/include/drm/drm_mipi_dsi.h
> index c0aec0d4d664..3011d33eccbd 100644
> --- a/include/drm/drm_mipi_dsi.h
> +++ b/include/drm/drm_mipi_dsi.h
> @@ -241,9 +241,9 @@ int mipi_dsi_shutdown_peripheral(struct mipi_dsi_device 
> *dsi);
>  int mipi_dsi_turn_on_peripheral(struct mipi_dsi_device *dsi);
>  int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi,
>   u16 value);
> -ssize_t mipi_dsi_compression_mode(struct mipi_dsi_device *dsi, bool enable);
> -ssize_t mipi_dsi_picture_parameter_set(struct mipi_dsi_device *dsi,
> -const struct 
> drm_dsc_picture_parameter_set *pps);
> +int mipi_dsi_compression_mode(struct mipi_dsi_device *dsi, bool enable);
> +int mipi_dsi_picture_parameter_set(struct mipi_dsi_device *dsi,
> +const struct drm_dsc_picture_parameter_set 
> *pps);
>  
>  ssize_t mipi_dsi_generic_write(struct mipi_dsi_device *dsi, const void 
> *payload,
>  size_t size);
> 
> -- 
> 2.39.2
> 


Re: [PATCH v3 1/4] dt-bindings: panel: Add LG SW43408 MIPI-DSI panel

2024-04-02 Thread Marijn Suijten
On 2024-04-02 10:23:22, Dmitry Baryshkov wrote:
> On Tue, 2 Apr 2024 at 09:31, Krzysztof Kozlowski
>  wrote:
> >
> > On 02/04/2024 01:51, Dmitry Baryshkov wrote:
> > > From: Sumit Semwal 
> > >
> > > LG SW43408 is 1080x2160, 4-lane MIPI-DSI panel present on Google Pixel 3
> > > phones.
> > >
> > > Signed-off-by: Vinod Koul 
> > > Signed-off-by: Sumit Semwal 
> > > [caleb: convert to yaml]
> > > Signed-off-by: Caleb Connolly 
> > > Signed-off-by: Dmitry Baryshkov 
> > > ---
> >
> > Tags missing.
> >
> > `b4 trailers -u`
> 
> Excuse me, I keep on forgetting it.

Does a similar thing exist for adding Cc: tags for all reviewers/replyers to an
earlier version, even if said reviewer didn't yet provide R-b/A-b or other tags?

I'd like to have the next revisions in my inbox as well after leaving
comments :)

Thanks! - Marijn


Re: [PATCH 3/3] drm: panel: Add LG sw43408 panel driver

2024-04-02 Thread Marijn Suijten
On 2024-04-01 22:11:48, Dmitry Baryshkov wrote:
> On Mon, 1 Apr 2024 at 13:29, Marijn Suijten
>  wrote:
> >
> > On 2024-03-30 16:37:08, Dmitry Baryshkov wrote:
> > > On Sat, 30 Mar 2024 at 12:27, Marijn Suijten
> > >  wrote:
> > > >
> > > > On 2024-03-30 05:59:30, Dmitry Baryshkov wrote:
> > > > > From: Sumit Semwal 
> > > > >
> > > > > LG SW43408 is 1080x2160, 4-lane MIPI-DSI panel, used in some Pixel3
> > > > > phones.
> > > > >
> > > > > Whatever init sequence we have for this panel isn't capable of
> > > > > initialising it completely, toggling the reset gpio ever causes the
> > > > > panel to die. Until this is resolved we avoid resetting the panel. The
> > > >
> > > > Are you sure it is avoided?  This patch seems to be toggling reset_gpio 
> > > > in
> > > > sw43408_prepare()?
> > > >
> > > > > disable/unprepare functions only put the panel to sleep mode and
> > > > > disable the backlight.
> > > > >
> > > > > Signed-off-by: Sumit Semwal 
> > > > > [vinod: Add DSC support]
> > > > > Signed-off-by: Vinod Koul 
> > > > > [caleb: cleanup and support turning off the panel]
> > > > > Signed-off-by: Caleb Connolly 
> > > > > [DB: partially rewrote the driver and fixed DSC programming]
> > > > > Signed-off-by: Dmitry Baryshkov 
> > > > > ---
> > > > >  MAINTAINERS  |   8 +
> > > > >  drivers/gpu/drm/panel/Kconfig|  11 ++
> > > > >  drivers/gpu/drm/panel/Makefile   |   1 +
> > > > >  drivers/gpu/drm/panel/panel-lg-sw43408.c | 322 
> > > > > +++
> > > > >  4 files changed, 342 insertions(+)
> > > > >
> > > > > diff --git a/MAINTAINERS b/MAINTAINERS
> > > > > index 4b511a55101c..f4cf7ee97376 100644
> > > > > --- a/MAINTAINERS
> > > > > +++ b/MAINTAINERS
> > > > > @@ -6755,6 +6755,14 @@ S: Maintained
> > > > >  F:   
> > > > > Documentation/devicetree/bindings/display/panel/jadard,jd9365da-h3.yaml
> > > > >  F:   drivers/gpu/drm/panel/panel-jadard-jd9365da-h3.c
> > > > >
> > > > > +DRM DRIVER FOR LG SW43408 PANELS
> > > > > +M:   Sumit Semwal 
> > > > > +M:   Caleb Connolly 
> > > > > +S:   Maintained
> > > > > +T:   git git://anongit.freedesktop.org/drm/drm-misc
> > > > > +F:   Documentation/devicetree/bindings/display/panel/lg,sw43408.yaml
> > > > > +F:   drivers/gpu/drm/panel/panel-lg-sw43408.c
> > > > > +
> > > > >  DRM DRIVER FOR LOGICVC DISPLAY CONTROLLER
> > > > >  M:   Paul Kocialkowski 
> > > > >  S:   Supported
> > > > > diff --git a/drivers/gpu/drm/panel/Kconfig 
> > > > > b/drivers/gpu/drm/panel/Kconfig
> > > > > index d037b3b8b999..f94c702735cb 100644
> > > > > --- a/drivers/gpu/drm/panel/Kconfig
> > > > > +++ b/drivers/gpu/drm/panel/Kconfig
> > > > > @@ -335,6 +335,17 @@ config DRM_PANEL_LG_LG4573
> > > > > Say Y here if you want to enable support for LG4573 RGB panel.
> > > > > To compile this driver as a module, choose M here.
> > > > >
> > > > > +config DRM_PANEL_LG_SW43408
> > > > > + tristate "LG SW43408 panel"
> > > > > + depends on OF
> > > > > + depends on DRM_MIPI_DSI
> > > > > + depends on BACKLIGHT_CLASS_DEVICE
> > > > > + help
> > > > > +   Say Y here if you want to enable support for LG sw43408 panel.
> > > > > +   The panel has a 1080x2160 resolution and uses
> > > > > +   24 bit RGB per pixel. It provides a MIPI DSI interface to
> > > > > +   the host and has a built-in LED backlight.
> > > > > +
> > > > >  config DRM_PANEL_MAGNACHIP_D53E6EA8966
> > > > >   tristate "Magnachip D53E6EA8966 DSI panel"
> > > > >   depends on OF && SPI
> > > > > diff --git a/drivers/gpu/drm/panel/Makefile 
> > > > > b/drivers/gpu/drm/panel/Makefile
> > > > > index f156d7fa0bcc..a75687d13caf 100644
> > > > > --- a/drivers/gpu/drm/panel/Makefile
> > > > > +++ b/drivers/gpu/drm/panel/Makefile
> > > > > @@ -34,6 +34,7 @@ obj-$(CONFIG_DRM_PANEL_LEADTEK_LTK050H3146W) += 
> > > > > panel-leadtek-ltk050h3146w.o
> > > > >  obj-$(CONFIG_DRM_PANEL_LEADTEK_LTK500HD1829) += 
> > > > > panel-leadtek-ltk500hd1829.o
> > > > >  obj-$(CONFIG_DRM_PANEL_LG_LB035Q02) += panel-lg-lb035q02.o
> > > > >  obj-$(CONFIG_DRM_PANEL_LG_LG4573) += panel-lg-lg4573.o
> > > > > +obj-$(CONFIG_DRM_PANEL_LG_SW43408) += panel-lg-sw43408.o
> > > > >  obj-$(CONFIG_DRM_PANEL_MAGNACHIP_D53E6EA8966) += 
> > > > > panel-magnachip-d53e6ea8966.o
> > > > >  obj-$(CONFIG_DRM_PANEL_NEC_NL8048HL11) += panel-nec-nl8048hl11.o
> > > > >  obj-$(CONFIG_DRM_PANEL_NEWVISION_NV3051D) += 
> > > > > panel-newvision-nv3051d.o
> > > > > diff --git a/drivers/gpu/drm/panel/panel-lg-sw43408.c 
> > > > > b/drivers/gpu/drm/panel/panel-lg-sw43408.c
> > > > > new file mode 100644
> > > > > index ..365d25e14d54
> > > > > --- /dev/null
> > > > > +++ b/drivers/gpu/drm/panel/panel-lg-sw43408.c
> > > > > @@ -0,0 +1,322 @@
> > > > > +// SPDX-License-Identifier: GPL-2.0+
> > > > > +/*
> > > > > + * Copyright (C) 2019-2024 Linaro Ltd
> > > > > + * Author: Sumit Semwal 
> > > > > + *Dmitry Baryshkov 
> > > > > + */
> > > > > +

Re: [PATCH v2 24/25] fuse: virtio: drop owner assignment

2024-04-02 Thread Stefan Hajnoczi
On Sun, Mar 31, 2024 at 10:44:11AM +0200, Krzysztof Kozlowski wrote:
> virtio core already sets the .owner, so driver does not need to.
> 
> Signed-off-by: Krzysztof Kozlowski 
> 
> ---
> 
> Depends on the first patch.
> ---
>  fs/fuse/virtio_fs.c | 1 -
>  1 file changed, 1 deletion(-)

Reviewed-by: Stefan Hajnoczi 


signature.asc
Description: PGP signature


Re: [PATCH v2 23/25] scsi: virtio: drop owner assignment

2024-04-02 Thread Stefan Hajnoczi
On Sun, Mar 31, 2024 at 10:44:10AM +0200, Krzysztof Kozlowski wrote:
> virtio core already sets the .owner, so driver does not need to.
> 
> Signed-off-by: Krzysztof Kozlowski 
> 
> ---
> 
> Depends on the first patch.
> ---
>  drivers/scsi/virtio_scsi.c | 1 -
>  1 file changed, 1 deletion(-)

Reviewed-by: Stefan Hajnoczi 


signature.asc
Description: PGP signature


Re: [PATCH v2 19/25] vsock/virtio: drop owner assignment

2024-04-02 Thread Stefan Hajnoczi
On Sun, Mar 31, 2024 at 10:44:06AM +0200, Krzysztof Kozlowski wrote:
> virtio core already sets the .owner, so driver does not need to.
> 
> Acked-by: Stefano Garzarella 
> Signed-off-by: Krzysztof Kozlowski 
> ---
> 
> Depends on the first patch.
> ---
>  net/vmw_vsock/virtio_transport.c | 1 -
>  1 file changed, 1 deletion(-)

Reviewed-by: Stefan Hajnoczi 


signature.asc
Description: PGP signature


Re: [PATCH v2 06/25] virtio_blk: drop owner assignment

2024-04-02 Thread Stefan Hajnoczi
On Sun, Mar 31, 2024 at 10:43:53AM +0200, Krzysztof Kozlowski wrote:
> virtio core already sets the .owner, so driver does not need to.
> 
> Signed-off-by: Krzysztof Kozlowski 
> 
> ---
> 
> Depends on the first patch.
> ---
>  drivers/block/virtio_blk.c | 1 -
>  1 file changed, 1 deletion(-)

Reviewed-by: Stefan Hajnoczi 


signature.asc
Description: PGP signature


[drm-misc:for-linux-next 3/4] drivers/gpu/drm/panthor/panthor_device.h:326:13: warning: unused variable 'cookie'

2024-04-02 Thread kernel test robot
tree:   git://anongit.freedesktop.org/drm/drm-misc for-linux-next
head:   10021ef27310279c850cf6cb38542c443a995e92
commit: 962f88b9c91647f3ff4a0d3709662641baed5164 [3/4] drm/panthor: Drop the 
dev_enter/exit() sections in _irq_suspend/resume()
config: arm64-defconfig 
(https://download.01.org/0day-ci/archive/20240403/202404030209.n8lhzyfk-...@intel.com/config)
compiler: aarch64-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): 
(https://download.01.org/0day-ci/archive/20240403/202404030209.n8lhzyfk-...@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot 
| Closes: 
https://lore.kernel.org/oe-kbuild-all/202404030209.n8lhzyfk-...@intel.com/

All warnings (new ones prefixed by >>):

   In file included from drivers/gpu/drm/panthor/panthor_fw.c:19:
   drivers/gpu/drm/panthor/panthor_fw.c: In function 'panthor_job_irq_suspend':
>> drivers/gpu/drm/panthor/panthor_device.h:326:13: warning: unused variable 
>> 'cookie' [-Wunused-variable]
 326 | int cookie;  
   \
 | ^~
   drivers/gpu/drm/panthor/panthor_fw.c:979:1: note: in expansion of macro 
'PANTHOR_IRQ_HANDLER'
 979 | PANTHOR_IRQ_HANDLER(job, JOB, panthor_job_irq_handler);
 | ^~~
   drivers/gpu/drm/panthor/panthor_fw.c: In function 'panthor_job_irq_resume':
   drivers/gpu/drm/panthor/panthor_device.h:336:13: warning: unused variable 
'cookie' [-Wunused-variable]
 336 | int cookie;  
   \
 | ^~
   drivers/gpu/drm/panthor/panthor_fw.c:979:1: note: in expansion of macro 
'PANTHOR_IRQ_HANDLER'
 979 | PANTHOR_IRQ_HANDLER(job, JOB, panthor_job_irq_handler);
 | ^~~
--
   In file included from drivers/gpu/drm/panthor/panthor_gpu.c:19:
   drivers/gpu/drm/panthor/panthor_gpu.c: In function 'panthor_gpu_irq_suspend':
>> drivers/gpu/drm/panthor/panthor_device.h:326:13: warning: unused variable 
>> 'cookie' [-Wunused-variable]
 326 | int cookie;  
   \
 | ^~
   drivers/gpu/drm/panthor/panthor_gpu.c:166:1: note: in expansion of macro 
'PANTHOR_IRQ_HANDLER'
 166 | PANTHOR_IRQ_HANDLER(gpu, GPU, panthor_gpu_irq_handler);
 | ^~~
   drivers/gpu/drm/panthor/panthor_gpu.c: In function 'panthor_gpu_irq_resume':
   drivers/gpu/drm/panthor/panthor_device.h:336:13: warning: unused variable 
'cookie' [-Wunused-variable]
 336 | int cookie;  
   \
 | ^~
   drivers/gpu/drm/panthor/panthor_gpu.c:166:1: note: in expansion of macro 
'PANTHOR_IRQ_HANDLER'
 166 | PANTHOR_IRQ_HANDLER(gpu, GPU, panthor_gpu_irq_handler);
 | ^~~
--
   In file included from drivers/gpu/drm/panthor/panthor_mmu.c:30:
   drivers/gpu/drm/panthor/panthor_mmu.c: In function 'panthor_mmu_irq_suspend':
>> drivers/gpu/drm/panthor/panthor_device.h:326:13: warning: unused variable 
>> 'cookie' [-Wunused-variable]
 326 | int cookie;  
   \
 | ^~
   drivers/gpu/drm/panthor/panthor_mmu.c:1689:1: note: in expansion of macro 
'PANTHOR_IRQ_HANDLER'
1689 | PANTHOR_IRQ_HANDLER(mmu, MMU, panthor_mmu_irq_handler);
 | ^~~
   drivers/gpu/drm/panthor/panthor_mmu.c: In function 'panthor_mmu_irq_resume':
   drivers/gpu/drm/panthor/panthor_device.h:336:13: warning: unused variable 
'cookie' [-Wunused-variable]
 336 | int cookie;  
   \
 | ^~
   drivers/gpu/drm/panthor/panthor_mmu.c:1689:1: note: in expansion of macro 
'PANTHOR_IRQ_HANDLER'
1689 | PANTHOR_IRQ_HANDLER(mmu, MMU, panthor_mmu_irq_handler);
 | ^~~


vim +/cookie +326 drivers/gpu/drm/panthor/panthor_device.h

5fe909cae118a7 Boris Brezillon 2024-02-29  271  
5fe909cae118a7 Boris Brezillon 2024-02-29  272  const char 
*panthor_exception_name(struct panthor_device *ptdev,
5fe909cae118a7 Boris Brezillon 2024-02-29  273  
   u32 exception_code);
5fe909cae118a7 Boris Brezillon 2024-02-29  274  
5fe909cae118a7 Boris Brezillon 2024-02-29  275  /**
5fe909cae118a7 Boris Brezillon 2024-02-29  276   * PANTHOR_IRQ_HANDLER() - 
Define interrupt handlers and the interrupt
5fe909cae118a7 Boris Brezillon 2024-02-29  277   * registration function.
5fe909cae118a7 Boris Brezillon 2024-02-29  278   *
5fe909cae118a7 Boris Brezillon 2024-02-29  279   * The boiler-plate to 
gracefully deal with shared interrupts is
5fe909cae118a7 Boris 

Re: [PATCH] dmabuf: fix dmabuf file poll uaf issue

2024-04-02 Thread T.J. Mercier
On Tue, Apr 2, 2024 at 1:08 AM Christian König  wrote:
>
> Am 02.04.24 um 08:49 schrieb zhiguojiang:
> >> As far as I can see that's not because of the DMA-buf code, but
> >> because you are somehow using this interface incorrectly.
> >>
> >> When dma_buf_poll() is called it is mandatory for the caller to hold
> >> a reference to the file descriptor on which the poll operation is
> >> executed.
> >>
> >> So adding code like "if (!file_count(file))" in the beginning of
> >> dma_buf_poll() is certainly broken.
> >>
> >> My best guess is that you have some unbalanced
> >> dma_buf_get()/dma_buf_put() somewhere instead.
> >>
> >>
> > Hi Christian,
> >
> > The kernel dma_buf_poll() code shound not cause system crashes due to
> > the user mode usage logical issues ?
>
> What user mode logical issues are you talking about? Closing a file
> while polling on it is perfectly valid.
>
> dma_buf_poll() is called by the filesystem layer and it's the filesystem
> layer which should make sure that a file can't be closed while polling
> for an event.
>
> If that doesn't work then you have stumbled over a massive bug in the fs
> layer. And I have some doubts that this is actually the case.
>
> What is more likely is that some driver messes up the reference count
> and because of this you see an UAF.
>
> Anyway as far as I can see the DMA-buf code is correct regarding this.
>
> Regards,
> Christian.

I tried to reproduce this problem but I couldn't. What I see is a ref
get taken when poll is first called. So subsequently closing the fd in
userspace while it's being polled doesn't take the refcount all the
way to 0. That happens when dma_buf_poll_cb fires, either due to an
event or when the fd is closed upon timeout.

I don't really see how this could be triggered from userspace so I am
also suspicious of dma_buf_get/put.


Re: [PATCH v0 03/14] drm/gma500,drm/i915: Make I2C terminology more inclusive

2024-04-02 Thread Easwar Hariharan
On 4/2/2024 9:52 AM, Jani Nikula wrote:
> On Tue, 02 Apr 2024, Easwar Hariharan  wrote:
>> On 4/2/2024 7:32 AM, Jani Nikula wrote:
>>> On Tue, 02 Apr 2024, Easwar Hariharan  wrote:
 On 4/2/2024 12:48 AM, Jani Nikula wrote:
> On Fri, 29 Mar 2024, Easwar Hariharan  
> wrote:
>> I2C v7, SMBus 3.2, and I3C specifications have replaced "master/slave"
>> with more appropriate terms. Inspired by and following on to Wolfram's
>> series to fix drivers/i2c/[1], fix the terminology for users of
>> I2C_ALGOBIT bitbanging interface, now that the approved verbiage exists
>> in the specification.
>
> gma500 and i915 changes should be split. See MAINTAINERS.
>
> Might also split the i915 changes to smaller pieces, it's kind of
> random. And the changes here are not strictly related to I2C AFAICT, so
> the commit message should be updated.
>
> BR,
> Jani.
>
>

 

 I will split gma500 and i915 into their respective patches if possible in 
 v2.

 Can you say more about the changes being "not strictly related to I2C"? My
 heuristic was to grep for master/slave, and look in the surrounding 
 context for
 i2c-related terminology (i2c_pin, 7-bit address, struct i2c_adapter, 
 i2c_bus, etc)
 to confirm that they are i2c-related, then following the references around 
 to
 make the compiler happy. For e.g., I did not change the many references to 
 bigjoiner
 master and slave because I understood from context they were not i2c 
 references.

 A couple examples would help me restrict the changes to I2C, since as 
 mentioned in the
 discussion on Wolfram's thread, there are places where migrating away from 
 master/slave
 terms in the code would conflict with the original technical manuals and 
 reduce correlation
 and understanding of the code.
>>>
>>> I guess I was looking at the VBT changes in intel_bios.c. Granted, they
>>> do end up being used as i2c addresses. No big deal.
>>>
>>> I think I'd expect the treewide i2c adapter changes to land first, via
>>> i2c, and subsequent cleanups to happen next, via individual driver
>>> trees. There's quite a bit of conflict potential merging this outside of
>>> drm-intel-next, and there's really no need for that.
>>>
>>> BR,
>>> Jani.
>>>
>>
>> Great! Just so I'm clear, do you still want the i915 changes split up more, 
>> along with them being
>> split off from gma500?
> 
> If we can merge the i915 changes via drm-intel-next, it's probably fine
> as a big i915 patch. Just the gma500 separated. (The struct
> i2c_algorithm change etc. necessarily has to go via I2C tree of course.)
> 
> BR,
> Jani.
> 

Got it. I'll send the split out in v1 (not v2 as mentioned earlier) since this 
is v0.

Thanks,
Easwar



[drm-misc:for-linux-next 3/4] drivers/gpu/drm/panthor/panthor_device.h:326:13: error: unused variable 'cookie'

2024-04-02 Thread kernel test robot
tree:   git://anongit.freedesktop.org/drm/drm-misc for-linux-next
head:   10021ef27310279c850cf6cb38542c443a995e92
commit: 962f88b9c91647f3ff4a0d3709662641baed5164 [3/4] drm/panthor: Drop the 
dev_enter/exit() sections in _irq_suspend/resume()
config: alpha-allyesconfig 
(https://download.01.org/0day-ci/archive/20240403/202404030237.5ykbs02j-...@intel.com/config)
compiler: alpha-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): 
(https://download.01.org/0day-ci/archive/20240403/202404030237.5ykbs02j-...@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot 
| Closes: 
https://lore.kernel.org/oe-kbuild-all/202404030237.5ykbs02j-...@intel.com/

All errors (new ones prefixed by >>):

   In file included from drivers/gpu/drm/panthor/panthor_fw.c:19:
   drivers/gpu/drm/panthor/panthor_fw.c: In function 'panthor_job_irq_suspend':
>> drivers/gpu/drm/panthor/panthor_device.h:326:13: error: unused variable 
>> 'cookie' [-Werror=unused-variable]
 326 | int cookie;  
   \
 | ^~
   drivers/gpu/drm/panthor/panthor_fw.c:979:1: note: in expansion of macro 
'PANTHOR_IRQ_HANDLER'
 979 | PANTHOR_IRQ_HANDLER(job, JOB, panthor_job_irq_handler);
 | ^~~
   drivers/gpu/drm/panthor/panthor_fw.c: In function 'panthor_job_irq_resume':
   drivers/gpu/drm/panthor/panthor_device.h:336:13: error: unused variable 
'cookie' [-Werror=unused-variable]
 336 | int cookie;  
   \
 | ^~
   drivers/gpu/drm/panthor/panthor_fw.c:979:1: note: in expansion of macro 
'PANTHOR_IRQ_HANDLER'
 979 | PANTHOR_IRQ_HANDLER(job, JOB, panthor_job_irq_handler);
 | ^~~
   cc1: all warnings being treated as errors
--
   In file included from drivers/gpu/drm/panthor/panthor_gpu.c:19:
   drivers/gpu/drm/panthor/panthor_gpu.c: In function 'panthor_gpu_irq_suspend':
>> drivers/gpu/drm/panthor/panthor_device.h:326:13: error: unused variable 
>> 'cookie' [-Werror=unused-variable]
 326 | int cookie;  
   \
 | ^~
   drivers/gpu/drm/panthor/panthor_gpu.c:166:1: note: in expansion of macro 
'PANTHOR_IRQ_HANDLER'
 166 | PANTHOR_IRQ_HANDLER(gpu, GPU, panthor_gpu_irq_handler);
 | ^~~
   drivers/gpu/drm/panthor/panthor_gpu.c: In function 'panthor_gpu_irq_resume':
   drivers/gpu/drm/panthor/panthor_device.h:336:13: error: unused variable 
'cookie' [-Werror=unused-variable]
 336 | int cookie;  
   \
 | ^~
   drivers/gpu/drm/panthor/panthor_gpu.c:166:1: note: in expansion of macro 
'PANTHOR_IRQ_HANDLER'
 166 | PANTHOR_IRQ_HANDLER(gpu, GPU, panthor_gpu_irq_handler);
 | ^~~
   cc1: all warnings being treated as errors
--
   In file included from drivers/gpu/drm/panthor/panthor_mmu.c:30:
   drivers/gpu/drm/panthor/panthor_mmu.c: In function 'panthor_mmu_irq_suspend':
>> drivers/gpu/drm/panthor/panthor_device.h:326:13: error: unused variable 
>> 'cookie' [-Werror=unused-variable]
 326 | int cookie;  
   \
 | ^~
   drivers/gpu/drm/panthor/panthor_mmu.c:1689:1: note: in expansion of macro 
'PANTHOR_IRQ_HANDLER'
1689 | PANTHOR_IRQ_HANDLER(mmu, MMU, panthor_mmu_irq_handler);
 | ^~~
   drivers/gpu/drm/panthor/panthor_mmu.c: In function 'panthor_mmu_irq_resume':
   drivers/gpu/drm/panthor/panthor_device.h:336:13: error: unused variable 
'cookie' [-Werror=unused-variable]
 336 | int cookie;  
   \
 | ^~
   drivers/gpu/drm/panthor/panthor_mmu.c:1689:1: note: in expansion of macro 
'PANTHOR_IRQ_HANDLER'
1689 | PANTHOR_IRQ_HANDLER(mmu, MMU, panthor_mmu_irq_handler);
 | ^~~
   cc1: all warnings being treated as errors


vim +/cookie +326 drivers/gpu/drm/panthor/panthor_device.h

5fe909cae118a7 Boris Brezillon 2024-02-29  271  
5fe909cae118a7 Boris Brezillon 2024-02-29  272  const char 
*panthor_exception_name(struct panthor_device *ptdev,
5fe909cae118a7 Boris Brezillon 2024-02-29  273  
   u32 exception_code);
5fe909cae118a7 Boris Brezillon 2024-02-29  274  
5fe909cae118a7 Boris Brezillon 2024-02-29  275  /**
5fe909cae118a7 Boris Brezillon 2024-02-29  276   * PANTHOR_IRQ_HANDLER() - 
Define interrupt handlers and the interrupt
5fe909cae118a7 Boris Brezillon 2024-02-29  277   * registration function.
5fe909cae118a7 Boris Brezill

Re: [PATCH 2/2] dt-bindings: display: bridge: lt8912b: document 'lontium,pn-swap' property

2024-04-02 Thread Conor Dooley
On Tue, Apr 02, 2024 at 01:59:25PM +0300, Alexandru Ardelean wrote:
> On some HW designs, it's easier for the layout if the P/N pins are swapped.
> The driver currently has a DT property to do that.

"currently", because 1/2 adds it. bindings patches should precede the
driver patches in the series, so please swap the patches and remove this
portion of the description.

> 
> This change documents the 'lontium,pn-swap' property.
> 
> Signed-off-by: Alexandru Ardelean 
> ---
>  .../devicetree/bindings/display/bridge/lontium,lt8912b.yaml | 6 ++
>  1 file changed, 6 insertions(+)
> 
> diff --git 
> a/Documentation/devicetree/bindings/display/bridge/lontium,lt8912b.yaml 
> b/Documentation/devicetree/bindings/display/bridge/lontium,lt8912b.yaml
> index 2cef252157985..3a804926b288a 100644
> --- a/Documentation/devicetree/bindings/display/bridge/lontium,lt8912b.yaml
> +++ b/Documentation/devicetree/bindings/display/bridge/lontium,lt8912b.yaml
> @@ -24,6 +24,12 @@ properties:
>  maxItems: 1
>  description: GPIO connected to active high RESET pin.
>  
> +  lontium,pn-swap:
> +description: Swap the polarities of the P/N pins in software.
> +  On some HW designs, the layout is simplified if the P/N pins
> +  are inverted.

Please explain what configuration of a board would cause these to be
swapped, rather than why someone might want to configure the board this
way. I've got no idea what this hardware is actually doing, so this is
being pulled out of a hat, but I'd expect something like "Some boards
swap the polarity of the P/N pins, use this property to indicate this to
software". 

> +type: boolean

The type here should be flag.

Cheers,
Conor.

> +
>ports:
>  $ref: /schemas/graph.yaml#/properties/ports
>  
> -- 
> 2.44.0
> 


signature.asc
Description: PGP signature


Re: [PATCH 1/2] drm/bridge: lt8912b: add support for P/N pin swap

2024-04-02 Thread Francesco Dolcini
Hello Alexandru, thanks for your patch.

On Tue, Apr 02, 2024 at 01:59:24PM +0300, Alexandru Ardelean wrote:
> On some HW designs, it's easier for the layout if the P/N pins are swapped.
> In those cases, we need to adjust (for this) by configuring the MIPI analog
> registers differently. Specifically, register 0x3e needs to be 0xf6
> (instead of 0xd6).
> 
> This change adds a 'lontium,pn-swap' device-tree property to configure the
> MIPI analog registers for P/N swap.
> 
> Signed-off-by: Alexandru Ardelean 
> ---
>  drivers/gpu/drm/bridge/lontium-lt8912b.c | 25 +---
>  1 file changed, 22 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/bridge/lontium-lt8912b.c 
> b/drivers/gpu/drm/bridge/lontium-lt8912b.c
> index 4b2ae27f0a57f..154126bb922b4 100644
> --- a/drivers/gpu/drm/bridge/lontium-lt8912b.c
> +++ b/drivers/gpu/drm/bridge/lontium-lt8912b.c
> @@ -47,6 +47,7 @@ struct lt8912 {
>  
>   u8 data_lanes;
>   bool is_power_on;
> + bool do_pn_swap;
>  };
>  
>  static int lt8912_write_init_config(struct lt8912 *lt)
> @@ -78,15 +79,31 @@ static int lt8912_write_init_config(struct lt8912 *lt)
>   {0x55, 0x44},
>   {0x57, 0x01},
>   {0x5a, 0x02},
> -
> - /*MIPI Analog*/
> + };
> + const struct reg_sequence mipi_analog_seq[] = {
>   {0x3e, 0xd6},
>   {0x3f, 0xd4},
>   {0x41, 0x3c},
>   {0xB2, 0x00},
>   };
> + const struct reg_sequence mipi_analog_pn_swap_seq[] = {
> + {0x3e, 0xf6},
> + {0x3f, 0xd4},
> + {0x41, 0x3c},
> + {0xB2, 0x00},
> + };
> + int ret;
>  
> - return regmap_multi_reg_write(lt->regmap[I2C_MAIN], seq, 
> ARRAY_SIZE(seq));
> + ret = regmap_multi_reg_write(lt->regmap[I2C_MAIN], seq, 
> ARRAY_SIZE(seq));
> + if (ret < 0)
> + return ret;
> +
> + if (!lt->do_pn_swap)
> + return regmap_multi_reg_write(lt->regmap[I2C_MAIN], 
> mipi_analog_seq,
> +   ARRAY_SIZE(mipi_analog_seq));
> +
> + return regmap_multi_reg_write(lt->regmap[I2C_MAIN], 
> mipi_analog_pn_swap_seq,
> +   ARRAY_SIZE(mipi_analog_pn_swap_seq));

Can you just remove {0x3e, 0xd6} from the register/value array and write
it afterward depending on `do_pn_swap` value? Or keep it with the
current value and only overwrite it when do_pn_swap is true?

If you do it this way is a 4 line change.


>  static int lt8912_write_mipi_basic_config(struct lt8912 *lt)
> @@ -702,6 +719,8 @@ static int lt8912_parse_dt(struct lt8912 *lt)
>   }
>   lt->gp_reset = gp_reset;
>  
> + lt->do_pn_swap = device_property_read_bool(dev, "lontium,pn-swap");

I would call this variable the same that is called in the lontium
documentation, mipirx_diff_swap

Francesco



Re: [PATCH v0 03/14] drm/gma500,drm/i915: Make I2C terminology more inclusive

2024-04-02 Thread Jani Nikula
On Tue, 02 Apr 2024, Easwar Hariharan  wrote:
> On 4/2/2024 7:32 AM, Jani Nikula wrote:
>> On Tue, 02 Apr 2024, Easwar Hariharan  wrote:
>>> On 4/2/2024 12:48 AM, Jani Nikula wrote:
 On Fri, 29 Mar 2024, Easwar Hariharan  wrote:
> I2C v7, SMBus 3.2, and I3C specifications have replaced "master/slave"
> with more appropriate terms. Inspired by and following on to Wolfram's
> series to fix drivers/i2c/[1], fix the terminology for users of
> I2C_ALGOBIT bitbanging interface, now that the approved verbiage exists
> in the specification.

 gma500 and i915 changes should be split. See MAINTAINERS.

 Might also split the i915 changes to smaller pieces, it's kind of
 random. And the changes here are not strictly related to I2C AFAICT, so
 the commit message should be updated.

 BR,
 Jani.


>>>
>>> 
>>>
>>> I will split gma500 and i915 into their respective patches if possible in 
>>> v2.
>>>
>>> Can you say more about the changes being "not strictly related to I2C"? My
>>> heuristic was to grep for master/slave, and look in the surrounding context 
>>> for
>>> i2c-related terminology (i2c_pin, 7-bit address, struct i2c_adapter, 
>>> i2c_bus, etc)
>>> to confirm that they are i2c-related, then following the references around 
>>> to
>>> make the compiler happy. For e.g., I did not change the many references to 
>>> bigjoiner
>>> master and slave because I understood from context they were not i2c 
>>> references.
>>>
>>> A couple examples would help me restrict the changes to I2C, since as 
>>> mentioned in the
>>> discussion on Wolfram's thread, there are places where migrating away from 
>>> master/slave
>>> terms in the code would conflict with the original technical manuals and 
>>> reduce correlation
>>> and understanding of the code.
>> 
>> I guess I was looking at the VBT changes in intel_bios.c. Granted, they
>> do end up being used as i2c addresses. No big deal.
>> 
>> I think I'd expect the treewide i2c adapter changes to land first, via
>> i2c, and subsequent cleanups to happen next, via individual driver
>> trees. There's quite a bit of conflict potential merging this outside of
>> drm-intel-next, and there's really no need for that.
>> 
>> BR,
>> Jani.
>> 
>
> Great! Just so I'm clear, do you still want the i915 changes split up more, 
> along with them being
> split off from gma500?

If we can merge the i915 changes via drm-intel-next, it's probably fine
as a big i915 patch. Just the gma500 separated. (The struct
i2c_algorithm change etc. necessarily has to go via I2C tree of course.)

BR,
Jani.



>
> Thanks,
> Easwar

-- 
Jani Nikula, Intel


Re: [PATCH v3] drm/panthor: Fix couple of NULL vs IS_ERR() bugs

2024-04-02 Thread Dan Carpenter
On Tue, Apr 02, 2024 at 05:19:25PM +0200, Boris Brezillon wrote:
> On Tue, 2 Apr 2024 17:44:18 +0300
> Dan Carpenter  wrote:
> 
> > On Tue, Apr 02, 2024 at 04:38:38PM +0200, Boris Brezillon wrote:
> > > On Tue,  2 Apr 2024 07:14:11 -0700
> > > Harshit Mogalapalli  wrote:
> > >   
> > > > Currently panthor_vm_get_heap_pool() returns both ERR_PTR() and
> > > > NULL(when create is false and if there is no poool attached to the  
> > > 
> > >^ pool
> > >   
> > > > VM)
> > > > - Change the function to return error pointers, when pool is
> > > >   NULL return -ENOENT
> > > > - Also handle the callers to check for IS_ERR() on failure.
> > > > 
> > > > Fixes: 4bdca1150792 ("drm/panthor: Add the driver frontend block")  
> > > 
> > > I would explain that the code was correct, but the documentation didn't
> > > match the function behavior, otherwise it feels a bit weird to have a
> > > Fixes tag here.  
> > 
> > The code wasn't correct, it returned a mix of error pointers and NULL.
> 
> AFAICT, this is allowed, otherwise why would we have IS_ERR_OR_NULL().

Yep.  I have written a blog about this:
https://staticthinking.wordpress.com/2022/08/01/mixing-error-pointers-and-null/

> The fact smatch can't see through panthor_vm_get_heap_pool() and detect
> that the return value is different for create=false/true doesn't mean
> the code was wrong. I'm certainly not saying this is a good thing to
> have a function that encodes the error case with two different kind of
> return value, but I wouldn't qualify it as a bug either. What's
> incorrect though, is the fact the documentation doesn't match the code.
> 
> > So it needs a Fixes tag.
> 
> I didn't say we should drop the Fixes tag, but the bug being fixed here
> is a mismatch between the doc and the implementation, the code itself
> was correct, and the behavior is actually unchanged with this patch
> applied, it's just done in a less confusing way.

Oh.  Sorry, I haven't been following this thread closely and I misread
the code as well.  You're right that the code works.  In this case, I
would say actually that it does not need a Fixes tag because it's not
a bug.  It's just a cleanup.

Sorry for the noise.

regards,
dan carpenter



Re: [PATCH v0 03/14] drm/gma500,drm/i915: Make I2C terminology more inclusive

2024-04-02 Thread Easwar Hariharan
On 4/2/2024 7:32 AM, Jani Nikula wrote:
> On Tue, 02 Apr 2024, Easwar Hariharan  wrote:
>> On 4/2/2024 12:48 AM, Jani Nikula wrote:
>>> On Fri, 29 Mar 2024, Easwar Hariharan  wrote:
 I2C v7, SMBus 3.2, and I3C specifications have replaced "master/slave"
 with more appropriate terms. Inspired by and following on to Wolfram's
 series to fix drivers/i2c/[1], fix the terminology for users of
 I2C_ALGOBIT bitbanging interface, now that the approved verbiage exists
 in the specification.
>>>
>>> gma500 and i915 changes should be split. See MAINTAINERS.
>>>
>>> Might also split the i915 changes to smaller pieces, it's kind of
>>> random. And the changes here are not strictly related to I2C AFAICT, so
>>> the commit message should be updated.
>>>
>>> BR,
>>> Jani.
>>>
>>>
>>
>> 
>>
>> I will split gma500 and i915 into their respective patches if possible in v2.
>>
>> Can you say more about the changes being "not strictly related to I2C"? My
>> heuristic was to grep for master/slave, and look in the surrounding context 
>> for
>> i2c-related terminology (i2c_pin, 7-bit address, struct i2c_adapter, 
>> i2c_bus, etc)
>> to confirm that they are i2c-related, then following the references around to
>> make the compiler happy. For e.g., I did not change the many references to 
>> bigjoiner
>> master and slave because I understood from context they were not i2c 
>> references.
>>
>> A couple examples would help me restrict the changes to I2C, since as 
>> mentioned in the
>> discussion on Wolfram's thread, there are places where migrating away from 
>> master/slave
>> terms in the code would conflict with the original technical manuals and 
>> reduce correlation
>> and understanding of the code.
> 
> I guess I was looking at the VBT changes in intel_bios.c. Granted, they
> do end up being used as i2c addresses. No big deal.
> 
> I think I'd expect the treewide i2c adapter changes to land first, via
> i2c, and subsequent cleanups to happen next, via individual driver
> trees. There's quite a bit of conflict potential merging this outside of
> drm-intel-next, and there's really no need for that.
> 
> BR,
> Jani.
> 

Great! Just so I'm clear, do you still want the i915 changes split up more, 
along with them being
split off from gma500?

Thanks,
Easwar


Re: [PATCH v3 07/13] drm: Make drivers depends on DRM_DW_HDMI

2024-04-02 Thread Mark Brown
On Wed, Mar 27, 2024 at 11:57:02AM +0100, Maxime Ripard wrote:

> DRM_DW_HDMI has a number of dependencies that might not be enabled.
> However, drivers were used to selecting it while not enforcing the
> DRM_DW_HDMI dependencies.
> 
> This could result in Kconfig warnings (and further build breakages) such
> as:
> 
>   Kconfig warnings: (for reference only)
>  WARNING: unmet direct dependencies detected for DRM_DW_HDMI
>  Depends on [n]: HAS_IOMEM [=y] && DRM [=m] && DRM_BRIDGE [=y] && 
> DRM_DISPLAY_HELPER [=n]
>  Selected by [m]:
>  - DRM_SUN8I_DW_HDMI [=m] && HAS_IOMEM [=y] && DRM_SUN4I [=m]

This has landed in -next and appears to be causing breakage for several
platforms using these devices.  For example I'm seeing the HDMI fail to
probe on sun50i-a64-pin64-plus with arm64 defconfig, the DT kselftest
result isn't terribly informative but it can be seen here:

   https://lava.sirena.org.uk/scheduler/job/78288#L6007

which I bisected to this change:

# bad: [c0b832517f627ead3388c6f0c74e8ac10ad5774b] Add linux-next specific files 
for 20240402
# good: [0fc83069bcaee78f60b8511d9453a9441963a072] Merge branch 
'for-linux-next-fixes' of https://gitlab.freedesktop.org/drm/misc/kernel.git
# good: [ba5206881843e16b74a07c37970dcc44d22f8f6f] spi: spi.h: add missing 
kernel-doc for @last_cs_index_mask
# good: [64fe73d10323e399b2e8eb5407390bcb302a046c] spi: fsl: remove 
is_dma_mapped checks
# good: [bb77c99ee6d3d704086acf141d3ec92601747809] spi: pxa2xx: Skip SSP 
initialization if it's done elsewhere
# good: [e64d3b6fc9a388d7dc516668651cf4404bffec9b] spi: omap2-mcpsi: Enable 
MULTI-mode in more situations
# good: [57ad033ce09d4d0c866ac558fc3c4cf53cfb2599] ASoC: Intel: sof_cs42l42: 
add mtl_cs42l42_def for mtl boards
# good: [7b5f2072657a9041cbaf4ba139f672be11694ca3] ASoC: dt-bindings: fsl-sai: 
allow only one dma-names
# good: [a5bef84422eb066ee8fa5c13960657a79b3cc1e7] spi: fsl-dspi: drop driver 
owner assignment
# good: [29580cd7b9c6f975e88597ca66a001b16b97bae9] ASoC: sdw-mockup: drop 
driver owner assignment
# good: [ea60ab95723f5738e7737b56dda95e6feefa5b50] ASoC: kirkwood: Fix 
potential NULL dereference
# good: [c0a3873b9938bfaa77bd337cad33266a50a6583f] ASoC: nau8325: new driver
# good: [559aebe45a054a479fdbd2a3dfba999ffd73cc9d] ASoC: sun8i-codec: Fix build 
with CONFIG_SND_JACK_INPUT_DEV disabled
# good: [d5449432f794e75cd4f5e46bc33bfe6ce20b657d] spi: pxa2xx: Switch to use 
dev_err_probe()
# good: [7b95ee0db7e0a7f99077f1b926323c7bf0d2e8f8] ASoC: soc-jack: Get rid of 
legacy GPIO support
# good: [ea5fee227ff3dae209062ac9544906debe1e9ac1] ASoC: hdac_hda: improve 
error logs
# good: [4ed0915f5bc4bcc81bca783a5b984f3d81e9764e] ASoC: codecs: Add RK3308 
internal audio codec driver
# good: [59ffeb15b2f7b44cf934fd778dc0d98a35aa6a84] ASoC: Intel: sof_sdw: Add 
support for cs42l43 optional speaker output
# good: [1e90a846493c716e3e6b4d901fc0844e9eea6430] ASoC: soc-dai: Note valid 
values of sysclock direction
# good: [61cafaeab5bca2d3e6a68ee8fa92b5c10b8610ca] ASoC: Intel: sof_rt5682: 
board id cleanup for cml boards
# good: [9b163e0d330debbf7dcc14b2c3e2dc19a3b50a1d] spi: remove struct 
spi_message::is_dma_mapped
# good: [b340f56a74b62d8ce8617650c8ab4a26c87ba5c5] ASoC: dt-bindings: wm8974: 
Convert to dtschema
# good: [bdeef5dcea6b164f4bd614655821b1ef12ebec9a] spi: rspi: Get rid of unused 
struct rspi_plat_data
# good: [885dd75f41f9fff5b277bc6ab28ad798f98a37b4] ASoC: dt-bindings: fsl-esai: 
Convert fsl,esai.txt to yaml
# good: [10402419f2d60890525f590b54d0eaec3de0d87a] spi: spi-mt65xx: Rename a 
variable in interrupt handler
# good: [9855f05e553637f05494cf47a3154cbf9a5cfc67] ASoC: fsl: imx-es8328: 
Switch to using gpiod API
# good: [5f39231888c63f0a7708abc86b51b847476379d8] ASoC: mediatek: Assign dummy 
when codec not specified for a DAI link
# good: [5edeb7d312628961046eec9b26a7e72f44baf846] regulator: pca9450: add 
pca9451a support
# good: [c14445bdcb98feddf9afaeb05e6193cc1f8eec1a] ASoC: fsl: imx-rpmsg: Update 
to correct DT node
# good: [a39111b1cf0864b1782f30f9a1fa65260d057327] spi: xilinx: Make 
num_chipselect 8-bit in the struct xspi_platform_data
# good: [b5867a5c0d7a6bf36f59f3d472c7aed33ca4d02c] spi: pxa2xx: Use proper SSP 
header in soc/pxa/ssp.c
# good: [60c10c678b582d41532fefa12667d8adca75811b] ASoC: Intel: avs: i2s_test: 
Remove redundant dapm routes
# good: [21fa98f4197bb3365dda1417708b318f403c13c1] ASoC: sun8i-codec: Implement 
jack and accessory detection
# good: [cee28113db17f0de58df0eaea4e2756c404ee01f] ASoC: dmaengine_pcm: Allow 
passing component name via config
# good: [aad6b35290f52639d3601063d33d9621c0948a04] regmap: maple: Remove second 
semicolon
# good: [e6913c6ef83c80aa7569c9e0820454fbf542] ASoC: codecs: ES8326: Delete 
unused REG_SUPPLY
# good: [0c5f77f4eaef8ed9fe752d21f40ac471dd511cfc] dt-bindings: regulator: 
qcom,usb-vbus-regulator: Add PM7250B compatible
# good: [ab

Re: [PATCH v3] drm/panthor: Fix couple of NULL vs IS_ERR() bugs

2024-04-02 Thread Boris Brezillon
On Tue, 2 Apr 2024 17:44:18 +0300
Dan Carpenter  wrote:

> On Tue, Apr 02, 2024 at 04:38:38PM +0200, Boris Brezillon wrote:
> > On Tue,  2 Apr 2024 07:14:11 -0700
> > Harshit Mogalapalli  wrote:
> >   
> > > Currently panthor_vm_get_heap_pool() returns both ERR_PTR() and
> > > NULL(when create is false and if there is no poool attached to the  
> > 
> >^ pool
> >   
> > > VM)
> > >   - Change the function to return error pointers, when pool is
> > > NULL return -ENOENT
> > >   - Also handle the callers to check for IS_ERR() on failure.
> > > 
> > > Fixes: 4bdca1150792 ("drm/panthor: Add the driver frontend block")  
> > 
> > I would explain that the code was correct, but the documentation didn't
> > match the function behavior, otherwise it feels a bit weird to have a
> > Fixes tag here.  
> 
> The code wasn't correct, it returned a mix of error pointers and NULL.

AFAICT, this is allowed, otherwise why would we have IS_ERR_OR_NULL().
The fact smatch can't see through panthor_vm_get_heap_pool() and detect
that the return value is different for create=false/true doesn't mean
the code was wrong. I'm certainly not saying this is a good thing to
have a function that encodes the error case with two different kind of
return value, but I wouldn't qualify it as a bug either. What's
incorrect though, is the fact the documentation doesn't match the code.

> So it needs a Fixes tag.

I didn't say we should drop the Fixes tag, but the bug being fixed here
is a mismatch between the doc and the implementation, the code itself
was correct, and the behavior is actually unchanged with this patch
applied, it's just done in a less confusing way.

Regards,

Boris


Re: [PATCH v4 10/10] drm/vboxvideo: fix mapping leaks

2024-04-02 Thread Hans de Goede
Hi,

On 4/2/24 3:50 PM, Philipp Stanner wrote:
> On Thu, 2024-03-28 at 12:55 -0500, Bjorn Helgaas wrote:
>> On Fri, Mar 01, 2024 at 12:29:58PM +0100, Philipp Stanner wrote:
>>> When the PCI devres API was introduced to this driver, it was
>>> wrongly
>>> assumed that initializing the device with pcim_enable_device()
>>> instead
>>> of pci_enable_device() will make all PCI functions managed.
>>>
>>> This is wrong and was caused by the quite confusing PCI devres API
>>> in
>>> which some, but not all, functions become managed that way.
>>>
>>> The function pci_iomap_range() is never managed.
>>>
>>> Replace pci_iomap_range() with the actually managed function
>>> pcim_iomap_range().
>>>
>>> CC:  # v5.10+
>>
>> This is marked for stable but depends on the preceding patches in
>> this
>> series, which are not marked for stable.
>>
>> The rest of this series might be picked up automatically for stable,
>> but I personally wouldn't suggest backporting it because it's quite a
>> lot of change and I don't think it fits per
>> Documentation/process/stable-kernel-rules.rst.
> 
> I agree, if I were a stable maintainer I wouldn't apply it.
> I just put them in CC so that they can make this decision themselves.
> 
>> So I think the best way to fix the vboxvideo leaks would be to fix
>> them independently of this series, then include as a separate patch a
>> conversion to the new pcim_iomap_range() in this series (or possibly
>> for the next merge window to avoid merge conflicts).
> 
> It is hard to fix independently of our new devres utility.
> Reason being that it's _impossible_ to have partial BAR mappings *with*
> the current PCI devres API.
> 
> Consequently, a portable vboxvideo would have to revert the entire
> commit 8558de401b5f and become an unmanaged driver again.
> 
> I guess you could do a hacky fix where the regions are handled by
> devres and the mappings are created and destroyed manually with
> pci_iomap_range() – but do we really want that...?
> 
> The leak only occurs when driver and device detach, so how often does
> that happen... and as far as I can tell it's also not an exploitable
> leak, so one could make the decision to just leave it in the stable
> kernels...
> 
> @Hans:
> What do you say?

In practice this has never been a problem, so I suggest we just drop
the Cc: stable .

Regards,

Hans




>>> Fixes: 8558de401b5f ("drm/vboxvideo: use managed pci functions")
>>> Signed-off-by: Philipp Stanner 
>>> ---
>>>  drivers/gpu/drm/vboxvideo/vbox_main.c | 20 +---
>>>  1 file changed, 9 insertions(+), 11 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/vboxvideo/vbox_main.c
>>> b/drivers/gpu/drm/vboxvideo/vbox_main.c
>>> index 42c2d8a99509..d4ade9325401 100644
>>> --- a/drivers/gpu/drm/vboxvideo/vbox_main.c
>>> +++ b/drivers/gpu/drm/vboxvideo/vbox_main.c
>>> @@ -42,12 +42,11 @@ static int vbox_accel_init(struct vbox_private
>>> *vbox)
>>> /* Take a command buffer for each screen from the end of
>>> usable VRAM. */
>>> vbox->available_vram_size -= vbox->num_crtcs *
>>> VBVA_MIN_BUFFER_SIZE;
>>>  
>>> -   vbox->vbva_buffers = pci_iomap_range(pdev, 0,
>>> -    vbox-
 available_vram_size,
>>> -    vbox->num_crtcs *
>>> -    VBVA_MIN_BUFFER_SIZE);
>>> -   if (!vbox->vbva_buffers)
>>> -   return -ENOMEM;
>>> +   vbox->vbva_buffers = pcim_iomap_range(
>>> +   pdev, 0, vbox->available_vram_size,
>>> +   vbox->num_crtcs * VBVA_MIN_BUFFER_SIZE);
>>> +   if (IS_ERR(vbox->vbva_buffers))
>>> +   return PTR_ERR(vbox->vbva_buffers);
>>>  
>>> for (i = 0; i < vbox->num_crtcs; ++i) {
>>> vbva_setup_buffer_context(&vbox->vbva_info[i],
>>> @@ -116,11 +115,10 @@ int vbox_hw_init(struct vbox_private *vbox)
>>> DRM_INFO("VRAM %08x\n", vbox->full_vram_size);
>>>  
>>> /* Map guest-heap at end of vram */
>>> -   vbox->guest_heap =
>>> -   pci_iomap_range(pdev, 0, GUEST_HEAP_OFFSET(vbox),
>>> -   GUEST_HEAP_SIZE);
>>> -   if (!vbox->guest_heap)
>>> -   return -ENOMEM;
>>> +   vbox->guest_heap = pcim_iomap_range(pdev, 0,
>>> +   GUEST_HEAP_OFFSET(vbox), GUEST_HEAP_SIZE);
>>> +   if (IS_ERR(vbox->guest_heap))
>>> +   return PTR_ERR(vbox->guest_heap);
>>>  
>>> /* Create guest-heap mem-pool use 2^4 = 16 byte chunks */
>>> vbox->guest_pool = devm_gen_pool_create(vbox->ddev.dev, 4,
>>> -1,
>>> -- 
>>> 2.43.0
>>>
>>
> 



Re: [PATCH v3] drm/panthor: Fix couple of NULL vs IS_ERR() bugs

2024-04-02 Thread Dan Carpenter
On Tue, Apr 02, 2024 at 04:38:38PM +0200, Boris Brezillon wrote:
> On Tue,  2 Apr 2024 07:14:11 -0700
> Harshit Mogalapalli  wrote:
> 
> > Currently panthor_vm_get_heap_pool() returns both ERR_PTR() and
> > NULL(when create is false and if there is no poool attached to the
> 
>^ pool
> 
> > VM)
> > - Change the function to return error pointers, when pool is
> >   NULL return -ENOENT
> > - Also handle the callers to check for IS_ERR() on failure.
> > 
> > Fixes: 4bdca1150792 ("drm/panthor: Add the driver frontend block")
> 
> I would explain that the code was correct, but the documentation didn't
> match the function behavior, otherwise it feels a bit weird to have a
> Fixes tag here.

The code wasn't correct, it returned a mix of error pointers and NULL.
So it needs a Fixes tag.

regards,
dan carpenter



Re: [PATCH v3] drm/panthor: Fix couple of NULL vs IS_ERR() bugs

2024-04-02 Thread Boris Brezillon
On Tue,  2 Apr 2024 07:14:11 -0700
Harshit Mogalapalli  wrote:

> Currently panthor_vm_get_heap_pool() returns both ERR_PTR() and
> NULL(when create is false and if there is no poool attached to the

   ^ pool

> VM)
>   - Change the function to return error pointers, when pool is
> NULL return -ENOENT
>   - Also handle the callers to check for IS_ERR() on failure.
> 
> Fixes: 4bdca1150792 ("drm/panthor: Add the driver frontend block")

I would explain that the code was correct, but the documentation didn't
match the function behavior, otherwise it feels a bit weird to have a
Fixes tag here.

> Signed-off-by: Harshit Mogalapalli 
> ---
> This is spotted by smatch and the patch is only compile tested
> 
> v1->v2: Fix the function panthor_vm_get_heap_pool() to only return error
> pointers and handle the caller sites [Suggested by Boris Brezillon]
> - Also merge these IS_ERR() vs NULL bugs into same patch
> 
> v2->v3: pull out error checking for devm_drm_dev_alloc() failure.
> ---
>  drivers/gpu/drm/panthor/panthor_drv.c   | 4 ++--
>  drivers/gpu/drm/panthor/panthor_mmu.c   | 2 ++
>  drivers/gpu/drm/panthor/panthor_sched.c | 2 +-
>  3 files changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/panthor/panthor_drv.c 
> b/drivers/gpu/drm/panthor/panthor_drv.c
> index 11b3ccd58f85..050b905b0453 100644
> --- a/drivers/gpu/drm/panthor/panthor_drv.c
> +++ b/drivers/gpu/drm/panthor/panthor_drv.c
> @@ -1090,8 +1090,8 @@ static int panthor_ioctl_tiler_heap_destroy(struct 
> drm_device *ddev, void *data,
>   return -EINVAL;
>  
>   pool = panthor_vm_get_heap_pool(vm, false);
> - if (!pool) {
> - ret = -EINVAL;
> + if (IS_ERR(pool)) {
> + ret = PTR_ERR(pool);
>   goto out_put_vm;
>   }
>  
> diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c 
> b/drivers/gpu/drm/panthor/panthor_mmu.c
> index fdd35249169f..e1285cdb09ff 100644
> --- a/drivers/gpu/drm/panthor/panthor_mmu.c
> +++ b/drivers/gpu/drm/panthor/panthor_mmu.c
> @@ -1893,6 +1893,8 @@ struct panthor_heap_pool 
> *panthor_vm_get_heap_pool(struct panthor_vm *vm, bool c
>   vm->heaps.pool = panthor_heap_pool_get(pool);
>   } else {
>   pool = panthor_heap_pool_get(vm->heaps.pool);
> + if (!pool)
> + pool = ERR_PTR(-ENOENT);
>   }
>   mutex_unlock(&vm->heaps.lock);
>  
> diff --git a/drivers/gpu/drm/panthor/panthor_sched.c 
> b/drivers/gpu/drm/panthor/panthor_sched.c
> index 5f7803b6fc48..617df2b980d0 100644
> --- a/drivers/gpu/drm/panthor/panthor_sched.c
> +++ b/drivers/gpu/drm/panthor/panthor_sched.c
> @@ -1343,7 +1343,7 @@ static int group_process_tiler_oom(struct panthor_group 
> *group, u32 cs_id)
>   if (unlikely(csg_id < 0))
>   return 0;
>  
> - if (!heaps || frag_end > vt_end || vt_end >= vt_start) {
> + if (IS_ERR(heaps) || frag_end > vt_end || vt_end >= vt_start) {
>   ret = -EINVAL;
>   } else {
>   /* We do the allocation without holding the scheduler lock to 
> avoid



Re: [PATCH v0 03/14] drm/gma500,drm/i915: Make I2C terminology more inclusive

2024-04-02 Thread Jani Nikula
On Tue, 02 Apr 2024, Easwar Hariharan  wrote:
> On 4/2/2024 12:48 AM, Jani Nikula wrote:
>> On Fri, 29 Mar 2024, Easwar Hariharan  wrote:
>>> I2C v7, SMBus 3.2, and I3C specifications have replaced "master/slave"
>>> with more appropriate terms. Inspired by and following on to Wolfram's
>>> series to fix drivers/i2c/[1], fix the terminology for users of
>>> I2C_ALGOBIT bitbanging interface, now that the approved verbiage exists
>>> in the specification.
>> 
>> gma500 and i915 changes should be split. See MAINTAINERS.
>> 
>> Might also split the i915 changes to smaller pieces, it's kind of
>> random. And the changes here are not strictly related to I2C AFAICT, so
>> the commit message should be updated.
>> 
>> BR,
>> Jani.
>> 
>> 
>
> 
>
> I will split gma500 and i915 into their respective patches if possible in v2.
>
> Can you say more about the changes being "not strictly related to I2C"? My
> heuristic was to grep for master/slave, and look in the surrounding context 
> for
> i2c-related terminology (i2c_pin, 7-bit address, struct i2c_adapter, i2c_bus, 
> etc)
> to confirm that they are i2c-related, then following the references around to
> make the compiler happy. For e.g., I did not change the many references to 
> bigjoiner
> master and slave because I understood from context they were not i2c 
> references.
>
> A couple examples would help me restrict the changes to I2C, since as 
> mentioned in the
> discussion on Wolfram's thread, there are places where migrating away from 
> master/slave
> terms in the code would conflict with the original technical manuals and 
> reduce correlation
> and understanding of the code.

I guess I was looking at the VBT changes in intel_bios.c. Granted, they
do end up being used as i2c addresses. No big deal.

I think I'd expect the treewide i2c adapter changes to land first, via
i2c, and subsequent cleanups to happen next, via individual driver
trees. There's quite a bit of conflict potential merging this outside of
drm-intel-next, and there's really no need for that.

BR,
Jani.




>
> Thanks,
> Easwar
>

-- 
Jani Nikula, Intel


Re: [PATCH v12 2/8] mm/gup: Introduce check_and_migrate_movable_folios()

2024-04-02 Thread David Hildenbrand

On 25.02.24 08:56, Vivek Kasireddy wrote:

This helper is the folio equivalent of check_and_migrate_movable_pages().
Therefore, all the rules that apply to check_and_migrate_movable_pages()
also apply to this one as well. Currently, this helper is only used by
memfd_pin_folios().

This patch also includes changes to rename and convert the internal
functions collect_longterm_unpinnable_pages() and
migrate_longterm_unpinnable_pages() to work on folios. Since they
are also used by check_and_migrate_movable_pages(), a temporary
array is used to collect and share the folios with these functions.

Cc: David Hildenbrand 
Cc: Matthew Wilcox 
Cc: Christoph Hellwig 
Cc: Jason Gunthorpe 
Cc: Peter Xu 
Suggested-by: David Hildenbrand 
Signed-off-by: Vivek Kasireddy 
---
  mm/gup.c | 129 +++
  1 file changed, 92 insertions(+), 37 deletions(-)

diff --git a/mm/gup.c b/mm/gup.c
index 0a45eda6aaeb..1410af954a4e 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -2099,20 +2099,24 @@ struct page *get_dump_page(unsigned long addr)
  
  #ifdef CONFIG_MIGRATION

  /*
- * Returns the number of collected pages. Return value is always >= 0.
+ * Returns the number of collected folios. Return value is always >= 0.
   */
-static unsigned long collect_longterm_unpinnable_pages(
-   struct list_head *movable_page_list,
-   unsigned long nr_pages,
+static unsigned long collect_longterm_unpinnable_folios(
+   struct list_head *movable_folio_list,
+   unsigned long nr_folios,
+   struct folio **folios,
struct page **pages)


This function really shouldn't consume both folios and pages.

Either use "folios" and handle the conversion from pages->folios in the 
caller, or handle it similar to release_pages() where we can pass either 
and simply always do page_folio() on the given pointer, using 
essentially an abstracted pointer type and always calling page_folio() 
on that thing.


The easiest is likely to just do the page->folio conversion in the 
caller by looping over the arrays once more. See below.


Temporary memory allocation can be avoided by using an abstracted 
pointer type.


[...]

  
+		folio = folios[i];

if (folio == prev_folio)
continue;
prev_folio = folio;
@@ -2126,7 +2130,7 @@ static unsigned long collect_longterm_unpinnable_pages(
continue;
  
  		if (folio_test_hugetlb(folio)) {

-   isolate_hugetlb(folio, movable_page_list);
+   isolate_hugetlb(folio, movable_folio_list);
continue;
}
  
@@ -2138,7 +2142,7 @@ static unsigned long collect_longterm_unpinnable_pages(

if (!folio_isolate_lru(folio))
continue;
  
-		list_add_tail(&folio->lru, movable_page_list);

+   list_add_tail(&folio->lru, movable_folio_list);
node_stat_mod_folio(folio,
NR_ISOLATED_ANON + folio_is_file_lru(folio),
folio_nr_pages(folio));
@@ -2148,27 +2152,28 @@ static unsigned long collect_longterm_unpinnable_pages(
  }
  
  /*

- * Unpins all pages and migrates device coherent pages and movable_page_list.
- * Returns -EAGAIN if all pages were successfully migrated or -errno for 
failure
- * (or partial success).
+ * Unpins all folios and migrates device coherent folios and 
movable_folio_list.
+ * Returns -EAGAIN if all folios were successfully migrated or -errno for
+ * failure (or partial success).
   */
-static int migrate_longterm_unpinnable_pages(
-   struct list_head *movable_page_list,
-   unsigned long nr_pages,
-   struct page **pages)
+static int migrate_longterm_unpinnable_folios(
+   struct list_head *movable_folio_list,
+   unsigned long nr_folios,
+   struct folio **folios)
  {
int ret;
unsigned long i;
  
-	for (i = 0; i < nr_pages; i++) {

-   struct folio *folio = page_folio(pages[i]);
+   for (i = 0; i < nr_folios; i++) {
+   struct folio *folio = folios[i];
  
  		if (folio_is_device_coherent(folio)) {

/*
-* Migration will fail if the page is pinned, so convert
-* the pin on the source page to a normal reference.
+* Migration will fail if the folio is pinned, so
+* convert the pin on the source folio to a normal
+* reference.
 */
-   pages[i] 

[PATCH v3] drm/panthor: Fix couple of NULL vs IS_ERR() bugs

2024-04-02 Thread Harshit Mogalapalli
Currently panthor_vm_get_heap_pool() returns both ERR_PTR() and
NULL(when create is false and if there is no poool attached to the
VM)
- Change the function to return error pointers, when pool is
  NULL return -ENOENT
- Also handle the callers to check for IS_ERR() on failure.

Fixes: 4bdca1150792 ("drm/panthor: Add the driver frontend block")
Signed-off-by: Harshit Mogalapalli 
---
This is spotted by smatch and the patch is only compile tested

v1->v2: Fix the function panthor_vm_get_heap_pool() to only return error
pointers and handle the caller sites [Suggested by Boris Brezillon]
- Also merge these IS_ERR() vs NULL bugs into same patch

v2->v3: pull out error checking for devm_drm_dev_alloc() failure.
---
 drivers/gpu/drm/panthor/panthor_drv.c   | 4 ++--
 drivers/gpu/drm/panthor/panthor_mmu.c   | 2 ++
 drivers/gpu/drm/panthor/panthor_sched.c | 2 +-
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/panthor/panthor_drv.c 
b/drivers/gpu/drm/panthor/panthor_drv.c
index 11b3ccd58f85..050b905b0453 100644
--- a/drivers/gpu/drm/panthor/panthor_drv.c
+++ b/drivers/gpu/drm/panthor/panthor_drv.c
@@ -1090,8 +1090,8 @@ static int panthor_ioctl_tiler_heap_destroy(struct 
drm_device *ddev, void *data,
return -EINVAL;
 
pool = panthor_vm_get_heap_pool(vm, false);
-   if (!pool) {
-   ret = -EINVAL;
+   if (IS_ERR(pool)) {
+   ret = PTR_ERR(pool);
goto out_put_vm;
}
 
diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c 
b/drivers/gpu/drm/panthor/panthor_mmu.c
index fdd35249169f..e1285cdb09ff 100644
--- a/drivers/gpu/drm/panthor/panthor_mmu.c
+++ b/drivers/gpu/drm/panthor/panthor_mmu.c
@@ -1893,6 +1893,8 @@ struct panthor_heap_pool *panthor_vm_get_heap_pool(struct 
panthor_vm *vm, bool c
vm->heaps.pool = panthor_heap_pool_get(pool);
} else {
pool = panthor_heap_pool_get(vm->heaps.pool);
+   if (!pool)
+   pool = ERR_PTR(-ENOENT);
}
mutex_unlock(&vm->heaps.lock);
 
diff --git a/drivers/gpu/drm/panthor/panthor_sched.c 
b/drivers/gpu/drm/panthor/panthor_sched.c
index 5f7803b6fc48..617df2b980d0 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.c
+++ b/drivers/gpu/drm/panthor/panthor_sched.c
@@ -1343,7 +1343,7 @@ static int group_process_tiler_oom(struct panthor_group 
*group, u32 cs_id)
if (unlikely(csg_id < 0))
return 0;
 
-   if (!heaps || frag_end > vt_end || vt_end >= vt_start) {
+   if (IS_ERR(heaps) || frag_end > vt_end || vt_end >= vt_start) {
ret = -EINVAL;
} else {
/* We do the allocation without holding the scheduler lock to 
avoid
-- 
2.39.3



Re: [PATCH v12 1/8] mm/gup: Introduce unpin_folio/unpin_folios helpers

2024-04-02 Thread David Hildenbrand

On 02.04.24 15:52, David Hildenbrand wrote:

On 25.02.24 08:56, Vivek Kasireddy wrote:

These helpers are the folio versions of unpin_user_page/unpin_user_pages.
They are currently only useful for unpinning folios pinned by
memfd_pin_folios() or other associated routines. However, they could
find new uses in the future, when more and more folio-only helpers
are added to GUP.

Cc: David Hildenbrand 
Cc: Matthew Wilcox 
Cc: Christoph Hellwig 
Cc: Jason Gunthorpe 
Cc: Peter Xu 
Suggested-by: David Hildenbrand 
Signed-off-by: Vivek Kasireddy 
---
   include/linux/mm.h |  2 ++
   mm/gup.c   | 81 --
   2 files changed, 74 insertions(+), 9 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 6f4825d82965..36e4c2b22600 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1601,11 +1601,13 @@ static inline void put_page(struct page *page)
   #define GUP_PIN_COUNTING_BIAS (1U << 10)
   
   void unpin_user_page(struct page *page);

+void unpin_folio(struct folio *folio);
   void unpin_user_pages_dirty_lock(struct page **pages, unsigned long npages,
 bool make_dirty);
   void unpin_user_page_range_dirty_lock(struct page *page, unsigned long 
npages,
  bool make_dirty);
   void unpin_user_pages(struct page **pages, unsigned long npages);
+void unpin_folios(struct folio **folios, unsigned long nfolios);
   
   static inline bool is_cow_mapping(vm_flags_t flags)

   {
diff --git a/mm/gup.c b/mm/gup.c
index df83182ec72d..0a45eda6aaeb 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -30,6 +30,23 @@ struct follow_page_context {
unsigned int page_mask;
   };
   
+static inline void sanity_check_pinned_folios(struct folio **folios,

+ unsigned long nfolios)
+{
+   if (!IS_ENABLED(CONFIG_DEBUG_VM))
+   return;
+
+   for (; nfolios; nfolios--, folios++) {
+   struct folio *folio = *folios;
+
+   if (is_zero_folio(folio) ||
+   !folio_test_anon(folio))
+   continue;
+
+   VM_BUG_ON_FOLIO(!PageAnonExclusive(&folio->page), folio);


That change is wrong (and the split makes the check confusing).

It could be that the first subpage is no longer exclusive, but the given
(sanity_check_pinned_pages() ) subpage is exclusive for large folios.

I suggest dropping that change, and instead, in
unpin_folio()/unpin_folios(), reject any anon folios for now.

So, replace the sanity_check_pinned_folios() in unpin_folio() /
unpin_folios() by a VM_WARN_ON(folio_test_anon(folio));


After reading patch #2: drop both the sanity check and VM_WARN_ON() from 
unpin_folio()/unpin_folios(), and add a comment to the patch description 
that we cannot do the sanity checking without the subpage, and that we 
can reintroduce it once we have a single per-folio AnonExclusive bit.


--
Cheers,

David / dhildenb



Re: [PATCH v2] drm/panthor: Fix couple of NULL vs IS_ERR() bugs

2024-04-02 Thread Boris Brezillon
On Tue, 2 Apr 2024 19:35:41 +0530
Harshit Mogalapalli  wrote:

> Hi Boris,
> On 02/04/24 19:32, Boris Brezillon wrote:
> > On Tue,  2 Apr 2024 06:47:08 -0700
> > Harshit Mogalapalli  wrote:
> >   
> >> 1. The devm_drm_dev_alloc() function returns error pointers.
> >> Update the error handling to check for error pointers instead of NULL.
> >> 2. Currently panthor_vm_get_heap_pool() returns both ERR_PTR() and
> >> NULL(when create is false and if there is no poool attached to the
> >> VM)
> >>- Change the function to return error pointers, when pool is
> >>  NULL return -ENOENT
> >>- Also handle the callers to check for IS_ERR() on failure.
> >>
> >> Fixes: 4bdca1150792 ("drm/panthor: Add the driver frontend block")
> >> Signed-off-by: Harshit Mogalapalli 
> >> ---
> >> This is spotted by smatch and the patch is only compile tested
> >>
> >> v1->v2: Fix the function panthor_vm_get_heap_pool() to only return error
> >> pointers and handle the caller sites [Suggested by Boris Brezillon]
> >>- Also merge these IS_ERR() vs NULL bugs into same patch
> >> ---
> >>   drivers/gpu/drm/panthor/panthor_drv.c   | 6 +++---
> >>   drivers/gpu/drm/panthor/panthor_mmu.c   | 2 ++
> >>   drivers/gpu/drm/panthor/panthor_sched.c | 2 +-
> >>   3 files changed, 6 insertions(+), 4 deletions(-)
> >>
> >> diff --git a/drivers/gpu/drm/panthor/panthor_drv.c 
> >> b/drivers/gpu/drm/panthor/panthor_drv.c
> >> index 11b3ccd58f85..c8374cd4a30d 100644
> >> --- a/drivers/gpu/drm/panthor/panthor_drv.c
> >> +++ b/drivers/gpu/drm/panthor/panthor_drv.c
> >> @@ -1090,8 +1090,8 @@ static int panthor_ioctl_tiler_heap_destroy(struct 
> >> drm_device *ddev, void *data,
> >>return -EINVAL;
> >>   
> >>pool = panthor_vm_get_heap_pool(vm, false);
> >> -  if (!pool) {
> >> -  ret = -EINVAL;
> >> +  if (IS_ERR(pool)) {
> >> +  ret = PTR_ERR(pool);
> >>goto out_put_vm;
> >>}
> >>   
> >> @@ -1385,7 +1385,7 @@ static int panthor_probe(struct platform_device 
> >> *pdev)
> >>   
> >>ptdev = devm_drm_dev_alloc(&pdev->dev, &panthor_drm_driver,
> >>   struct panthor_device, base);
> >> -  if (!ptdev)
> >> +  if (IS_ERR(ptdev))
> >>return -ENOMEM;
> >> 
> > 
> > Sorry, that one deserves a separate patch.
> >   
> 
> Ah okay, I was confused about the same.
> So I will send a V3 removing that part and could you please use the 
> independent patch that I sent before ?
> 
> https://lore.kernel.org/all/20240402104041.1689951-1-harshit.m.mogalapa...@oracle.com/

Yes, I already added my R-b on that one.


Re: [PATCH v2] drm/panthor: Fix couple of NULL vs IS_ERR() bugs

2024-04-02 Thread Harshit Mogalapalli

Hi Boris,
On 02/04/24 19:32, Boris Brezillon wrote:

On Tue,  2 Apr 2024 06:47:08 -0700
Harshit Mogalapalli  wrote:


1. The devm_drm_dev_alloc() function returns error pointers.
Update the error handling to check for error pointers instead of NULL.
2. Currently panthor_vm_get_heap_pool() returns both ERR_PTR() and
NULL(when create is false and if there is no poool attached to the
VM)
- Change the function to return error pointers, when pool is
  NULL return -ENOENT
- Also handle the callers to check for IS_ERR() on failure.

Fixes: 4bdca1150792 ("drm/panthor: Add the driver frontend block")
Signed-off-by: Harshit Mogalapalli 
---
This is spotted by smatch and the patch is only compile tested

v1->v2: Fix the function panthor_vm_get_heap_pool() to only return error
pointers and handle the caller sites [Suggested by Boris Brezillon]
- Also merge these IS_ERR() vs NULL bugs into same patch
---
  drivers/gpu/drm/panthor/panthor_drv.c   | 6 +++---
  drivers/gpu/drm/panthor/panthor_mmu.c   | 2 ++
  drivers/gpu/drm/panthor/panthor_sched.c | 2 +-
  3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/panthor/panthor_drv.c 
b/drivers/gpu/drm/panthor/panthor_drv.c
index 11b3ccd58f85..c8374cd4a30d 100644
--- a/drivers/gpu/drm/panthor/panthor_drv.c
+++ b/drivers/gpu/drm/panthor/panthor_drv.c
@@ -1090,8 +1090,8 @@ static int panthor_ioctl_tiler_heap_destroy(struct 
drm_device *ddev, void *data,
return -EINVAL;
  
  	pool = panthor_vm_get_heap_pool(vm, false);

-   if (!pool) {
-   ret = -EINVAL;
+   if (IS_ERR(pool)) {
+   ret = PTR_ERR(pool);
goto out_put_vm;
}
  
@@ -1385,7 +1385,7 @@ static int panthor_probe(struct platform_device *pdev)
  
  	ptdev = devm_drm_dev_alloc(&pdev->dev, &panthor_drm_driver,

   struct panthor_device, base);
-   if (!ptdev)
+   if (IS_ERR(ptdev))
return -ENOMEM;
  


Sorry, that one deserves a separate patch.



Ah okay, I was confused about the same.
So I will send a V3 removing that part and could you please use the 
independent patch that I sent before ?


https://lore.kernel.org/all/20240402104041.1689951-1-harshit.m.mogalapa...@oracle.com/

Thanks,
Harshit


platform_set_drvdata(pdev, ptdev);
diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c 
b/drivers/gpu/drm/panthor/panthor_mmu.c
index fdd35249169f..e1285cdb09ff 100644
--- a/drivers/gpu/drm/panthor/panthor_mmu.c
+++ b/drivers/gpu/drm/panthor/panthor_mmu.c
@@ -1893,6 +1893,8 @@ struct panthor_heap_pool *panthor_vm_get_heap_pool(struct 
panthor_vm *vm, bool c
vm->heaps.pool = panthor_heap_pool_get(pool);
} else {
pool = panthor_heap_pool_get(vm->heaps.pool);
+   if (!pool)
+   pool = ERR_PTR(-ENOENT);
}
mutex_unlock(&vm->heaps.lock);
  
diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c

index 5f7803b6fc48..617df2b980d0 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.c
+++ b/drivers/gpu/drm/panthor/panthor_sched.c
@@ -1343,7 +1343,7 @@ static int group_process_tiler_oom(struct panthor_group 
*group, u32 cs_id)
if (unlikely(csg_id < 0))
return 0;
  
-	if (!heaps || frag_end > vt_end || vt_end >= vt_start) {

+   if (IS_ERR(heaps) || frag_end > vt_end || vt_end >= vt_start) {
ret = -EINVAL;
} else {
/* We do the allocation without holding the scheduler lock to 
avoid







Re: [PATCH] drm/panthor: Fix NULL vs IS_ERR() bug in panthor_probe()

2024-04-02 Thread Boris Brezillon
On Tue,  2 Apr 2024 03:40:40 -0700
Harshit Mogalapalli  wrote:

> The devm_drm_dev_alloc() function returns error pointers.
> Update the error handling to check for error pointers instead of NULL.
> 
> Fixes: 4bdca1150792 ("drm/panthor: Add the driver frontend block")
> Signed-off-by: Harshit Mogalapalli 

Reviewed-by: Boris Brezillon 

> ---
> This is spotted by smatch and the patch is only compile tested
> ---
>  drivers/gpu/drm/panthor/panthor_drv.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/panthor/panthor_drv.c 
> b/drivers/gpu/drm/panthor/panthor_drv.c
> index 11b3ccd58f85..1b588b37db98 100644
> --- a/drivers/gpu/drm/panthor/panthor_drv.c
> +++ b/drivers/gpu/drm/panthor/panthor_drv.c
> @@ -1385,7 +1385,7 @@ static int panthor_probe(struct platform_device *pdev)
>  
>   ptdev = devm_drm_dev_alloc(&pdev->dev, &panthor_drm_driver,
>  struct panthor_device, base);
> - if (!ptdev)
> + if (IS_ERR(ptdev))
>   return -ENOMEM;
>  
>   platform_set_drvdata(pdev, ptdev);



Re: [PATCH v2] drm/panthor: Fix couple of NULL vs IS_ERR() bugs

2024-04-02 Thread Boris Brezillon
On Tue,  2 Apr 2024 06:47:08 -0700
Harshit Mogalapalli  wrote:

> 1. The devm_drm_dev_alloc() function returns error pointers.
>Update the error handling to check for error pointers instead of NULL.
> 2. Currently panthor_vm_get_heap_pool() returns both ERR_PTR() and
>NULL(when create is false and if there is no poool attached to the
>VM)
>   - Change the function to return error pointers, when pool is
> NULL return -ENOENT
>   - Also handle the callers to check for IS_ERR() on failure.
> 
> Fixes: 4bdca1150792 ("drm/panthor: Add the driver frontend block")
> Signed-off-by: Harshit Mogalapalli 
> ---
> This is spotted by smatch and the patch is only compile tested
> 
> v1->v2: Fix the function panthor_vm_get_heap_pool() to only return error
> pointers and handle the caller sites [Suggested by Boris Brezillon]
>   - Also merge these IS_ERR() vs NULL bugs into same patch
> ---
>  drivers/gpu/drm/panthor/panthor_drv.c   | 6 +++---
>  drivers/gpu/drm/panthor/panthor_mmu.c   | 2 ++
>  drivers/gpu/drm/panthor/panthor_sched.c | 2 +-
>  3 files changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/gpu/drm/panthor/panthor_drv.c 
> b/drivers/gpu/drm/panthor/panthor_drv.c
> index 11b3ccd58f85..c8374cd4a30d 100644
> --- a/drivers/gpu/drm/panthor/panthor_drv.c
> +++ b/drivers/gpu/drm/panthor/panthor_drv.c
> @@ -1090,8 +1090,8 @@ static int panthor_ioctl_tiler_heap_destroy(struct 
> drm_device *ddev, void *data,
>   return -EINVAL;
>  
>   pool = panthor_vm_get_heap_pool(vm, false);
> - if (!pool) {
> - ret = -EINVAL;
> + if (IS_ERR(pool)) {
> + ret = PTR_ERR(pool);
>   goto out_put_vm;
>   }
>  
> @@ -1385,7 +1385,7 @@ static int panthor_probe(struct platform_device *pdev)
>  
>   ptdev = devm_drm_dev_alloc(&pdev->dev, &panthor_drm_driver,
>  struct panthor_device, base);
> - if (!ptdev)
> + if (IS_ERR(ptdev))
>   return -ENOMEM;
>  

Sorry, that one deserves a separate patch.

>   platform_set_drvdata(pdev, ptdev);
> diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c 
> b/drivers/gpu/drm/panthor/panthor_mmu.c
> index fdd35249169f..e1285cdb09ff 100644
> --- a/drivers/gpu/drm/panthor/panthor_mmu.c
> +++ b/drivers/gpu/drm/panthor/panthor_mmu.c
> @@ -1893,6 +1893,8 @@ struct panthor_heap_pool 
> *panthor_vm_get_heap_pool(struct panthor_vm *vm, bool c
>   vm->heaps.pool = panthor_heap_pool_get(pool);
>   } else {
>   pool = panthor_heap_pool_get(vm->heaps.pool);
> + if (!pool)
> + pool = ERR_PTR(-ENOENT);
>   }
>   mutex_unlock(&vm->heaps.lock);
>  
> diff --git a/drivers/gpu/drm/panthor/panthor_sched.c 
> b/drivers/gpu/drm/panthor/panthor_sched.c
> index 5f7803b6fc48..617df2b980d0 100644
> --- a/drivers/gpu/drm/panthor/panthor_sched.c
> +++ b/drivers/gpu/drm/panthor/panthor_sched.c
> @@ -1343,7 +1343,7 @@ static int group_process_tiler_oom(struct panthor_group 
> *group, u32 cs_id)
>   if (unlikely(csg_id < 0))
>   return 0;
>  
> - if (!heaps || frag_end > vt_end || vt_end >= vt_start) {
> + if (IS_ERR(heaps) || frag_end > vt_end || vt_end >= vt_start) {
>   ret = -EINVAL;
>   } else {
>   /* We do the allocation without holding the scheduler lock to 
> avoid



[PATCH v2] drm: ensure drm headers are self-contained and pass kernel-doc

2024-04-02 Thread Jani Nikula
Ensure drm headers build, are self-contained, have header guards, and
have no kernel-doc warnings, when CONFIG_DRM_HEADER_TEST=y.

The mechanism follows similar patters used in i915, xe, and usr/include.

To cover include/drm, we need to recurse there using the top level
Kbuild and the new include/Kbuild files.

v2: make DRM_HEADER_TEST depend on DRM

Suggested-by: Daniel Vetter 
Cc: David Airlie 
Cc: Daniel Vetter 
Cc: Maarten Lankhorst 
Cc: Maxime Ripard 
Cc: Thomas Zimmermann 
Cc: Masahiro Yamada 
Acked-by: Thomas Zimmermann 
Signed-off-by: Jani Nikula 
---
 Kbuild   |  1 +
 drivers/gpu/drm/Kconfig  | 11 +++
 drivers/gpu/drm/Makefile | 18 ++
 include/Kbuild   |  1 +
 include/drm/Makefile | 18 ++
 5 files changed, 49 insertions(+)
 create mode 100644 include/Kbuild
 create mode 100644 include/drm/Makefile

diff --git a/Kbuild b/Kbuild
index 464b34a08f51..f327ca86990c 100644
--- a/Kbuild
+++ b/Kbuild
@@ -97,3 +97,4 @@ obj-$(CONFIG_SAMPLES) += samples/
 obj-$(CONFIG_NET)  += net/
 obj-y  += virt/
 obj-y  += $(ARCH_DRIVERS)
+obj-$(CONFIG_DRM_HEADER_TEST)  += include/
diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index 3914aaf443a8..a388c4fda984 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -431,3 +431,14 @@ config DRM_WERROR
  this config option is disabled by default.
 
  If in doubt, say N.
+
+config DRM_HEADER_TEST
+   bool "Ensure DRM headers are self-contained and pass kernel-doc"
+   depends on DRM && EXPERT
+   default n
+   help
+ Ensure the DRM subsystem headers both under drivers/gpu/drm and
+ include/drm compile, are self-contained, have header guards, and have
+ no kernel-doc warnings.
+
+ If in doubt, say N.
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index a73c04d2d7a3..6605d5686d01 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -218,3 +218,21 @@ obj-y  += solomon/
 obj-$(CONFIG_DRM_SPRD) += sprd/
 obj-$(CONFIG_DRM_LOONGSON) += loongson/
 obj-$(CONFIG_DRM_POWERVR) += imagination/
+
+# Ensure drm headers are self-contained and pass kernel-doc
+hdrtest-files := \
+   $(shell cd $(srctree)/$(src) && find . -maxdepth 1 -name 'drm_*.h') \
+   $(shell cd $(srctree)/$(src) && find display lib -name '*.h')
+
+always-$(CONFIG_DRM_HEADER_TEST) += \
+   $(patsubst %.h,%.hdrtest, $(hdrtest-files))
+
+# Include the header twice to detect missing include guard.
+quiet_cmd_hdrtest = HDRTEST $(patsubst %.hdrtest,%.h,$@)
+  cmd_hdrtest = \
+   $(CC) $(c_flags) -fsyntax-only -x c /dev/null -include $< 
-include $<; \
+   $(srctree)/scripts/kernel-doc -none $(if 
$(CONFIG_DRM_WERROR),-Werror) $<; \
+   touch $@
+
+$(obj)/%.hdrtest: $(src)/%.h FORCE
+   $(call if_changed_dep,hdrtest)
diff --git a/include/Kbuild b/include/Kbuild
new file mode 100644
index ..5e76a599e2dd
--- /dev/null
+++ b/include/Kbuild
@@ -0,0 +1 @@
+obj-$(CONFIG_DRM_HEADER_TEST)  += drm/
diff --git a/include/drm/Makefile b/include/drm/Makefile
new file mode 100644
index ..b9f391d7aadd
--- /dev/null
+++ b/include/drm/Makefile
@@ -0,0 +1,18 @@
+# SPDX-License-Identifier: GPL-2.0
+
+# Ensure drm headers are self-contained and pass kernel-doc
+hdrtest-files := \
+   $(shell cd $(srctree)/$(src) && find * -name '*.h' 2>/dev/null)
+
+always-$(CONFIG_DRM_HEADER_TEST) += \
+   $(patsubst %.h,%.hdrtest, $(hdrtest-files))
+
+# Include the header twice to detect missing include guard.
+quiet_cmd_hdrtest = HDRTEST $(patsubst %.hdrtest,%.h,$@)
+  cmd_hdrtest = \
+   $(CC) $(c_flags) -fsyntax-only -x c /dev/null -include $< 
-include $<; \
+   $(srctree)/scripts/kernel-doc -none $(if 
$(CONFIG_DRM_WERROR),-Werror) $<; \
+   touch $@
+
+$(obj)/%.hdrtest: $(src)/%.h FORCE
+   $(call if_changed_dep,hdrtest)
-- 
2.39.2



Re: [PATCH v12 1/8] mm/gup: Introduce unpin_folio/unpin_folios helpers

2024-04-02 Thread David Hildenbrand

On 25.02.24 08:56, Vivek Kasireddy wrote:

These helpers are the folio versions of unpin_user_page/unpin_user_pages.
They are currently only useful for unpinning folios pinned by
memfd_pin_folios() or other associated routines. However, they could
find new uses in the future, when more and more folio-only helpers
are added to GUP.

Cc: David Hildenbrand 
Cc: Matthew Wilcox 
Cc: Christoph Hellwig 
Cc: Jason Gunthorpe 
Cc: Peter Xu 
Suggested-by: David Hildenbrand 
Signed-off-by: Vivek Kasireddy 
---
  include/linux/mm.h |  2 ++
  mm/gup.c   | 81 --
  2 files changed, 74 insertions(+), 9 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 6f4825d82965..36e4c2b22600 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1601,11 +1601,13 @@ static inline void put_page(struct page *page)
  #define GUP_PIN_COUNTING_BIAS (1U << 10)
  
  void unpin_user_page(struct page *page);

+void unpin_folio(struct folio *folio);
  void unpin_user_pages_dirty_lock(struct page **pages, unsigned long npages,
 bool make_dirty);
  void unpin_user_page_range_dirty_lock(struct page *page, unsigned long npages,
  bool make_dirty);
  void unpin_user_pages(struct page **pages, unsigned long npages);
+void unpin_folios(struct folio **folios, unsigned long nfolios);
  
  static inline bool is_cow_mapping(vm_flags_t flags)

  {
diff --git a/mm/gup.c b/mm/gup.c
index df83182ec72d..0a45eda6aaeb 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -30,6 +30,23 @@ struct follow_page_context {
unsigned int page_mask;
  };
  
+static inline void sanity_check_pinned_folios(struct folio **folios,

+ unsigned long nfolios)
+{
+   if (!IS_ENABLED(CONFIG_DEBUG_VM))
+   return;
+
+   for (; nfolios; nfolios--, folios++) {
+   struct folio *folio = *folios;
+
+   if (is_zero_folio(folio) ||
+   !folio_test_anon(folio))
+   continue;
+
+   VM_BUG_ON_FOLIO(!PageAnonExclusive(&folio->page), folio);


That change is wrong (and the split makes the check confusing).

It could be that the first subpage is no longer exclusive, but the given 
(sanity_check_pinned_pages() ) subpage is exclusive for large folios.


I suggest dropping that change, and instead, in 
unpin_folio()/unpin_folios(), reject any anon folios for now.


So, replace the sanity_check_pinned_folios() in unpin_folio() / 
unpin_folios() by a VM_WARN_ON(folio_test_anon(folio));


It will all be better once we have a single anon-exclusive flag per 
folio (which I am working on), but in the meantime, we really don't 
expect code that called pin_user_pages() to call unpin_folios().


[...]

  
+/**

+ * unpin_folio() - release a dma-pinned folio
+ * @folio: pointer to folio to be released
+ *
+ * Folios that were pinned via memfd_pin_folios() or other similar routines
+ * must be released either using unpin_folio() or unpin_folios(). This is so
+ * that such folios can be separately tracked and uniquely handled.


I'd drop the last sentence; no need for apologies/explanations, this is 
simply how ;pinning works :)



+ */
+void unpin_folio(struct folio *folio)
+{
+   sanity_check_pinned_folios(&folio, 1);
+   gup_put_folio(folio, 1, FOLL_PIN);
+}
+EXPORT_SYMBOL(unpin_folio);


Can we restrict that to EXPORT_SYMBOL_GPL for now? memfd_pin_folios() 
uses EXPORT_SYMBOL_GPL...



+
  /**
   * folio_add_pin - Try to get an additional pin on a pinned folio
   * @folio: The folio to be pinned
@@ -488,6 +516,41 @@ void unpin_user_pages(struct page **pages, unsigned long 
npages)
  }
  EXPORT_SYMBOL(unpin_user_pages);
  
+/**

+ * unpin_folios() - release an array of gup-pinned folios.
+ * @folios:  array of folios to be marked dirty and released.
+ * @nfolios: number of folios in the @folios array.
+ *
+ * For each folio in the @folios array, release the folio using unpin_folio().
+ *
+ * Please see the unpin_folio() documentation for details.
+ */
+void unpin_folios(struct folio **folios, unsigned long nfolios)
+{
+   unsigned long i = 0, j;
+
+   /*
+* If this WARN_ON() fires, then the system *might* be leaking folios
+* (by leaving them pinned), but probably not. More likely, gup/pup
+* returned a hard -ERRNO error to the caller, who erroneously passed
+* it here.
+*/
+   if (WARN_ON(IS_ERR_VALUE(nfolios)))
+   return;
+
+   sanity_check_pinned_folios(folios, nfolios);
+   while (i < nfolios) {
+   for (j = i + 1; j < nfolios; j++)
+   if (folios[i] != folios[j])
+   break;
+
+   if (folios[i])
+   gup_put_folio(folios[i], j - i, FOLL_PIN);
+   i = j;
+   }
+}
+EXPORT_SYMBOL(unpin_folios);


Same thought here.

--
Cheers,

David / dhilde

Re: [PATCH v4 10/10] drm/vboxvideo: fix mapping leaks

2024-04-02 Thread Philipp Stanner
On Thu, 2024-03-28 at 12:55 -0500, Bjorn Helgaas wrote:
> On Fri, Mar 01, 2024 at 12:29:58PM +0100, Philipp Stanner wrote:
> > When the PCI devres API was introduced to this driver, it was
> > wrongly
> > assumed that initializing the device with pcim_enable_device()
> > instead
> > of pci_enable_device() will make all PCI functions managed.
> > 
> > This is wrong and was caused by the quite confusing PCI devres API
> > in
> > which some, but not all, functions become managed that way.
> > 
> > The function pci_iomap_range() is never managed.
> > 
> > Replace pci_iomap_range() with the actually managed function
> > pcim_iomap_range().
> > 
> > CC:  # v5.10+
> 
> This is marked for stable but depends on the preceding patches in
> this
> series, which are not marked for stable.
> 
> The rest of this series might be picked up automatically for stable,
> but I personally wouldn't suggest backporting it because it's quite a
> lot of change and I don't think it fits per
> Documentation/process/stable-kernel-rules.rst.

I agree, if I were a stable maintainer I wouldn't apply it.
I just put them in CC so that they can make this decision themselves.

> So I think the best way to fix the vboxvideo leaks would be to fix
> them independently of this series, then include as a separate patch a
> conversion to the new pcim_iomap_range() in this series (or possibly
> for the next merge window to avoid merge conflicts).

It is hard to fix independently of our new devres utility.
Reason being that it's _impossible_ to have partial BAR mappings *with*
the current PCI devres API.

Consequently, a portable vboxvideo would have to revert the entire
commit 8558de401b5f and become an unmanaged driver again.

I guess you could do a hacky fix where the regions are handled by
devres and the mappings are created and destroyed manually with
pci_iomap_range() – but do we really want that...?

The leak only occurs when driver and device detach, so how often does
that happen... and as far as I can tell it's also not an exploitable
leak, so one could make the decision to just leave it in the stable
kernels...

@Hans:
What do you say?


P.

> 
> > Fixes: 8558de401b5f ("drm/vboxvideo: use managed pci functions")
> > Signed-off-by: Philipp Stanner 
> > ---
> >  drivers/gpu/drm/vboxvideo/vbox_main.c | 20 +---
> >  1 file changed, 9 insertions(+), 11 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/vboxvideo/vbox_main.c
> > b/drivers/gpu/drm/vboxvideo/vbox_main.c
> > index 42c2d8a99509..d4ade9325401 100644
> > --- a/drivers/gpu/drm/vboxvideo/vbox_main.c
> > +++ b/drivers/gpu/drm/vboxvideo/vbox_main.c
> > @@ -42,12 +42,11 @@ static int vbox_accel_init(struct vbox_private
> > *vbox)
> > /* Take a command buffer for each screen from the end of
> > usable VRAM. */
> > vbox->available_vram_size -= vbox->num_crtcs *
> > VBVA_MIN_BUFFER_SIZE;
> >  
> > -   vbox->vbva_buffers = pci_iomap_range(pdev, 0,
> > -    vbox-
> > >available_vram_size,
> > -    vbox->num_crtcs *
> > -    VBVA_MIN_BUFFER_SIZE);
> > -   if (!vbox->vbva_buffers)
> > -   return -ENOMEM;
> > +   vbox->vbva_buffers = pcim_iomap_range(
> > +   pdev, 0, vbox->available_vram_size,
> > +   vbox->num_crtcs * VBVA_MIN_BUFFER_SIZE);
> > +   if (IS_ERR(vbox->vbva_buffers))
> > +   return PTR_ERR(vbox->vbva_buffers);
> >  
> > for (i = 0; i < vbox->num_crtcs; ++i) {
> > vbva_setup_buffer_context(&vbox->vbva_info[i],
> > @@ -116,11 +115,10 @@ int vbox_hw_init(struct vbox_private *vbox)
> > DRM_INFO("VRAM %08x\n", vbox->full_vram_size);
> >  
> > /* Map guest-heap at end of vram */
> > -   vbox->guest_heap =
> > -   pci_iomap_range(pdev, 0, GUEST_HEAP_OFFSET(vbox),
> > -   GUEST_HEAP_SIZE);
> > -   if (!vbox->guest_heap)
> > -   return -ENOMEM;
> > +   vbox->guest_heap = pcim_iomap_range(pdev, 0,
> > +   GUEST_HEAP_OFFSET(vbox), GUEST_HEAP_SIZE);
> > +   if (IS_ERR(vbox->guest_heap))
> > +   return PTR_ERR(vbox->guest_heap);
> >  
> > /* Create guest-heap mem-pool use 2^4 = 16 byte chunks */
> > vbox->guest_pool = devm_gen_pool_create(vbox->ddev.dev, 4,
> > -1,
> > -- 
> > 2.43.0
> > 
> 



[PATCH v2] drm/panthor: Fix couple of NULL vs IS_ERR() bugs

2024-04-02 Thread Harshit Mogalapalli
1. The devm_drm_dev_alloc() function returns error pointers.
   Update the error handling to check for error pointers instead of NULL.
2. Currently panthor_vm_get_heap_pool() returns both ERR_PTR() and
   NULL(when create is false and if there is no poool attached to the
   VM)
- Change the function to return error pointers, when pool is
  NULL return -ENOENT
- Also handle the callers to check for IS_ERR() on failure.

Fixes: 4bdca1150792 ("drm/panthor: Add the driver frontend block")
Signed-off-by: Harshit Mogalapalli 
---
This is spotted by smatch and the patch is only compile tested

v1->v2: Fix the function panthor_vm_get_heap_pool() to only return error
pointers and handle the caller sites [Suggested by Boris Brezillon]
- Also merge these IS_ERR() vs NULL bugs into same patch
---
 drivers/gpu/drm/panthor/panthor_drv.c   | 6 +++---
 drivers/gpu/drm/panthor/panthor_mmu.c   | 2 ++
 drivers/gpu/drm/panthor/panthor_sched.c | 2 +-
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/panthor/panthor_drv.c 
b/drivers/gpu/drm/panthor/panthor_drv.c
index 11b3ccd58f85..c8374cd4a30d 100644
--- a/drivers/gpu/drm/panthor/panthor_drv.c
+++ b/drivers/gpu/drm/panthor/panthor_drv.c
@@ -1090,8 +1090,8 @@ static int panthor_ioctl_tiler_heap_destroy(struct 
drm_device *ddev, void *data,
return -EINVAL;
 
pool = panthor_vm_get_heap_pool(vm, false);
-   if (!pool) {
-   ret = -EINVAL;
+   if (IS_ERR(pool)) {
+   ret = PTR_ERR(pool);
goto out_put_vm;
}
 
@@ -1385,7 +1385,7 @@ static int panthor_probe(struct platform_device *pdev)
 
ptdev = devm_drm_dev_alloc(&pdev->dev, &panthor_drm_driver,
   struct panthor_device, base);
-   if (!ptdev)
+   if (IS_ERR(ptdev))
return -ENOMEM;
 
platform_set_drvdata(pdev, ptdev);
diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c 
b/drivers/gpu/drm/panthor/panthor_mmu.c
index fdd35249169f..e1285cdb09ff 100644
--- a/drivers/gpu/drm/panthor/panthor_mmu.c
+++ b/drivers/gpu/drm/panthor/panthor_mmu.c
@@ -1893,6 +1893,8 @@ struct panthor_heap_pool *panthor_vm_get_heap_pool(struct 
panthor_vm *vm, bool c
vm->heaps.pool = panthor_heap_pool_get(pool);
} else {
pool = panthor_heap_pool_get(vm->heaps.pool);
+   if (!pool)
+   pool = ERR_PTR(-ENOENT);
}
mutex_unlock(&vm->heaps.lock);
 
diff --git a/drivers/gpu/drm/panthor/panthor_sched.c 
b/drivers/gpu/drm/panthor/panthor_sched.c
index 5f7803b6fc48..617df2b980d0 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.c
+++ b/drivers/gpu/drm/panthor/panthor_sched.c
@@ -1343,7 +1343,7 @@ static int group_process_tiler_oom(struct panthor_group 
*group, u32 cs_id)
if (unlikely(csg_id < 0))
return 0;
 
-   if (!heaps || frag_end > vt_end || vt_end >= vt_start) {
+   if (IS_ERR(heaps) || frag_end > vt_end || vt_end >= vt_start) {
ret = -EINVAL;
} else {
/* We do the allocation without holding the scheduler lock to 
avoid
-- 
2.39.3



Re: [PATCH v10 0/9] Improve test coverage of TTM

2024-04-02 Thread Somalapuram, Amaranath
some issue with the latest drm-misc:  (commit 
4c4f33be7e4d476566246e7166c54ef175287e00 (origin/for-linux-next, 
origin/drm-misc-next, origin/HEAD))


Regards,
S.Amarnath

$ make ARCH=um O=.kunit --jobs=16
ERROR:root:../arch/x86/um/user-offsets.c:17:6: warning: no previous 
prototype for ‘foo’ [-Wmissing-prototypes]

   17 | void foo(void)
  |  ^~~
In file included from ../arch/um/kernel/asm-offsets.c:1:
../arch/x86/um/shared/sysdep/kernel-offsets.h:9:6: warning: no previous 
prototype for ‘foo’ [-Wmissing-prototypes]

    9 | void foo(void)
  |  ^~~
../arch/x86/um/os-Linux/registers.c:146:15: warning: no previous 
prototype for ‘get_thread_reg’ [-Wmissing-prototypes]

  146 | unsigned long get_thread_reg(int reg, jmp_buf *buf)
  |   ^~
../arch/x86/um/vdso/um_vdso.c:16:5: warning: no previous prototype for 
‘__vdso_clock_gettime’ [-Wmissing-prototypes]
   16 | int __vdso_clock_gettime(clockid_t clock, struct 
__kernel_old_timespec *ts)

  | ^~~~
../arch/x86/um/vdso/um_vdso.c:30:5: warning: no previous prototype for 
‘__vdso_gettimeofday’ [-Wmissing-prototypes]
   30 | int __vdso_gettimeofday(struct __kernel_old_timeval *tv, struct 
timezone *tz)

  | ^~~
../arch/x86/um/vdso/um_vdso.c:44:21: warning: no previous prototype for 
‘__vdso_time’ [-Wmissing-prototypes]

   44 | __kernel_old_time_t __vdso_time(__kernel_old_time_t *t)
  | ^~~
../arch/x86/um/vdso/um_vdso.c:57:1: warning: no previous prototype for 
‘__vdso_getcpu’ [-Wmissing-prototypes]
   57 | __vdso_getcpu(unsigned *cpu, unsigned *node, struct 
getcpu_cache *unused)

  | ^
../arch/x86/um/bugs_64.c:9:6: warning: no previous prototype for 
‘arch_check_bugs’ [-Wmissing-prototypes]

    9 | void arch_check_bugs(void)
  |  ^~~
../arch/x86/um/bugs_64.c:13:6: warning: no previous prototype for 
‘arch_examine_signal’ [-Wmissing-prototypes]

   13 | void arch_examine_signal(int sig, struct uml_pt_regs *regs)
  |  ^~~
../arch/x86/um/os-Linux/mcontext.c:7:6: warning: no previous prototype 
for ‘get_regs_from_mc’ [-Wmissing-prototypes]

    7 | void get_regs_from_mc(struct uml_pt_regs *regs, mcontext_t *mc)
  |  ^~~~
../arch/um/os-Linux/skas/process.c:107:6: warning: no previous prototype 
for ‘wait_stub_done’ [-Wmissing-prototypes]

  107 | void wait_stub_done(int pid)
  |  ^~
../arch/um/os-Linux/skas/process.c:683:6: warning: no previous prototype 
for ‘__switch_mm’ [-Wmissing-prototypes]

  683 | void __switch_mm(struct mm_id *mm_idp)
  |  ^~~
../arch/um/kernel/skas/mmu.c:17:5: warning: no previous prototype for 
‘init_new_context’ [-Wmissing-prototypes]
   17 | int init_new_context(struct task_struct *task, struct mm_struct 
*mm)

  | ^~~~
../arch/um/kernel/skas/mmu.c:60:6: warning: no previous prototype for 
‘destroy_context’ [-Wmissing-prototypes]

   60 | void destroy_context(struct mm_struct *mm)
  |  ^~~
../arch/x86/um/fault.c:18:5: warning: no previous prototype for 
‘arch_fixup’ [-Wmissing-prototypes]

   18 | int arch_fixup(unsigned long address, struct uml_pt_regs *regs)
  | ^~
../arch/um/kernel/skas/process.c:36:12: warning: no previous prototype 
for ‘start_uml’ [-Wmissing-prototypes]

   36 | int __init start_uml(void)
  |    ^
../arch/um/os-Linux/main.c:187:7: warning: no previous prototype for 
‘__wrap_malloc’ [-Wmissing-prototypes]

  187 | void *__wrap_malloc(int size)
  |   ^
../arch/um/os-Linux/main.c:208:7: warning: no previous prototype for 
‘__wrap_calloc’ [-Wmissing-prototypes]

  208 | void *__wrap_calloc(int n, int size)
  |   ^
../arch/um/os-Linux/main.c:222:6: warning: no previous prototype for 
‘__wrap_free’ [-Wmissing-prototypes]

  222 | void __wrap_free(void *ptr)
  |  ^~~
../arch/um/os-Linux/mem.c:28:6: warning: no previous prototype for 
‘kasan_map_memory’ [-Wmissing-prototypes]

   28 | void kasan_map_memory(void *start, size_t len)
  |  ^~~~
../arch/um/os-Linux/mem.c:212:13: warning: no previous prototype for 
‘check_tmpexec’ [-Wmissing-prototypes]

  212 | void __init check_tmpexec(void)
  | ^
../arch/um/os-Linux/signal.c:75:6: warning: no previous prototype for 
‘sig_handler’ [-Wmissing-prototypes]

   75 | void sig_handler(int sig, struct siginfo *si, mcontext_t *mc)
  |  ^~~
../arch/um/os-Linux/signal.c:111:6: warning: no previous prototype for 
‘timer_alarm_handler’ [-Wmissing-prototypes]
  111 | void timer_alarm_handler(int sig, struct siginfo *unused_si, 
mcontext_t *mc)

  |  ^~~
../arch/x86/um/ptrace_64.c:111:5: warning: no previous prototype for 
‘poke_user’ [-Wmissing-prototypes]

  111 | int poke_user(struct task_struct *child, long addr, long data)
  |   

Re: [PATCH] drm/panthor: Fix NULL vs IS_ERR() bug in panthor_ioctl_tiler_heap_destroy()

2024-04-02 Thread Boris Brezillon
On Tue, 2 Apr 2024 18:52:12 +0530
Harshit Mogalapalli  wrote:

> Hello Boris,
> 
> On 02/04/24 18:03, Boris Brezillon wrote:
> > Hello Harshit,
> > 
> > On Tue,  2 Apr 2024 03:33:58 -0700
> > Harshit Mogalapalli  wrote:
> >   
> >> panthor_vm_get_heap_pool() returns ERR_PTR on failure.
> >>
> >> Fixes: 4bdca1150792 ("drm/panthor: Add the driver frontend block")
> >> Signed-off-by: Harshit Mogalapalli 
> >> ---
> >> This is spotted by smatch and the patch is only compile tested
> >> ---
> >>   drivers/gpu/drm/panthor/panthor_drv.c | 4 ++--
> >>   1 file changed, 2 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/drivers/gpu/drm/panthor/panthor_drv.c 
> >> b/drivers/gpu/drm/panthor/panthor_drv.c
> >> index 11b3ccd58f85..050b905b0453 100644
> >> --- a/drivers/gpu/drm/panthor/panthor_drv.c
> >> +++ b/drivers/gpu/drm/panthor/panthor_drv.c
> >> @@ -1090,8 +1090,8 @@ static int panthor_ioctl_tiler_heap_destroy(struct 
> >> drm_device *ddev, void *data,
> >>return -EINVAL;
> >>   
> >>pool = panthor_vm_get_heap_pool(vm, false);
> >> -  if (!pool) {
> >> -  ret = -EINVAL;
> >> +  if (IS_ERR(pool)) {
> >> +  ret = PTR_ERR(pool);  
> > 
> > Actually, panthor_vm_get_heap_pool() will return NULL if there's no
> > heap pool attached to this VM and create=false, so this was correct.
> > This being said, I'm fine making that consistent by returning
> > ERR_PTR(-ENOENT) instead of NULL in that case. This way we don't have
> > two different semantics based on the 'create' value.
> >   
> 
> Thanks for explaining. I missed the case where create is false and there 
> is no heap pool attached, so panthor_vm_get_heap_pool() can return NULL.
> 
> 1878  *
> 1879  * Return: A valid pointer on success, an ERR_PTR() otherwise.
> 1880  */
> 1881 struct panthor_heap_pool *panthor_vm_get_heap_pool(struct 
> panthor_vm *vm, bool create)
> 
> The documentation says it returns ERR_PTR() on failure, so is it worth 
> doing something like:
> 
> diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c 
> b/drivers/gpu/drm/panthor/panthor_mmu.c
> index fdd35249169f..e1285cdb09ff 100644
> --- a/drivers/gpu/drm/panthor/panthor_mmu.c
> +++ b/drivers/gpu/drm/panthor/panthor_mmu.c
> @@ -1893,6 +1893,8 @@ struct panthor_heap_pool 
> *panthor_vm_get_heap_pool(struct panthor_vm *vm, bool c
>  vm->heaps.pool = panthor_heap_pool_get(pool);
>  } else {
>  pool = panthor_heap_pool_get(vm->heaps.pool);
> +   if (!pool)
> +   pool = ERR_PTR(-ENOENT);
>  }
>  mutex_unlock(&vm->heaps.lock);
> 
> 
> and change all callers of panthor_vm_get_heap_pool() to only check for 
> IS_ERR() ?

Yep, that's what I had in mind.

> 
> 
> > Oh, and please merge everything into a single patch instead of one patch
> > per call-site.
> >   
> 
> Sure, I noticed one after the other. I will fix them together in v2.

Great!

Thanks,

Boris


Re: [PATCH] drm/panthor: Fix NULL vs IS_ERR() bug in panthor_ioctl_tiler_heap_destroy()

2024-04-02 Thread Harshit Mogalapalli

Hello Boris,

On 02/04/24 18:03, Boris Brezillon wrote:

Hello Harshit,

On Tue,  2 Apr 2024 03:33:58 -0700
Harshit Mogalapalli  wrote:


panthor_vm_get_heap_pool() returns ERR_PTR on failure.

Fixes: 4bdca1150792 ("drm/panthor: Add the driver frontend block")
Signed-off-by: Harshit Mogalapalli 
---
This is spotted by smatch and the patch is only compile tested
---
  drivers/gpu/drm/panthor/panthor_drv.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/panthor/panthor_drv.c 
b/drivers/gpu/drm/panthor/panthor_drv.c
index 11b3ccd58f85..050b905b0453 100644
--- a/drivers/gpu/drm/panthor/panthor_drv.c
+++ b/drivers/gpu/drm/panthor/panthor_drv.c
@@ -1090,8 +1090,8 @@ static int panthor_ioctl_tiler_heap_destroy(struct 
drm_device *ddev, void *data,
return -EINVAL;
  
  	pool = panthor_vm_get_heap_pool(vm, false);

-   if (!pool) {
-   ret = -EINVAL;
+   if (IS_ERR(pool)) {
+   ret = PTR_ERR(pool);


Actually, panthor_vm_get_heap_pool() will return NULL if there's no
heap pool attached to this VM and create=false, so this was correct.
This being said, I'm fine making that consistent by returning
ERR_PTR(-ENOENT) instead of NULL in that case. This way we don't have
two different semantics based on the 'create' value.



Thanks for explaining. I missed the case where create is false and there 
is no heap pool attached, so panthor_vm_get_heap_pool() can return NULL.


1878  *
1879  * Return: A valid pointer on success, an ERR_PTR() otherwise.
1880  */
1881 struct panthor_heap_pool *panthor_vm_get_heap_pool(struct 
panthor_vm *vm, bool create)


The documentation says it returns ERR_PTR() on failure, so is it worth 
doing something like:


diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c 
b/drivers/gpu/drm/panthor/panthor_mmu.c

index fdd35249169f..e1285cdb09ff 100644
--- a/drivers/gpu/drm/panthor/panthor_mmu.c
+++ b/drivers/gpu/drm/panthor/panthor_mmu.c
@@ -1893,6 +1893,8 @@ struct panthor_heap_pool 
*panthor_vm_get_heap_pool(struct panthor_vm *vm, bool c

vm->heaps.pool = panthor_heap_pool_get(pool);
} else {
pool = panthor_heap_pool_get(vm->heaps.pool);
+   if (!pool)
+   pool = ERR_PTR(-ENOENT);
}
mutex_unlock(&vm->heaps.lock);


and change all callers of panthor_vm_get_heap_pool() to only check for 
IS_ERR() ?




Oh, and please merge everything into a single patch instead of one patch
per call-site.



Sure, I noticed one after the other. I will fix them together in v2.

Thanks,
Harshit

Regards,

Boris


goto out_put_vm;
}
  






Re: [PATCH v6 3/5] crypto: tegra: Add Tegra Security Engine driver

2024-04-02 Thread Herbert Xu
On Tue, Apr 02, 2024 at 12:36:41PM +, Akhil R wrote:
>
> Should I set the reqsize as below in sha_cra_init()? Seeing this in other 
> crypto drivers.
> 
> crypto_ahash_set_reqsize(ahash_tfm,
> sizeof(struct tegra_sha_reqctx) +
> crypto_ahash_reqsize(ctx->fallback_tfm));

Yes if you places the fallback request at the end of reqctx then
this is the correct reqsize.

Cheers,
-- 
Email: Herbert Xu 
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


RE: [PATCH v6 3/5] crypto: tegra: Add Tegra Security Engine driver

2024-04-02 Thread Akhil R
> On Tue, Mar 19, 2024 at 01:53:04PM +0530, Akhil R wrote:
> >
> > +struct tegra_sha_reqctx {
> > + struct ahash_request fallback_req;
> 
> This doesn't work because ahash_request is dynamically sized.
> So you'll end up clobbering the rest of the struct if a fallback ends up 
> being used.
> 
> You should place the fallback_req at the end of the reqctx and set the reqsize
> based on the fallback reqsize.
> 
Should I set the reqsize as below in sha_cra_init()? Seeing this in other 
crypto drivers.

crypto_ahash_set_reqsize(ahash_tfm,
sizeof(struct tegra_sha_reqctx) +
crypto_ahash_reqsize(ctx->fallback_tfm));

Regards,
Akhil


Re: [PATCH] drm/panthor: Fix NULL vs IS_ERR() bug in panthor_ioctl_tiler_heap_destroy()

2024-04-02 Thread Boris Brezillon
Hello Harshit,

On Tue,  2 Apr 2024 03:33:58 -0700
Harshit Mogalapalli  wrote:

> panthor_vm_get_heap_pool() returns ERR_PTR on failure.
> 
> Fixes: 4bdca1150792 ("drm/panthor: Add the driver frontend block")
> Signed-off-by: Harshit Mogalapalli 
> ---
> This is spotted by smatch and the patch is only compile tested
> ---
>  drivers/gpu/drm/panthor/panthor_drv.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/panthor/panthor_drv.c 
> b/drivers/gpu/drm/panthor/panthor_drv.c
> index 11b3ccd58f85..050b905b0453 100644
> --- a/drivers/gpu/drm/panthor/panthor_drv.c
> +++ b/drivers/gpu/drm/panthor/panthor_drv.c
> @@ -1090,8 +1090,8 @@ static int panthor_ioctl_tiler_heap_destroy(struct 
> drm_device *ddev, void *data,
>   return -EINVAL;
>  
>   pool = panthor_vm_get_heap_pool(vm, false);
> - if (!pool) {
> - ret = -EINVAL;
> + if (IS_ERR(pool)) {
> + ret = PTR_ERR(pool);

Actually, panthor_vm_get_heap_pool() will return NULL if there's no
heap pool attached to this VM and create=false, so this was correct.
This being said, I'm fine making that consistent by returning
ERR_PTR(-ENOENT) instead of NULL in that case. This way we don't have
two different semantics based on the 'create' value.

Oh, and please merge everything into a single patch instead of one patch
per call-site.

Regards,

Boris

>   goto out_put_vm;
>   }
>  



Re: [PATCH] drm/panthor: Fix a couple -ENOMEM error codes

2024-04-02 Thread Boris Brezillon
On Tue, 2 Apr 2024 12:58:09 +0300
Dan Carpenter  wrote:

> These error paths forgot to set the error code to -ENOMEM.
> 
> Fixes: 647810ec2476 ("drm/panthor: Add the MMU/VM logical block")
> Signed-off-by: Dan Carpenter 

Reviewed-by: Boris Brezillon 

> ---
>  drivers/gpu/drm/panthor/panthor_mmu.c | 8 ++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c 
> b/drivers/gpu/drm/panthor/panthor_mmu.c
> index fdd35249169f..a26b40aab261 100644
> --- a/drivers/gpu/drm/panthor/panthor_mmu.c
> +++ b/drivers/gpu/drm/panthor/panthor_mmu.c
> @@ -1264,8 +1264,10 @@ static int panthor_vm_prepare_map_op_ctx(struct 
> panthor_vm_op_ctx *op_ctx,
>   op_ctx->rsvd_page_tables.pages = kcalloc(pt_count,
>
> sizeof(*op_ctx->rsvd_page_tables.pages),
>GFP_KERNEL);
> - if (!op_ctx->rsvd_page_tables.pages)
> + if (!op_ctx->rsvd_page_tables.pages) {
> + ret = -ENOMEM;
>   goto err_cleanup;
> + }
>  
>   ret = kmem_cache_alloc_bulk(pt_cache, GFP_KERNEL, pt_count,
>   op_ctx->rsvd_page_tables.pages);
> @@ -1318,8 +1320,10 @@ static int panthor_vm_prepare_unmap_op_ctx(struct 
> panthor_vm_op_ctx *op_ctx,
>   op_ctx->rsvd_page_tables.pages = kcalloc(pt_count,
>
> sizeof(*op_ctx->rsvd_page_tables.pages),
>GFP_KERNEL);
> - if (!op_ctx->rsvd_page_tables.pages)
> + if (!op_ctx->rsvd_page_tables.pages) {
> + ret = -ENOMEM;
>   goto err_cleanup;
> + }
>  
>   ret = kmem_cache_alloc_bulk(pt_cache, GFP_KERNEL, pt_count,
>   op_ctx->rsvd_page_tables.pages);



Re: [PATCH] drm/panthor: Fix off by one in panthor_fw_get_cs_iface()

2024-04-02 Thread Boris Brezillon
On Tue, 2 Apr 2024 12:56:42 +0300
Dan Carpenter  wrote:

> The ->iface.streams[csg_slot][] array has MAX_CS_PER_CSG elements so
> this > comparison needs to be >= to prevent an out of bounds access.
> 
> Fixes: 2718d91816ee ("drm/panthor: Add the FW logical block")
> Signed-off-by: Dan Carpenter 

Reviewed-by: Boris Brezillon 

> ---
>  drivers/gpu/drm/panthor/panthor_fw.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/panthor/panthor_fw.c 
> b/drivers/gpu/drm/panthor/panthor_fw.c
> index 33c87a59834e..181395e2859a 100644
> --- a/drivers/gpu/drm/panthor/panthor_fw.c
> +++ b/drivers/gpu/drm/panthor/panthor_fw.c
> @@ -308,7 +308,7 @@ panthor_fw_get_csg_iface(struct panthor_device *ptdev, 
> u32 csg_slot)
>  struct panthor_fw_cs_iface *
>  panthor_fw_get_cs_iface(struct panthor_device *ptdev, u32 csg_slot, u32 
> cs_slot)
>  {
> - if (drm_WARN_ON(&ptdev->base, csg_slot >= MAX_CSGS || cs_slot > 
> MAX_CS_PER_CSG))
> + if (drm_WARN_ON(&ptdev->base, csg_slot >= MAX_CSGS || cs_slot >= 
> MAX_CS_PER_CSG))
>   return NULL;
>  
>   return &ptdev->fw->iface.streams[csg_slot][cs_slot];



Re: [PATCH] drm/panthor: Fix error code in panthor_gpu_init()

2024-04-02 Thread Boris Brezillon
On Tue, 2 Apr 2024 12:56:19 +0300
Dan Carpenter  wrote:

> This code accidentally returns zero/success on error because of a typo.
> It should be "irq" instead of "ret".  The other thing is that if
> platform_get_irq_byname() were to return zero then the error code would
> be cmplicated.  Fortunately, it does not so we can just change <= to
> < 0.
> 
> Fixes: 5cd894e258c4 ("drm/panthor: Add the GPU logical block")
> Signed-off-by: Dan Carpenter 

Reviewed-by: Boris Brezillon 

> ---
>  drivers/gpu/drm/panthor/panthor_gpu.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/panthor/panthor_gpu.c 
> b/drivers/gpu/drm/panthor/panthor_gpu.c
> index 0f7c962440d3..5251d8764e7d 100644
> --- a/drivers/gpu/drm/panthor/panthor_gpu.c
> +++ b/drivers/gpu/drm/panthor/panthor_gpu.c
> @@ -211,8 +211,8 @@ int panthor_gpu_init(struct panthor_device *ptdev)
>   return ret;
>  
>   irq = platform_get_irq_byname(to_platform_device(ptdev->base.dev), 
> "gpu");
> - if (irq <= 0)
> - return ret;
> + if (irq < 0)
> + return irq;
>  
>   ret = panthor_request_gpu_irq(ptdev, &ptdev->gpu->irq, irq, 
> GPU_INTERRUPTS_MASK);
>   if (ret)



Re: [PATCH v0 03/14] drm/gma500,drm/i915: Make I2C terminology more inclusive

2024-04-02 Thread Easwar Hariharan
On 4/2/2024 12:48 AM, Jani Nikula wrote:
> On Fri, 29 Mar 2024, Easwar Hariharan  wrote:
>> I2C v7, SMBus 3.2, and I3C specifications have replaced "master/slave"
>> with more appropriate terms. Inspired by and following on to Wolfram's
>> series to fix drivers/i2c/[1], fix the terminology for users of
>> I2C_ALGOBIT bitbanging interface, now that the approved verbiage exists
>> in the specification.
> 
> gma500 and i915 changes should be split. See MAINTAINERS.
> 
> Might also split the i915 changes to smaller pieces, it's kind of
> random. And the changes here are not strictly related to I2C AFAICT, so
> the commit message should be updated.
> 
> BR,
> Jani.
> 
> 



I will split gma500 and i915 into their respective patches if possible in v2.

Can you say more about the changes being "not strictly related to I2C"? My
heuristic was to grep for master/slave, and look in the surrounding context for
i2c-related terminology (i2c_pin, 7-bit address, struct i2c_adapter, i2c_bus, 
etc)
to confirm that they are i2c-related, then following the references around to
make the compiler happy. For e.g., I did not change the many references to 
bigjoiner
master and slave because I understood from context they were not i2c references.

A couple examples would help me restrict the changes to I2C, since as mentioned 
in the
discussion on Wolfram's thread, there are places where migrating away from 
master/slave
terms in the code would conflict with the original technical manuals and reduce 
correlation
and understanding of the code.

Thanks,
Easwar



Re: [RFC PATCH 0/8] TTM shrinker helpers and xe buffer object shrinker

2024-04-02 Thread Somalapuram, Amaranath



On 3/29/2024 8:26 PM, Thomas Hellström wrote:

This series implements TTM shrinker / eviction helpers and an xe bo
shrinker. It builds on two previous series. First

https://www.mail-archive.com/dri-devel@lists.freedesktop.org/msg484425.html

for patch 1-4, which IMO still could be reviewed and pushed as a
separate series.

Second the previous TTM shrinker series 
On the latest drm-misc good amount of conflicts on both patch series, 
able to re-base first one, Second on has 16 patches.

If you have latest re-base patches, Please share it.

Regards,
S.Amarnath

https://lore.kernel.org/linux-mm/b7491378-defd-4f1c-31e2-29e4c77e2...@amd.com/T/

Where the comment about layering
https://lore.kernel.org/linux-mm/b7491378-defd-4f1c-31e2-29e4c77e2...@amd.com/T/#ma918844aa8a6efe8768fdcda0c6590d5c93850c9

now addressed, and this version also implements shmem objects for backup
rather than direct swap-cache insertions, which was used in the previuos
series. It turns out that with per-page backup / shrinking, shmem objects
appears to work just as well as direct swap-cache insertions with the
added benefit that was introduced in the previous TTM shrinker series to
avoid running out of swap entries isn't really needed.

In any case, patch 1-4 are better described in their separate series.
(RFC is removed for those).

Patch 5 could in theory be skipped but introduces a possibility to easily
add or test multiple backup backends, like the direct swap-cache
insertion or even files into fast dedicated nvme storage for for example.

Patch 6 introduces helpers in the ttm_pool code for page-by-page shrinking
and recovery. It avoids having to temporarily allocate a huge amount of
memory to be able to shrink a buffer object. It also introduces the
possibility to immediately write-back pages if needed, since that tends
to be a bit delayed when left to kswapd.

Patch 7 introduces a LRU walk helper for eviction and shrinking. It's
currently xe-only but not xe-specific and can easily be moved to TTM when
used by more than one driver or when eviction is implemented using it.

Patch 8 introduces a helper callback for shrinking (Also ready to be
moved to TTM) and an xe-specific shrinker implementation.

Testing:
ATM I don't think we have good tests to cover the shrinking functionality
The series has been tested with a hack that continously creates
TTM_TT buffer objects until system memory and swap space is exhausted,
and then reads them back and frees them. However, these tests
seem to be very slow.
Ideally a similar test on a machine with very fast solid state or
similar storage should be set up. Ideally also verifying content
preservation.

Cc: Somalapuram Amaranath 
Cc: Christian König 
Cc: 

Thomas Hellström (8):
   drm/ttm: Allow TTM LRU list nodes of different types
   drm/ttm: Use LRU hitches
   drm/ttm, drm/amdgpu, drm/xe: Consider hitch moves within bulk sublist
 moves
   drm/ttm: Allow continued swapout after -ENOSPC falure
   drm/ttm: Add a virtual base class for graphics memory backup
   drm/ttm/pool: Provide a helper to shrink pages.
   drm/xe, drm/ttm: Provide a generic LRU walker helper
   drm/xe: Add a shrinker for xe bos

  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c |   4 +
  drivers/gpu/drm/ttm/Makefile   |   2 +-
  drivers/gpu/drm/ttm/ttm_backup_shmem.c | 137 +
  drivers/gpu/drm/ttm/ttm_bo.c   |   1 +
  drivers/gpu/drm/ttm/ttm_device.c   |  33 ++-
  drivers/gpu/drm/ttm/ttm_pool.c | 391 -
  drivers/gpu/drm/ttm/ttm_resource.c | 231 ---
  drivers/gpu/drm/ttm/ttm_tt.c   |  34 +++
  drivers/gpu/drm/xe/Makefile|   2 +
  drivers/gpu/drm/xe/xe_bo.c | 123 ++--
  drivers/gpu/drm/xe/xe_bo.h |   3 +
  drivers/gpu/drm/xe/xe_device.c |   8 +
  drivers/gpu/drm/xe/xe_device_types.h   |   2 +
  drivers/gpu/drm/xe/xe_shrinker.c   | 237 +++
  drivers/gpu/drm/xe/xe_shrinker.h   |  18 ++
  drivers/gpu/drm/xe/xe_ttm_helpers.c| 224 ++
  drivers/gpu/drm/xe/xe_ttm_helpers.h|  63 
  drivers/gpu/drm/xe/xe_vm.c |   4 +
  include/drm/ttm/ttm_backup.h   | 136 +
  include/drm/ttm/ttm_device.h   |   2 +
  include/drm/ttm/ttm_pool.h |   4 +
  include/drm/ttm/ttm_resource.h |  96 +-
  include/drm/ttm/ttm_tt.h   |  19 ++
  23 files changed, 1683 insertions(+), 91 deletions(-)
  create mode 100644 drivers/gpu/drm/ttm/ttm_backup_shmem.c
  create mode 100644 drivers/gpu/drm/xe/xe_shrinker.c
  create mode 100644 drivers/gpu/drm/xe/xe_shrinker.h
  create mode 100644 drivers/gpu/drm/xe/xe_ttm_helpers.c
  create mode 100644 drivers/gpu/drm/xe/xe_ttm_helpers.h
  create mode 100644 include/drm/ttm/ttm_backup.h



Re: [PATCH] drm/vmwgfx: Filter modes which exceed graphics memory

2024-04-02 Thread Zack Rusin
On Mon, Apr 1, 2024 at 4:35 PM Ian Forbes  wrote:
>
> SVGA requires individual surfaces to fit within graphics memory
> (max_mob_pages) which means that modes with a final buffer size that would
> exceed graphics memory must be pruned otherwise creation will fail.
>
> This fixes an issue where VMs with low graphics memory (< 64MiB) configured
> with high resolution mode boot to a black screen because surface creation
> fails.
>
> Fixes: d947d1b71deb ("drm/vmwgfx: Add and connect connector helper function")
> Signed-off-by: Ian Forbes 
> ---
>  drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c | 32 +++-
>  1 file changed, 31 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c 
> b/drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c
> index 3c8414a13dba..49583b186a7d 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c
> @@ -830,7 +830,37 @@ static void vmw_stdu_connector_destroy(struct 
> drm_connector *connector)
> vmw_stdu_destroy(vmw_connector_to_stdu(connector));
>  }
>
> +static enum drm_mode_status
> +vmw_stdu_connector_mode_valid(struct drm_connector *connector,
> + struct drm_display_mode *mode)
> +{
> +   enum drm_mode_status ret;
> +   struct drm_device *dev = connector->dev;
> +   struct vmw_private *dev_priv = vmw_priv(dev);
> +   u64 assumed_cpp = dev_priv->assume_16bpp ? 2 : 4;
> +   u64 required_mem = mode->hdisplay * assumed_cpp * mode->vdisplay;
> +
> +   ret = drm_mode_validate_size(mode, dev_priv->stdu_max_width,
> +dev_priv->stdu_max_height);
> +   if (ret != MODE_OK)
> +   return ret;
> +
> +   ret = drm_mode_validate_size(mode, dev_priv->texture_max_width,
> +dev_priv->texture_max_height);
> +   if (ret != MODE_OK)
> +   return ret;
>
> +   if (required_mem > dev_priv->max_primary_mem)
> +   return MODE_MEM;
> +
> +   if (required_mem > dev_priv->max_mob_pages * PAGE_SIZE)
> +   return MODE_MEM;
> +
> +   if (required_mem > dev_priv->max_mob_size)
> +   return MODE_MEM;
> +
> +   return MODE_OK;
> +}
>
>  static const struct drm_connector_funcs vmw_stdu_connector_funcs = {
> .dpms = vmw_du_connector_dpms,
> @@ -846,7 +876,7 @@ static const struct drm_connector_funcs 
> vmw_stdu_connector_funcs = {
>  static const struct
>  drm_connector_helper_funcs vmw_stdu_connector_helper_funcs = {
> .get_modes = vmw_connector_get_modes,
> -   .mode_valid = vmw_connector_mode_valid
> +   .mode_valid = vmw_stdu_connector_mode_valid
>  };
>
>
> --
> 2.34.1
>

This looks like a great start. Some improvements that I'd suggest is
to take a look at
bora/vmcore/frobos/test/common/svga/1523068-svga-screen-limits/main.c
where those computations are spelled out a bit more verbose. I'd
suggest following them because those are being tested all the time.
It'd be great if we also covered the multimon case here, but it's not
our main concern.

The second thing that we'd want to adjust is that if we're not using
vmw_connector_mode_valid then we need to remove the stdu paths from
it.

Finally I'd suggest making this a series, i.e. include all the changes
we've talked about like fixing all of the display technologies,
disabling 3d etc iirc we talked about priority list among those at
some time.

z


Re: [PATCH v0 10/14] sfc: falcon: Make I2C terminology more inclusive

2024-04-02 Thread Martin Habets
On Fri, Mar 29, 2024 at 05:00:34PM +, Easwar Hariharan wrote:
> I2C v7, SMBus 3.2, and I3C specifications have replaced "master/slave"
> with more appropriate terms. Inspired by and following on to Wolfram's
> series to fix drivers/i2c/[1], fix the terminology for users of
> I2C_ALGOBIT bitbanging interface, now that the approved verbiage exists
> in the specification.
> 
> Compile tested, no functionality changes intended
> 
> [1]: 
> https://lore.kernel.org/all/20240322132619.6389-1-wsa+rene...@sang-engineering.com/
> 
> Signed-off-by: Easwar Hariharan 

Reviewed-by: Martin Habets 

> ---
>  drivers/net/ethernet/sfc/falcon/falcon.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/sfc/falcon/falcon.c 
> b/drivers/net/ethernet/sfc/falcon/falcon.c
> index 7a1c9337081b..147e7c8e3c02 100644
> --- a/drivers/net/ethernet/sfc/falcon/falcon.c
> +++ b/drivers/net/ethernet/sfc/falcon/falcon.c
> @@ -367,7 +367,7 @@ static const struct i2c_algo_bit_data 
> falcon_i2c_bit_operations = {
>   .getsda = falcon_getsda,
>   .getscl = falcon_getscl,
>   .udelay = 5,
> - /* Wait up to 50 ms for slave to let us pull SCL high */
> + /* Wait up to 50 ms for client to let us pull SCL high */
>   .timeout= DIV_ROUND_UP(HZ, 20),
>  };
>  
> -- 
> 2.34.1
> 


Re: [PATCH v9 1/6] dmaengine: Add API function dmaengine_prep_peripheral_dma_vec()

2024-04-02 Thread Paul Cercueil
Hi Vinod,

Le jeudi 28 mars 2024 à 11:53 +0530, Vinod Koul a écrit :
> On 10-03-24, 13:48, Paul Cercueil wrote:
> > This function can be used to initiate a scatter-gather DMA
> > transfer,
> > where the address and size of each segment is located in one entry
> > of
> > the dma_vec array.
> > 
> > The major difference with dmaengine_prep_slave_sg() is that it
> > supports
> > specifying the lengths of each DMA transfer; as trying to override
> > the
> > length of the transfer with dmaengine_prep_slave_sg() is a very
> > tedious
> > process. The introduction of a new API function is also justified
> > by the
> > fact that scatterlists are on their way out.
> > 
> > Note that dmaengine_prep_interleaved_dma() is not helpful either in
> > that
> > case, as it assumes that the address of each segment will be higher
> > than
> > the one of the previous segment, which we just cannot guarantee in
> > case
> > of a scatter-gather transfer.
> > 
> > Signed-off-by: Paul Cercueil 
> > Signed-off-by: Nuno Sa 
> > 
> > ---
> > v3: New patch
> > 
> > v5: Replace with function dmaengine_prep_slave_dma_vec(), and
> > struct
> >     'dma_vec'.
> >     Note that at some point we will need to support cyclic
> > transfers
> >     using dmaengine_prep_slave_dma_vec(). Maybe with a new "flags"
> >     parameter to the function?
> > 
> > v7:
> >   - Renamed *device_prep_slave_dma_vec() ->
> > device_prep_peripheral_dma_vec();
> >   - Added a new flag parameter to the function as agreed between
> > Paul
> >     and Vinod. I renamed the first parameter to prep_flags as it's
> > supposed to
> >     be used (I think) with enum dma_ctrl_flags. I'm not really sure
> > how that API
> >     can grow but I was thinking in just having a bool cyclic
> > parameter (as the
> >     first intention of the flags is to support cyclic transfers)
> > but ended up
> >     "respecting" the previously agreed approach.
> > ---
> >  include/linux/dmaengine.h | 27 +++
> >  1 file changed, 27 insertions(+)
> > 
> > diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
> > index 752dbde4cec1..856df8cd9a4e 100644
> > --- a/include/linux/dmaengine.h
> > +++ b/include/linux/dmaengine.h
> > @@ -160,6 +160,16 @@ struct dma_interleaved_template {
> >     struct data_chunk sgl[];
> >  };
> >  
> > +/**
> > + * struct dma_vec - DMA vector
> > + * @addr: Bus address of the start of the vector
> > + * @len: Length in bytes of the DMA vector
> > + */
> > +struct dma_vec {
> > +   dma_addr_t addr;
> > +   size_t len;
> > +};
> > +
> >  /**
> >   * enum dma_ctrl_flags - DMA flags to augment operation
> > preparation,
> >   *  control completion, and communicate status.
> > @@ -910,6 +920,10 @@ struct dma_device {
> >     struct dma_async_tx_descriptor
> > *(*device_prep_dma_interrupt)(
> >     struct dma_chan *chan, unsigned long flags);
> >  
> > +   struct dma_async_tx_descriptor
> > *(*device_prep_peripheral_dma_vec)(
> > +   struct dma_chan *chan, const struct dma_vec *vecs,
> > +   size_t nents, enum dma_transfer_direction
> > direction,
> > +   unsigned long prep_flags, unsigned long flags);
> >     struct dma_async_tx_descriptor *(*device_prep_slave_sg)(
> >     struct dma_chan *chan, struct scatterlist *sgl,
> >     unsigned int sg_len, enum dma_transfer_direction
> > direction,
> > @@ -973,6 +987,19 @@ static inline struct dma_async_tx_descriptor
> > *dmaengine_prep_slave_single(
> >       dir, flags,
> > NULL);
> >  }
> >  
> > +static inline struct dma_async_tx_descriptor
> > *dmaengine_prep_peripheral_dma_vec(
> > +   struct dma_chan *chan, const struct dma_vec *vecs, size_t
> > nents,
> > +   enum dma_transfer_direction dir, unsigned long prep_flags,
> > +   unsigned long flags)
> > +{
> > +   if (!chan || !chan->device || !chan->device-
> > >device_prep_peripheral_dma_vec)
> > +   return NULL;
> > +
> > +   return chan->device->device_prep_peripheral_dma_vec(chan,
> > vecs, nents,
> > +       dir,
> > prep_flags,
> > +      
> > flags);
> > +}
> 
> API looks good to me, thanks
> Few nits though:
> - Can we add kernel-doc for this new API please
> - Also update the documentation adding this new api
> - Lastly, we seem to have two flags, I know you have added a comment
> but
>   I dont seem to recall the discussion (looked at old threads for
> clue
>   as well), can you please remind me why we need both? And in your
> case,
>   what is the intended usage of these flags, i would prefer single
>   clean one...
> 

The "prep_flags" is a mask of "enum dma_ctrl_flags".

The second "flags" was supposed to be specific to this function, and
was to future-proof the API as we eventually want to have a "cyclic"
flag, which would emulate a cyclic transfer by linking the SG hardware
descriptors accordingly.

However - I think we can already do t

Re: [PATCH] drm/panthor: Fix IS_ERR() vs NULL bug in group_process_tiler_oom()

2024-04-02 Thread Harshit Mogalapalli

Hi,

On 02/04/24 16:47, Harshit Mogalapalli wrote:

panthor_vm_get_heap_pool() returns ERR_PTR on failure, update the check
accordingly.

Fixes: de8548813824 ("drm/panthor: Add the scheduler logical block")
Signed-off-by: Harshit Mogalapalli 
---
This is based on static analysis with smatch, only compile tested.
---
  drivers/gpu/drm/panthor/panthor_sched.c | 5 -
  1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/panthor/panthor_sched.c 
b/drivers/gpu/drm/panthor/panthor_sched.c
index 5f7803b6fc48..d34f213795a3 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.c
+++ b/drivers/gpu/drm/panthor/panthor_sched.c
@@ -1343,7 +1343,10 @@ static int group_process_tiler_oom(struct panthor_group 
*group, u32 cs_id)
if (unlikely(csg_id < 0))
return 0;
  
-	if (!heaps || frag_end > vt_end || vt_end >= vt_start) {

+   if (IS_ERR(heaps))
+   return PTR_ERR(heaps);
+


Please ignore this patch, doesn't look correct on looking at more closely.

I should have just done this:

diff --git a/drivers/gpu/drm/panthor/panthor_sched.c 
b/drivers/gpu/drm/panthor/panthor_sched.c

index 5f7803b6fc48..617df2b980d0 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.c
+++ b/drivers/gpu/drm/panthor/panthor_sched.c
@@ -1343,7 +1343,7 @@ static int group_process_tiler_oom(struct 
panthor_group *group, u32 cs_id)

if (unlikely(csg_id < 0))
return 0;

-   if (!heaps || frag_end > vt_end || vt_end >= vt_start) {
+   if (IS_ERR(heaps) || frag_end > vt_end || vt_end >= vt_start) {
ret = -EINVAL;
} else {
/* We do the allocation without holding the scheduler 
lock to avoid



Thanks,
Harshit



+   if (frag_end > vt_end || vt_end >= vt_start) {
ret = -EINVAL;
} else {
/* We do the allocation without holding the scheduler lock to 
avoid




  1   2   >