Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BCM270x: Make uart1 work with Device Tree #1008

Merged
merged 1 commit into from
Jun 7, 2015

Conversation

notro
Copy link
Contributor

@notro notro commented Jun 6, 2015

Add uart1 to Device Tree. Enable it in AUXENB when it's used.
Remove old platform device.

This is how I have tested this on Pi1 and Pi2:

config

CONFIG_SERIAL_8250=y
CONFIG_SERIAL_8250_CONSOLE=y
CONFIG_SERIAL_OF_PLATFORM=y

DT overlay

/dts-v1/;
/plugin/;

/ {
    compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";

    fragment@0 {
        target = <&gpio>;
        __overlay__ {
            uart1_pins: uart1_pins {
                brcm,pins = <14 15>;
                brcm,function = <2>; /* alt5 */
            };
        };
    };

    fragment@1 {
        target = <&uart1>;
        __overlay__ {
            pinctrl-names = "default";
            pinctrl-0 = <&uart1_pins>;
            status = "okay";
        };
    };
};

Add to /boot/cmdline.txt

console=ttyS0,115200

dmesg

[    0.260750] bcm2708: Mini UART enabled
[...]
[    0.278795] Serial: AMBA PL011 UART driver
[    0.283324] 20201000.uart: ttyAMA0 at MMIO 0x20201000 (irq = 83, base_baud = 0) is a PL011 rev2
[    0.292376] console [ttyAMA0] enabled
[...]
[    1.191862] Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled
[    1.201851] uart-pl011 20201000.uart: no DMA platform data
[    1.209983] console [ttyS0] disabled
[    1.215464] 20215040.uart: ttyS0 at MMIO 0x20215040 (irq = 29, base_baud = 31250000) is a 16550
[    1.901232] console [ttyS0] enabled

To get a login prompt on ttyS0, /etc/inittab would need some attention.

Add uart1 to Device Tree. Enable it in AUXENB when it's used.
Remove old platform device.

Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
@popcornmix
Copy link
Collaborator

Looks okay to me. @pelwell ?

pelwell added a commit that referenced this pull request Jun 7, 2015
BCM270x: Make uart1 work with Device Tree
@pelwell pelwell merged commit 51fe8aa into raspberrypi:rpi-4.0.y Jun 7, 2015
@notro notro deleted the uart1 branch June 7, 2015 13:35
@dpslwk
Copy link

dpslwk commented Jun 23, 2015

Would it be possible to now have the 8250 kernel drive enabled in bcmrpi_defconfig?

I believe that would be very useful as currently even with this change to allow uart1 to work with DT a user still needs to custom compile the kernel and modules to make use of it.

Im not sure if this can be done via a module option (I think these are correct)

CONFIG_SERIAL_8250=m
CONFIG_SERIAL_8250_CONSOLE=y
CONFIG_SERIAL_OF_PLATFORM=y

or if it should be just built in using the options given by @notro

popcornmix added a commit to Hexxeh/rpi-firmware that referenced this pull request Jun 23, 2015
kernel: Add rpi-ft5406 overlay Add rpi-ft5406 driver as module

kernel: config: Enable 8250 serial port
See: raspberrypi/linux#1008

kernel: config: Enable POWER_RESET_GPIO
See: raspberrypi/linux#1031

firmware: arm_display: Fix fb_base alias returned from mailbox property interface
See: raspberrypi/linux#1026

firmware: mem_unlock - prevent decrementing lock count below 0

firmware: camera: Support multi-channel raw image capture
firmware: camera: write_raw copies input frame if HDR is enabled
firmware: camera: Write correct camera mode from write_raw_md_stage
firmware: AGC tuner: Correction to setting default digital gain to x1.0
popcornmix added a commit to raspberrypi/firmware that referenced this pull request Jun 23, 2015
kernel: Add rpi-ft5406 overlay Add rpi-ft5406 driver as module

kernel: config: Enable 8250 serial port
See: raspberrypi/linux#1008

kernel: config: Enable POWER_RESET_GPIO
See: raspberrypi/linux#1031

firmware: arm_display: Fix fb_base alias returned from mailbox property interface
See: raspberrypi/linux#1026

firmware: mem_unlock - prevent decrementing lock count below 0

firmware: camera: Support multi-channel raw image capture
firmware: camera: write_raw copies input frame if HDR is enabled
firmware: camera: Write correct camera mode from write_raw_md_stage
firmware: AGC tuner: Correction to setting default digital gain to x1.0
@popcornmix
Copy link
Collaborator

Can you try rpi-update. The options should be in.

@dpslwk
Copy link

dpslwk commented Jun 25, 2015

The update works a treat and i have successfully used the port with minicom.
However one think i have noticed is that the /dev/ttyS0 is showing up even with out an overlay to enable the device, I'm not sure if this is the behaviour of the kernel compile options of the lower down DT settings.
I'm also not sure if this is a good change or not? As in /dev/ttyS0 start appearing in all pi distro's.
There are a lot of people out there that will have created /dev/ttyS0<>/dev/ttyAMA0 symlinks for use with the Arduino IDE
I intended to try compiling the kernel with a few different option for the 8250 driver and see what behaviour I can get

@pelwell
Copy link
Contributor

pelwell commented Jun 25, 2015

I was just about to ask if you could help out ondrej1024 on the forum, but I see you have done that already. Thank you.

If you would like to submit a pull request with your overlay and updates to the Makefile and README then I'll happily merge it.

I'll need to look into the automatic creation of /dev/ttyS0 even without the overlay - it is not the desired behaviour.

@pelwell
Copy link
Contributor

pelwell commented Jun 25, 2015

I now understand why ttyS0 is being created without an overlay, and I've got it working(ish).

The value of CONFIG_SERIAL_8250_RUNTIME_UARTS (currently 1) is the number of uarts initially configured at boot time, and causes /dev/ttyS0 to be created (but with what properties?) regardless of the DT content. Fortunately this config value can be overridden by a module parameter, so it may be necessary to use that as well as DT to enable the interface, unless we decide that having a (presumably) non-functioning ttyS0 is preferable to having to manipulate cmdline.txt.

The other remaining issue is that the baudrate seems to be out by a factor of two - I'm looking at clock rates now.

@dpslwk
Copy link

dpslwk commented Jun 26, 2015

So i just attached the logic analyser on my setup here (Compute in OpenPi) and the baud rate is correct for 9600 and 115200
I know the baud rate is tied to the 250MHz system clock, so if thats different you would need to override the (in the uart1 DT section)

clock-frequency = <500000000>;

I've not tried on the Pi2 and don't know if that has a different system clock speed?

@pelwell
Copy link
Contributor

pelwell commented Jun 26, 2015

Yes, the baud rate discrepancy was caused by using the core clock directly, which didn't take account of the non-standard clock divisor. Future firmware releases will correctly patch the uart1 clock value, but be aware that if you are overclocking the core you will need to set force_turbo=1 to get a sensible baud rate.

popcornmix added a commit to raspberrypi/firmware that referenced this pull request Jun 26, 2015
kernel: bcm2708-spi: Don't use static pin configuration with DT

kernel: bcm2708-i2s: Don't use static pin configuration with DT

kernel: gpio-poweroff: Allow it to work on Raspberry Pi
See: raspberrypi/linux#1031

kernel: BCM270X_DT: Create a core clock, use it for SPI and sdhost

kernel: BCM270X_DT: Add overlay to enable uart1
See: raspberrypi/linux#1008

kernel: config: Enable ZSMALLOC, ZRAM and PGTABLE_MAPPING
See: Hexxeh/rpi-firmware#85

firmware: arm_loader: Support initialising vchiq through mailbox property interface
See: raspberrypi/linux#1026

firmware: drivers/usb: Reduce busy-wait to sensible timeout
See: raspberrypi/linux#1026

firmware: video_encode: Initialise headers for video_bitrate
See: #163

firmware: arm_loader: Use the new core_freq DT parameter if present

firmware: arm_loader: Set the uart1_clkrate DT property from core_freq

firmware: arm_cursor: Better handling of a second app requesting a cursor

firmware: arm: Tidy up setting of arm_control and arm_bash
popcornmix added a commit to Hexxeh/rpi-firmware that referenced this pull request Jun 26, 2015
kernel: bcm2708-spi: Don't use static pin configuration with DT

kernel: bcm2708-i2s: Don't use static pin configuration with DT

kernel: gpio-poweroff: Allow it to work on Raspberry Pi
See: raspberrypi/linux#1031

kernel: BCM270X_DT: Create a core clock, use it for SPI and sdhost

kernel: BCM270X_DT: Add overlay to enable uart1
See: raspberrypi/linux#1008

kernel: config: Enable ZSMALLOC, ZRAM and PGTABLE_MAPPING
See: #85

firmware: arm_loader: Support initialising vchiq through mailbox property interface
See: raspberrypi/linux#1026

firmware: drivers/usb: Reduce busy-wait to sensible timeout
See: raspberrypi/linux#1026

firmware: video_encode: Initialise headers for video_bitrate
See: raspberrypi/firmware#163

firmware: arm_loader: Use the new core_freq DT parameter if present

firmware: arm_loader: Set the uart1_clkrate DT property from core_freq

firmware: arm_cursor: Better handling of a second app requesting a cursor

firmware: arm: Tidy up setting of arm_control and arm_bash
@popcornmix
Copy link
Collaborator

rpi-update firmware should contain @pelwell's fix

@dpslwk
Copy link

dpslwk commented Jun 29, 2015

New overlay works for me, getting good baudrates out of it and the pin override works

So that just leave the creation of /dev/ttyS0 question

@pelwell
Copy link
Contributor

pelwell commented Jun 29, 2015

The /dev/ttyS0 creation is triggered by the config parameter SERIAL_8250_RUNTIME_UARTS, which we are setting to 1. Making this a 0 stops the device being created without and with the DT overlay.

There are two parameters - SERIAL_8250_NR_UARTS and SERIAL_8250_RUNTIME_UARTS. The former is simply the size of an array, and the latter says how many entries in the array will be used. It seems odd to have a "RUNTIME" value like that compiled in, but it makes (slightly) more sense when you know that it can be overridden using the "nr_uarts" module parameter.

Creating the platform device from DT only has the effect of initialising one of the pre-defined UART ports, so in order to get the behaviour we want, i.e. either one configured UART or no UARTs, it is necessary to:

  1. change the config so that SERIAL_8250_RUNTIME_UARTS is 0, and
  2. load the overlay and add "8250.nr_uarts=1" to the kernel command line.

That sounds tedious, but I have a trick up my sleeve. When you write to the "/chosen/bootargs" DT property from an overlay the new value is appended to the kernel command line (plus, this happens before the extra settings supplied by the firmware). This makes it possible to set the module parameter from the overlay.

I've pushed an update to the rpi-4.0.y branch.

@notro
Copy link
Contributor Author

notro commented Jun 29, 2015

@pelwell I'm just amazed by what your overlay mechanism can accomplish. It solves one problem after another with ease.

@dpslwk
Copy link

dpslwk commented Jun 29, 2015

@pelwell that looks like a very nice little work around

@pelwell
Copy link
Contributor

pelwell commented Jun 29, 2015

Oddly, applying the same patch (specifically setting SERIAL_8250_RUNTIME_UARTS=0) to the rpi-4.1.y branch causes it to crash before the serial console comes up. I'll have to return to this later.

@pelwell
Copy link
Contributor

pelwell commented Jun 30, 2015

The 4.1 8250 driver has a bug that causes it to crash if nr_uarts is zero. With this bug patched, the overlay works as expected. Both are now on rpi-4.1.y.

@notro
Copy link
Contributor Author

notro commented Sep 9, 2015

Yes, the baud rate discrepancy was caused by using the core clock directly, which didn't take account of the non-standard clock divisor. Future firmware releases will correctly patch the uart1 clock value, but be aware that if you are overclocking the core you will need to set force_turbo=1 to get a sensible baud rate.

What does this mean?
Should clock-frequency on uart1 really be 250MHz?

The reason I ask is because Eric has a proposal for the aux enable problem using gated clocks.
And as I understand it, it will return 250MHz if we use it for uart1.
http://lists.infradead.org/pipermail/linux-rpi-kernel/2015-September/002261.html

@pelwell
Copy link
Contributor

pelwell commented Sep 10, 2015

This means that that UART1 isn't an exact clone of a 8250 UART. In particular, the clock divisor is calculated differently. A standard 8250 derives the baud rate as clock/(divisor*16), whereas the BCM2835 mini UART uses clock/(divisor*8). This means that if you want to use the standard driver then you need to lie about the clock frequency, providing a value twice the real value, in order for a suitable divisor to be calculated.

The mini UART clock is tied (through a gate) to the core clock. It will therefore normally be 250MHz, but that will change if the VPU is overclocked. The current Pi firmware uses the uart1_clkrate DT parameter, passing in double the value of core_freq. Unless Eric's cprman driver (or the 8250 driver) can be modified in some way, it sounds like UART1 will run twice as quickly as it should.

@notro
Copy link
Contributor Author

notro commented Sep 10, 2015

Maybe we can solve that problem by inserting a "fixed-factor-clock" to double the frequency?

  clocks: cprman@7e101000 {
    compatible = "brcm,bcm2835-cprman";
    #clock-cells = <1>;
    reg = <0x7e101000 0x2000>;
    clocks = <&clk_osc>;
  };

  aux_clocks: aux-clocks@0x7e215004 {
    compatible = "brcm,bcm2835-aux-clock";
    #clock-cells = <1>;
    reg = 0x7e215004 0x4>;
    clocks = <&clk_osc>;
    clocks = <&clocks BCM2835_CLOCK_VPU>;
  };

  uart1: uart@7e215040 {
    compatible = "brcm,bcm2835-aux-uart", "ns16550";
    reg = <0x7e215040 0x40>;
    interrupts = <1 29>;
//    clock-frequency = <500000000>;
    clocks = <&clk_uart1>;
    reg-shift = <2>;
    no-loopback-test;
    status = "disabled";
        };

  clocks: clocks {
    clk_uart1: clock@6 {
      compatible = "fixed-factor-clock";
      clocks = <&aux_clocks BCM2835_AUX_CLOCK_UART>;
      #clock-cells = <0>;
      clock-div = <1>;
      clock-mult = <2>;
    };
  };

http://lxr.free-electrons.com/source/drivers/clk/clk-fixed-factor.c
https://www.kernel.org/doc/Documentation/devicetree/bindings/clock/fixed-factor-clock.txt

@pelwell
Copy link
Contributor

pelwell commented Sep 10, 2015

That's neat (although I'd have called it "fixed-scaled-clock").

@pelwell
Copy link
Contributor

pelwell commented Sep 10, 2015

This patch seems to do the right thing, and removes the need for the uart1_clkrate parameter:

diff --git a/arch/arm/boot/dts/bcm2708_common.dtsi b/arch/arm/boot/dts/bcm2708_c
index f096f45..4d1cc67 100644
--- a/arch/arm/boot/dts/bcm2708_common.dtsi
+++ b/arch/arm/boot/dts/bcm2708_common.dtsi
@@ -165,7 +165,7 @@
                        compatible = "brcm,bcm2835-aux-uart", "ns16550";
                        reg = <0x7e215040 0x40>;
                        interrupts = <1 29>;
-                       clock-frequency = <500000000>;
+                       clocks = <&clk_uart1>;
                        reg-shift = <2>;
                        no-loopback-test;
                        status = "disabled";
@@ -294,6 +294,14 @@
                         clock-output-names = "pwm";
                         clock-frequency = <100000000>;
                };
+
+               clk_uart1: clock@6 {
+                       compatible = "fixed-factor-clock";
+                       clocks = <&clk_core>;
+                       #clock-cells = <0>;
+                       clock-div = <1>;
+                       clock-mult = <2>;
+               };
        };

        __overrides__ {

@notro
Copy link
Contributor Author

notro commented Sep 10, 2015

I didn't think this far, that we could benefit from it already.

This is maybe the best way to work around this discrepency in the almost-like 8250 uart.
I think it's better to do this explicitly like this than to let the bcm2835 clock driver lie about the frequence by doubling it just to please a driver.
And writing a new driver will generate a lot of code I'm afraid. The 16 divisor was in a lot of places in serial_core.c. So a new driver would probably just double the clock and be done with it and use the serial core as-is.

popcornmix added a commit to raspberrypi/firmware that referenced this pull request Sep 14, 2015
kernel: Revert "BCM270X_DT: mz61581: Revert to spi-bcm2708"
See: raspberrypi/linux#1132

kernel: bcm2835-mmc: Don't overwrite MMC capabilities from DT

kernel: BCM270X_DT: Use fixed-factor-clock for uart1
See: raspberrypi/linux#1008

kernel: vchiq: fix NULL pointer dereference when closing driver
See: raspberrypi/linux#1123

firmware: Fix touchscreen I2C to only read from i2c in smaller bursts to avoid a fifo overrun problem with the i2c peripheral
See: https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=120642

firmware: arm_display: Fix issue with nonsensical negative overscan settings
See: #471

firmware: arm_loader: Enable the i2c_arm and i2c_vc aliases for CM
See: raspberrypi/linux#1129

firmware: di_adv: Allow the v3d priority boost to be modified
See: http://forum.kodi.tv/showthread.php?tid=231092&pid=2103200#pid2103200
popcornmix added a commit to Hexxeh/rpi-firmware that referenced this pull request Sep 14, 2015
kernel: Revert "BCM270X_DT: mz61581: Revert to spi-bcm2708"
See: raspberrypi/linux#1132

kernel: bcm2835-mmc: Don't overwrite MMC capabilities from DT

kernel: BCM270X_DT: Use fixed-factor-clock for uart1
See: raspberrypi/linux#1008

kernel: vchiq: fix NULL pointer dereference when closing driver
See: raspberrypi/linux#1123

firmware: Fix touchscreen I2C to only read from i2c in smaller bursts to avoid a fifo overrun problem with the i2c peripheral
See: https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=120642

firmware: arm_display: Fix issue with nonsensical negative overscan settings
See: raspberrypi/firmware#471

firmware: arm_loader: Enable the i2c_arm and i2c_vc aliases for CM
See: raspberrypi/linux#1129

firmware: di_adv: Allow the v3d priority boost to be modified
See: http://forum.kodi.tv/showthread.php?tid=231092&pid=2103200#pid2103200
@msperl
Copy link
Contributor

msperl commented Feb 10, 2016

Note that the drivers/tty/serial/8250/8250_bcm2835aux.c driver (which essentially just doubles clock and is accepted into https://git.kernel.org/cgit/linux/kernel/git/gregkh/tty.git/commit/?h=tty-next&id=bdc5f300958062a766518b81d5378f837149d5c1 but not merged into upstream yet) is a candidate to use in the future. Note that it relies on drivers/clk/bcm/clk-bcm2835-aux.c and drivers/clk/bcm/clk-bcm2835.c, some of which we may already use with the openGL framework...

But while trying to see if setting the console works on ttyS0 I found that there is a clock issue when using the aux uart and then enabling the ttyAMA0 device the system freezes.

So I wonder if this behavior has been seen during development/testing of this downstream solution?

@pelwell
Copy link
Contributor

pelwell commented Feb 10, 2016

Apart from the fact that miniUART/UART1/ttyS0 uses the core clock which changes in turbo mode without force_turbo=1, I've not seen any downstream problems with UARTs and clocks.

If you can reproduce the freeze with the downstream kernel then please create a new issue.

@msperl
Copy link
Contributor

msperl commented Feb 10, 2016

thanks - so you have not seen it...

@dpslwk
Copy link

dpslwk commented Feb 10, 2016

It’s know that the system will freeze any time the port is opened and there is not a device connected to pins for it to talk to,
and if not a device at least an external pul up on the RXD1_pin
but i’ve not had any issue using both ports at the same time during normal OS use.
I have not tried using uart1 as a console.

‘RepRap’ Matt

On 10 Feb 2016, at 11:56, msperl notifications@github.com wrote:

thanks - so you have not seen it...


Reply to this email directly or view it on GitHub #1008 (comment).

@msperl
Copy link
Contributor

msperl commented Feb 10, 2016

as for VPU: i wonder if there is any means to get the clock framework to issue a notification when the
VPU clock is getting changed - but I guess that is something left right now to the firmware, so there is no notification of the kernel anyway... We may get there eventually.

But that is also similar to the SPI clock which also relies on VPU clock, but there the impact is smaller, as spi recalculates the divider on each spi_message, so it only impacts the current in-flight transaction...

Thanks for the info - I will build latest 4.5 and then report to the corresponding lists/Eric.

popcornmix pushed a commit that referenced this pull request Jun 28, 2016
During page migrations UBIFS might get confused
and the following assert triggers:
[  213.480000] UBIFS assert failed in ubifs_set_page_dirty at 1451 (pid 436)
[  213.490000] CPU: 0 PID: 436 Comm: drm-stress-test Not tainted 4.4.4-00176-geaa802524636-dirty #1008
[  213.490000] Hardware name: Allwinner sun4i/sun5i Families
[  213.490000] [<c0015e70>] (unwind_backtrace) from [<c0012cdc>] (show_stack+0x10/0x14)
[  213.490000] [<c0012cdc>] (show_stack) from [<c02ad834>] (dump_stack+0x8c/0xa0)
[  213.490000] [<c02ad834>] (dump_stack) from [<c0236ee8>] (ubifs_set_page_dirty+0x44/0x50)
[  213.490000] [<c0236ee8>] (ubifs_set_page_dirty) from [<c00fa0bc>] (try_to_unmap_one+0x10c/0x3a8)
[  213.490000] [<c00fa0bc>] (try_to_unmap_one) from [<c00fadb4>] (rmap_walk+0xb4/0x290)
[  213.490000] [<c00fadb4>] (rmap_walk) from [<c00fb1bc>] (try_to_unmap+0x64/0x80)
[  213.490000] [<c00fb1bc>] (try_to_unmap) from [<c010dc28>] (migrate_pages+0x328/0x7a0)
[  213.490000] [<c010dc28>] (migrate_pages) from [<c00d0cb0>] (alloc_contig_range+0x168/0x2f4)
[  213.490000] [<c00d0cb0>] (alloc_contig_range) from [<c010ec00>] (cma_alloc+0x170/0x2c0)
[  213.490000] [<c010ec00>] (cma_alloc) from [<c001a958>] (__alloc_from_contiguous+0x38/0xd8)
[  213.490000] [<c001a958>] (__alloc_from_contiguous) from [<c001ad44>] (__dma_alloc+0x23c/0x274)
[  213.490000] [<c001ad44>] (__dma_alloc) from [<c001ae08>] (arm_dma_alloc+0x54/0x5c)
[  213.490000] [<c001ae08>] (arm_dma_alloc) from [<c035cecc>] (drm_gem_cma_create+0xb8/0xf0)
[  213.490000] [<c035cecc>] (drm_gem_cma_create) from [<c035cf20>] (drm_gem_cma_create_with_handle+0x1c/0xe8)
[  213.490000] [<c035cf20>] (drm_gem_cma_create_with_handle) from [<c035d088>] (drm_gem_cma_dumb_create+0x3c/0x48)
[  213.490000] [<c035d088>] (drm_gem_cma_dumb_create) from [<c0341ed8>] (drm_ioctl+0x12c/0x444)
[  213.490000] [<c0341ed8>] (drm_ioctl) from [<c0121adc>] (do_vfs_ioctl+0x3f4/0x614)
[  213.490000] [<c0121adc>] (do_vfs_ioctl) from [<c0121d30>] (SyS_ioctl+0x34/0x5c)
[  213.490000] [<c0121d30>] (SyS_ioctl) from [<c000f2c0>] (ret_fast_syscall+0x0/0x34)

UBIFS is using PagePrivate() which can have different meanings across
filesystems. Therefore the generic page migration code cannot handle this
case correctly.
We have to implement our own migration function which basically does a
plain copy but also duplicates the page private flag.
UBIFS is not a block device filesystem and cannot use buffer_migrate_page().

Cc: stable@vger.kernel.org
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
[rw: Massaged changelog, build fixes, etc...]
Signed-off-by: Richard Weinberger <richard@nod.at>
Acked-by: Christoph Hellwig <hch@lst.de>
popcornmix pushed a commit that referenced this pull request Jul 28, 2016
commit 4ac1c17 upstream.

During page migrations UBIFS might get confused
and the following assert triggers:
[  213.480000] UBIFS assert failed in ubifs_set_page_dirty at 1451 (pid 436)
[  213.490000] CPU: 0 PID: 436 Comm: drm-stress-test Not tainted 4.4.4-00176-geaa802524636-dirty #1008
[  213.490000] Hardware name: Allwinner sun4i/sun5i Families
[  213.490000] [<c0015e70>] (unwind_backtrace) from [<c0012cdc>] (show_stack+0x10/0x14)
[  213.490000] [<c0012cdc>] (show_stack) from [<c02ad834>] (dump_stack+0x8c/0xa0)
[  213.490000] [<c02ad834>] (dump_stack) from [<c0236ee8>] (ubifs_set_page_dirty+0x44/0x50)
[  213.490000] [<c0236ee8>] (ubifs_set_page_dirty) from [<c00fa0bc>] (try_to_unmap_one+0x10c/0x3a8)
[  213.490000] [<c00fa0bc>] (try_to_unmap_one) from [<c00fadb4>] (rmap_walk+0xb4/0x290)
[  213.490000] [<c00fadb4>] (rmap_walk) from [<c00fb1bc>] (try_to_unmap+0x64/0x80)
[  213.490000] [<c00fb1bc>] (try_to_unmap) from [<c010dc28>] (migrate_pages+0x328/0x7a0)
[  213.490000] [<c010dc28>] (migrate_pages) from [<c00d0cb0>] (alloc_contig_range+0x168/0x2f4)
[  213.490000] [<c00d0cb0>] (alloc_contig_range) from [<c010ec00>] (cma_alloc+0x170/0x2c0)
[  213.490000] [<c010ec00>] (cma_alloc) from [<c001a958>] (__alloc_from_contiguous+0x38/0xd8)
[  213.490000] [<c001a958>] (__alloc_from_contiguous) from [<c001ad44>] (__dma_alloc+0x23c/0x274)
[  213.490000] [<c001ad44>] (__dma_alloc) from [<c001ae08>] (arm_dma_alloc+0x54/0x5c)
[  213.490000] [<c001ae08>] (arm_dma_alloc) from [<c035cecc>] (drm_gem_cma_create+0xb8/0xf0)
[  213.490000] [<c035cecc>] (drm_gem_cma_create) from [<c035cf20>] (drm_gem_cma_create_with_handle+0x1c/0xe8)
[  213.490000] [<c035cf20>] (drm_gem_cma_create_with_handle) from [<c035d088>] (drm_gem_cma_dumb_create+0x3c/0x48)
[  213.490000] [<c035d088>] (drm_gem_cma_dumb_create) from [<c0341ed8>] (drm_ioctl+0x12c/0x444)
[  213.490000] [<c0341ed8>] (drm_ioctl) from [<c0121adc>] (do_vfs_ioctl+0x3f4/0x614)
[  213.490000] [<c0121adc>] (do_vfs_ioctl) from [<c0121d30>] (SyS_ioctl+0x34/0x5c)
[  213.490000] [<c0121d30>] (SyS_ioctl) from [<c000f2c0>] (ret_fast_syscall+0x0/0x34)

UBIFS is using PagePrivate() which can have different meanings across
filesystems. Therefore the generic page migration code cannot handle this
case correctly.
We have to implement our own migration function which basically does a
plain copy but also duplicates the page private flag.
UBIFS is not a block device filesystem and cannot use buffer_migrate_page().

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
[rw: Massaged changelog, build fixes, etc...]
Signed-off-by: Richard Weinberger <richard@nod.at>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
popcornmix pushed a commit that referenced this pull request Jul 28, 2016
commit 4ac1c17 upstream.

During page migrations UBIFS might get confused
and the following assert triggers:
[  213.480000] UBIFS assert failed in ubifs_set_page_dirty at 1451 (pid 436)
[  213.490000] CPU: 0 PID: 436 Comm: drm-stress-test Not tainted 4.4.4-00176-geaa802524636-dirty #1008
[  213.490000] Hardware name: Allwinner sun4i/sun5i Families
[  213.490000] [<c0015e70>] (unwind_backtrace) from [<c0012cdc>] (show_stack+0x10/0x14)
[  213.490000] [<c0012cdc>] (show_stack) from [<c02ad834>] (dump_stack+0x8c/0xa0)
[  213.490000] [<c02ad834>] (dump_stack) from [<c0236ee8>] (ubifs_set_page_dirty+0x44/0x50)
[  213.490000] [<c0236ee8>] (ubifs_set_page_dirty) from [<c00fa0bc>] (try_to_unmap_one+0x10c/0x3a8)
[  213.490000] [<c00fa0bc>] (try_to_unmap_one) from [<c00fadb4>] (rmap_walk+0xb4/0x290)
[  213.490000] [<c00fadb4>] (rmap_walk) from [<c00fb1bc>] (try_to_unmap+0x64/0x80)
[  213.490000] [<c00fb1bc>] (try_to_unmap) from [<c010dc28>] (migrate_pages+0x328/0x7a0)
[  213.490000] [<c010dc28>] (migrate_pages) from [<c00d0cb0>] (alloc_contig_range+0x168/0x2f4)
[  213.490000] [<c00d0cb0>] (alloc_contig_range) from [<c010ec00>] (cma_alloc+0x170/0x2c0)
[  213.490000] [<c010ec00>] (cma_alloc) from [<c001a958>] (__alloc_from_contiguous+0x38/0xd8)
[  213.490000] [<c001a958>] (__alloc_from_contiguous) from [<c001ad44>] (__dma_alloc+0x23c/0x274)
[  213.490000] [<c001ad44>] (__dma_alloc) from [<c001ae08>] (arm_dma_alloc+0x54/0x5c)
[  213.490000] [<c001ae08>] (arm_dma_alloc) from [<c035cecc>] (drm_gem_cma_create+0xb8/0xf0)
[  213.490000] [<c035cecc>] (drm_gem_cma_create) from [<c035cf20>] (drm_gem_cma_create_with_handle+0x1c/0xe8)
[  213.490000] [<c035cf20>] (drm_gem_cma_create_with_handle) from [<c035d088>] (drm_gem_cma_dumb_create+0x3c/0x48)
[  213.490000] [<c035d088>] (drm_gem_cma_dumb_create) from [<c0341ed8>] (drm_ioctl+0x12c/0x444)
[  213.490000] [<c0341ed8>] (drm_ioctl) from [<c0121adc>] (do_vfs_ioctl+0x3f4/0x614)
[  213.490000] [<c0121adc>] (do_vfs_ioctl) from [<c0121d30>] (SyS_ioctl+0x34/0x5c)
[  213.490000] [<c0121d30>] (SyS_ioctl) from [<c000f2c0>] (ret_fast_syscall+0x0/0x34)

UBIFS is using PagePrivate() which can have different meanings across
filesystems. Therefore the generic page migration code cannot handle this
case correctly.
We have to implement our own migration function which basically does a
plain copy but also duplicates the page private flag.
UBIFS is not a block device filesystem and cannot use buffer_migrate_page().

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
[rw: Massaged changelog, build fixes, etc...]
Signed-off-by: Richard Weinberger <richard@nod.at>
Acked-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
neuschaefer pushed a commit to neuschaefer/raspi-binary-firmware that referenced this pull request Feb 27, 2017
kernel: Add rpi-ft5406 overlay Add rpi-ft5406 driver as module

kernel: config: Enable 8250 serial port
See: raspberrypi/linux#1008

kernel: config: Enable POWER_RESET_GPIO
See: raspberrypi/linux#1031

firmware: arm_display: Fix fb_base alias returned from mailbox property interface
See: raspberrypi/linux#1026

firmware: mem_unlock - prevent decrementing lock count below 0

firmware: camera: Support multi-channel raw image capture
firmware: camera: write_raw copies input frame if HDR is enabled
firmware: camera: Write correct camera mode from write_raw_md_stage
firmware: AGC tuner: Correction to setting default digital gain to x1.0
neuschaefer pushed a commit to neuschaefer/raspi-binary-firmware that referenced this pull request Feb 27, 2017
kernel: bcm2708-spi: Don't use static pin configuration with DT

kernel: bcm2708-i2s: Don't use static pin configuration with DT

kernel: gpio-poweroff: Allow it to work on Raspberry Pi
See: raspberrypi/linux#1031

kernel: BCM270X_DT: Create a core clock, use it for SPI and sdhost

kernel: BCM270X_DT: Add overlay to enable uart1
See: raspberrypi/linux#1008

kernel: config: Enable ZSMALLOC, ZRAM and PGTABLE_MAPPING
See: Hexxeh/rpi-firmware#85

firmware: arm_loader: Support initialising vchiq through mailbox property interface
See: raspberrypi/linux#1026

firmware: drivers/usb: Reduce busy-wait to sensible timeout
See: raspberrypi/linux#1026

firmware: video_encode: Initialise headers for video_bitrate
See: raspberrypi#163

firmware: arm_loader: Use the new core_freq DT parameter if present

firmware: arm_loader: Set the uart1_clkrate DT property from core_freq

firmware: arm_cursor: Better handling of a second app requesting a cursor

firmware: arm: Tidy up setting of arm_control and arm_bash
neuschaefer pushed a commit to neuschaefer/raspi-binary-firmware that referenced this pull request Feb 27, 2017
kernel: Revert "BCM270X_DT: mz61581: Revert to spi-bcm2708"
See: raspberrypi/linux#1132

kernel: bcm2835-mmc: Don't overwrite MMC capabilities from DT

kernel: BCM270X_DT: Use fixed-factor-clock for uart1
See: raspberrypi/linux#1008

kernel: vchiq: fix NULL pointer dereference when closing driver
See: raspberrypi/linux#1123

firmware: Fix touchscreen I2C to only read from i2c in smaller bursts to avoid a fifo overrun problem with the i2c peripheral
See: https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=120642

firmware: arm_display: Fix issue with nonsensical negative overscan settings
See: raspberrypi#471

firmware: arm_loader: Enable the i2c_arm and i2c_vc aliases for CM
See: raspberrypi/linux#1129

firmware: di_adv: Allow the v3d priority boost to be modified
See: http://forum.kodi.tv/showthread.php?tid=231092&pid=2103200#pid2103200
popcornmix pushed a commit that referenced this pull request Jun 27, 2022
Since setup_tlb_handler() is executed in atomic context, we should use
GFP_ATOMIC instead of GFP_KERNEL to alloc pages. Otherwise we will get
a "sleeping in atomic context" error:

[    0.013118] BUG: sleeping function called from invalid context at mm/page_alloc.c:5158
[    0.013126] in_atomic(): 1, irqs_disabled(): 1, non_block: 0, pid: 0, name: swapper/1
[    0.013131] CPU: 1 PID: 0 Comm: swapper/1 Not tainted 5.19-rc3+ #1008 1a223086d14d07967cc427f15d52139422271360
[    0.013136] Hardware name: Loongson Loongson-3A5000-7A1000-1w-V0.1-CRB/Loongson-LS3A5000-7A1000-1w-EVB-V1.21, BIOS Loongson-UDK2018-V2.0.04082-beta7 04/27
[    0.013140] Stack : 90000000015fc990 9000000100493c18 9000000000df3370 9000000100490000
[    0.013151]         9000000100493b50 0000000000000000 9000000100493b58 9000000001417ef0
[    0.013160]         900000000199e54e 0000000000000040 9000000100493c18 90000000015f7a98
[    0.013168]         ffffffffffffffff 6de72f8b42179d1e 9000000100403b80 90000000015f7890
[    0.013176]         0000000000000001 00000000fffff175 9000000000eb9860 9000000001530b4b
[    0.013184]         9000000000e99e60 0000000000000013 0000000006ecc000 0000000000000001
[    0.013193]         90000000015f7a98 9000000001417ef0 0000000000000004 0000000000000000
[    0.013201]         0000000000000cc0 0000000000000000 0000000000000001 90000000015fc990
[    0.013209]         9000000000217e74 9000000001603b6b 9000000000208640 0000000000000000
[    0.013217]         00000000000000b0 0000000000000004 0000000000000000 0000000000070000
[    0.013225]         ...
[    0.013229] Call Trace:
[    0.013230] [<9000000000208640>] show_stack+0x4c/0x14c
[    0.013240] [<9000000000df3370>] dump_stack_lvl+0x70/0xac
[    0.013246] [<9000000000270c8c>] ___might_sleep+0x104/0x124
[    0.013253] [<9000000000477e84>] __alloc_pages+0x240/0x464
[    0.013260] [<9000000000214214>] setup_tlb_handler+0x104/0x1e8
[    0.013265] [<9000000000214324>] tlb_init+0x2c/0x3c
[    0.013270] [<9000000000208b74>] per_cpu_trap_init+0xec/0x108
[    0.013275] [<9000000000202850>] cpu_probe+0x400/0x8a4
[    0.013279] [<900000000020d160>] start_secondary+0x5c/0x3d4

Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants