<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to call ioctl from kernel space in Linux kernel after version 5.18 and in 64-bit arch. in i.MX Processors</title>
    <link>https://community.nxp.com/t5/i-MX-Processors/How-to-call-ioctl-from-kernel-space-in-Linux-kernel-after/m-p/2043526#M233976</link>
    <description>Hello,&lt;BR /&gt;the BSP is 6.1.22,, from NXP github site (&lt;A href="https://github.com/nxp-real-time-edge-sw/real-time-edge-linux" target="_blank"&gt;https://github.com/nxp-real-time-edge-sw/real-time-edge-linux&lt;/A&gt;) and I work on iMX8MP cistom board.&lt;BR /&gt;&lt;BR /&gt;I wrote version 5.18 (referring to the mainline of linux kernel version) that is the version affected by code changing.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance.&lt;BR /&gt;&lt;BR /&gt;Stefano&lt;BR /&gt;</description>
    <pubDate>Thu, 13 Feb 2025 15:26:29 GMT</pubDate>
    <dc:creator>gigli_korg</dc:creator>
    <dc:date>2025-02-13T15:26:29Z</dc:date>
    <item>
      <title>How to call ioctl from kernel space in Linux kernel after version 5.18 and in 64-bit arch.</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/How-to-call-ioctl-from-kernel-space-in-Linux-kernel-after/m-p/2043397#M233970</link>
      <description>&lt;P&gt;&lt;BR /&gt;Good morning,&lt;/P&gt;&lt;P&gt;I try to rebuild a Linux device driver from previous release (4.19) in recent kernels, namely 6.1.22 on embedded platforms, ARM64 arch.&lt;/P&gt;&lt;P&gt;THe driver manage a tty device.&lt;/P&gt;&lt;P&gt;The problems start to occur when I invoke `unlocked_ioctl()` function similar to the user-space usage.&lt;/P&gt;&lt;P&gt;THe following code try to summarize the usage to maintain:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;char device_name = "/dev/my-tty";&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;int open_mode = O_RDWR | O_NOCTTY;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;struct file * file = filp_open(device_name, open_mode, 0);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;/* ... */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;struct ktermios *ntermios;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;int ldisc;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;/* ... something on ldisc and ntermios ... */&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;fs = get_fs();&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;set_fs(get_ds());&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;int retval = file-&amp;gt;f_op-&amp;gt;unlocked_ioctl(file, TCSETS, (unsigned long)&amp;amp;ntermios));&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;set_fs(fs);&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;/* ... */&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;fs = get_fs();&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;set_fs(get_ds());&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;int retval = file-&amp;gt;f_op-&amp;gt;unlocked_ioctl(file, TIOCSETD, (unsigned long)&amp;amp;ldisc));&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;set_fs(fs);&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;/* ... */&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;in both cases the return value of the two calls to `unlocked_ioctl` is -14 (`EFAULT` / Bad Address).&lt;BR /&gt;The is in the presence of function `copy_from_user()`, ... that simply fails.&lt;/P&gt;&lt;P&gt;Search in code and on several forum, I found several details about the "set_fs()"-dance removal, but nothing about solution or alternative approaches.&lt;/P&gt;&lt;P&gt;As example of the most meaning full resource I visited are the followings:&lt;BR /&gt;- &lt;A href="https://lwn.net/Articles/832121/" target="_blank"&gt;https://lwn.net/Articles/832121/&lt;/A&gt;&lt;BR /&gt;- &lt;A href="https://stackoverflow.com/questions/74966928/deprecation-of-force-uaccess-begin-in-linux-kernel-5-19-6-0" target="_blank"&gt;https://stackoverflow.com/questions/74966928/deprecation-of-force-uaccess-begin-in-linux-kernel-5-19-6-0&lt;/A&gt;&lt;BR /&gt;- &lt;A href="https://stackoverflow.com/questions/11121319/how-to-use-ioctl-from-kernel-space-in-linux" target="_blank"&gt;https://stackoverflow.com/questions/11121319/how-to-use-ioctl-from-kernel-space-in-linux&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The functions `force_uaccess_begin()` and `force_uaccess_end()`, `get_ds()`, `set_ds()`, `get_fs()`, as well as type `mm_segment_t` are not present any more (at least for ARM64 arch).&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Basically the questions are the followings:&lt;/P&gt;&lt;P&gt;- How can I drive a device, as a tty, from kernel space?&lt;BR /&gt;- Is it possible yet?&lt;BR /&gt;- Are there alternatives to the `set_fs()`-dance? Is the approach, if any, completely different?&lt;BR /&gt;- Do you examples, maybe on linux kernel source code, about module/driver that have this kind of problem solved?&lt;BR /&gt;&lt;BR /&gt;Any comment is appreciated.&lt;/P&gt;&lt;P&gt;Stefano&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Feb 2025 11:10:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/How-to-call-ioctl-from-kernel-space-in-Linux-kernel-after/m-p/2043397#M233970</guid>
      <dc:creator>gigli_korg</dc:creator>
      <dc:date>2025-02-13T11:10:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to call ioctl from kernel space in Linux kernel after version 5.18 and in 64-bit arch.</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/How-to-call-ioctl-from-kernel-space-in-Linux-kernel-after/m-p/2043514#M233974</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I think is not possible to managed your task, also you have to base on a nxp BSP and 5.18 there is no BSP for that version.&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Thu, 13 Feb 2025 15:12:49 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/How-to-call-ioctl-from-kernel-space-in-Linux-kernel-after/m-p/2043514#M233974</guid>
      <dc:creator>Bio_TICFSL</dc:creator>
      <dc:date>2025-02-13T15:12:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to call ioctl from kernel space in Linux kernel after version 5.18 and in 64-bit arch.</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/How-to-call-ioctl-from-kernel-space-in-Linux-kernel-after/m-p/2043526#M233976</link>
      <description>Hello,&lt;BR /&gt;the BSP is 6.1.22,, from NXP github site (&lt;A href="https://github.com/nxp-real-time-edge-sw/real-time-edge-linux" target="_blank"&gt;https://github.com/nxp-real-time-edge-sw/real-time-edge-linux&lt;/A&gt;) and I work on iMX8MP cistom board.&lt;BR /&gt;&lt;BR /&gt;I wrote version 5.18 (referring to the mainline of linux kernel version) that is the version affected by code changing.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance.&lt;BR /&gt;&lt;BR /&gt;Stefano&lt;BR /&gt;</description>
      <pubDate>Thu, 13 Feb 2025 15:26:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/How-to-call-ioctl-from-kernel-space-in-Linux-kernel-after/m-p/2043526#M233976</guid>
      <dc:creator>gigli_korg</dc:creator>
      <dc:date>2025-02-13T15:26:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to call ioctl from kernel space in Linux kernel after version 5.18 and in 64-bit arch.</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/How-to-call-ioctl-from-kernel-space-in-Linux-kernel-after/m-p/2048954#M234316</link>
      <description>Hello Bio_TICFSL&lt;BR /&gt;&lt;BR /&gt;you wrote "I think is not possible to managed your task,",&lt;BR /&gt;&lt;BR /&gt;but why?&lt;BR /&gt;&lt;BR /&gt;I suppose NXP too writes driver probably maintaining them during crossing ARM archs (as well 32 bit as wall 64 bit) and, during mainline kernel releses (and changes).&lt;BR /&gt;I suppose NXP developers adapt their driver. So, about&lt;BR /&gt;&lt;BR /&gt;Thanks in advance.&lt;BR /&gt;&lt;BR /&gt;gigli_korg.&lt;BR /&gt;</description>
      <pubDate>Fri, 21 Feb 2025 09:28:49 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/How-to-call-ioctl-from-kernel-space-in-Linux-kernel-after/m-p/2048954#M234316</guid>
      <dc:creator>gigli_korg</dc:creator>
      <dc:date>2025-02-21T09:28:49Z</dc:date>
    </item>
  </channel>
</rss>

