reference to Linux Foundation NDA program obsolete?

2020-05-23 Thread Lukas Bulwahn
Hi Jonathan,

while reading the process documentation, I noticed this reference to the 
Linux Foundation NDA program in Documentation/process/3.Early-stage.rst:

-->

That said, there are also cases where a company legitimately cannot
disclose its plans early in the development process.  Companies with
experienced kernel developers may choose to proceed in an open-loop manner
on the assumption that they will be able to avoid serious integration
problems later.  For companies without that sort of in-house expertise, 
the best option is often to hire an outside developer to review the plans 
undera non-disclosure agreement.  The Linux Foundation operates an NDA 
program designed to help with this sort of situation; more information can 
be found at:

http://www.linuxfoundation.org/en/NDA_program

This kind of review is often enough to avoid serious problems later on
without requiring public disclosure of the project.

<--

The link is dead; internet search only showed some references from 
meeting minutes in 2008, but nothing more since then.

Has this LF NDA program simply been phased out?

If so, I will provide a clean-up patch to remove this historic reference.

Lukas


[PATCH] media: venus: core: Fix runtime PM imbalance in venus_probe

2020-05-23 Thread Dinghao Liu
pm_runtime_get_sync() increments the runtime PM usage counter even
when it returns an error code. Thus a pairing decrement is needed on
the error handling path to keep the counter balanced. For other error
paths after this call, things are the same.

Signed-off-by: Dinghao Liu 
---
 drivers/media/platform/qcom/venus/core.c | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/qcom/venus/core.c 
b/drivers/media/platform/qcom/venus/core.c
index 194b10b98767..37db3b594dca 100644
--- a/drivers/media/platform/qcom/venus/core.c
+++ b/drivers/media/platform/qcom/venus/core.c
@@ -289,18 +289,24 @@ static int venus_probe(struct platform_device *pdev)
goto err_core_deinit;
 
ret = pm_runtime_put_sync(dev);
-   if (ret)
-   goto err_dev_unregister;
+   if (ret) {
+   v4l2_device_unregister(>v4l2_dev);
+   hfi_core_deinit(core, false);
+   venus_shutdown(core);
+   pm_runtime_set_suspended(dev);
+   pm_runtime_disable(dev);
+   hfi_destroy(core);
+   return ret;
+   }
 
return 0;
 
-err_dev_unregister:
-   v4l2_device_unregister(>v4l2_dev);
 err_core_deinit:
hfi_core_deinit(core, false);
 err_venus_shutdown:
venus_shutdown(core);
 err_runtime_disable:
+   pm_runtime_put_noidle(dev);
pm_runtime_set_suspended(dev);
pm_runtime_disable(dev);
hfi_destroy(core);
-- 
2.17.1



drivers/misc/pci_endpoint_test.c:347:6: warning: Local variable 'irq_type' shadows outer variable [shadowVariable]

2020-05-23 Thread kbuild test robot
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
master
head:   caffb99b6929f41a69edbb5aef3a359bf45f3315
commit: b2ba9225e0313b1de631a44b7b48c109032bffec misc: pci_endpoint_test: Avoid 
using module parameter to determine irqtype
date:   7 weeks ago
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
reproduce (this is a W=1 build):
git checkout b2ba9225e0313b1de631a44b7b48c109032bffec
# save the attached .config to linux build tree
make ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot 


cppcheck warnings: (new ones prefixed by >>)

>> drivers/misc/pci_endpoint_test.c:347:6: warning: Local variable 'irq_type' 
>> shadows outer variable [shadowVariable]
int irq_type = test->irq_type;
^
   drivers/misc/pci_endpoint_test.c:86:12: note: Shadowed declaration
   static int irq_type = IRQ_TYPE_MSI;
  ^
   drivers/misc/pci_endpoint_test.c:347:6: note: Shadow variable
int irq_type = test->irq_type;
^
   drivers/misc/pci_endpoint_test.c:481:6: warning: Local variable 'irq_type' 
shadows outer variable [shadowVariable]
int irq_type = test->irq_type;
^
   drivers/misc/pci_endpoint_test.c:86:12: note: Shadowed declaration
   static int irq_type = IRQ_TYPE_MSI;
  ^
   drivers/misc/pci_endpoint_test.c:481:6: note: Shadow variable
int irq_type = test->irq_type;
^
   drivers/misc/pci_endpoint_test.c:580:6: warning: Local variable 'irq_type' 
shadows outer variable [shadowVariable]
int irq_type = test->irq_type;
^
   drivers/misc/pci_endpoint_test.c:86:12: note: Shadowed declaration
   static int irq_type = IRQ_TYPE_MSI;
  ^
   drivers/misc/pci_endpoint_test.c:580:6: note: Shadow variable
int irq_type = test->irq_type;
^

vim +/irq_type +347 drivers/misc/pci_endpoint_test.c

   326  
   327  static bool pci_endpoint_test_copy(struct pci_endpoint_test *test,
   328 unsigned long arg)
   329  {
   330  struct pci_endpoint_test_xfer_param param;
   331  bool ret = false;
   332  void *src_addr;
   333  void *dst_addr;
   334  u32 flags = 0;
   335  bool use_dma;
   336  size_t size;
   337  dma_addr_t src_phys_addr;
   338  dma_addr_t dst_phys_addr;
   339  struct pci_dev *pdev = test->pdev;
   340  struct device *dev = >dev;
   341  void *orig_src_addr;
   342  dma_addr_t orig_src_phys_addr;
   343  void *orig_dst_addr;
   344  dma_addr_t orig_dst_phys_addr;
   345  size_t offset;
   346  size_t alignment = test->alignment;
 > 347  int irq_type = test->irq_type;
   348  u32 src_crc32;
   349  u32 dst_crc32;
   350  int err;
   351  
   352  err = copy_from_user(, (void __user *)arg, sizeof(param));
   353  if (err) {
   354  dev_err(dev, "Failed to get transfer param\n");
   355  return false;
   356  }
   357  
   358  size = param.size;
   359  if (size > SIZE_MAX - alignment)
   360  goto err;
   361  
   362  use_dma = !!(param.flags & PCITEST_FLAGS_USE_DMA);
   363  if (use_dma)
   364  flags |= FLAG_USE_DMA;
   365  
   366  if (irq_type < IRQ_TYPE_LEGACY || irq_type > IRQ_TYPE_MSIX) {
   367  dev_err(dev, "Invalid IRQ type option\n");
   368  goto err;
   369  }
   370  
   371  orig_src_addr = kzalloc(size + alignment, GFP_KERNEL);
   372  if (!orig_src_addr) {
   373  dev_err(dev, "Failed to allocate source buffer\n");
   374  ret = false;
   375  goto err;
   376  }
   377  
   378  get_random_bytes(orig_src_addr, size + alignment);
   379  orig_src_phys_addr = dma_map_single(dev, orig_src_addr,
   380  size + alignment, 
DMA_TO_DEVICE);
   381  if (dma_mapping_error(dev, orig_src_phys_addr)) {
   382  dev_err(dev, "failed to map source buffer address\n");
   383  ret = false;
   384  goto err_src_phys_addr;
   385  }
   386  
   387  if (alignment && !IS_ALIGNED(orig_src_phys_addr, alignment)) {
   388  src_phys_addr = PTR_ALIGN(orig_src_phys_addr, 
alignment);
   389  offset = src_phys_addr - orig_src_phys_addr;
   390  src_addr = orig_src_addr + offset;
   391  } else {
   392  src_phys_addr = orig_src_phys_addr;
   393  src_addr = orig_src_addr;
   394  }
   395  
   396  pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_LOWER_SRC_ADDR,
   397   lower_32_bits(src_phys_addr));
   398  
   399  

KVM broken after suspend in most recent kernels.

2020-05-23 Thread Brad Campbell

G'day all.

Machine is a Macbook Pro Retina ~ 2014. Kernels are always vanilla kernel and 
compiled on the machine. No additional patches.

vendor_id   : GenuineIntel
cpu family  : 6
model   : 69
model name  : Intel(R) Core(TM) i5-4278U CPU @ 2.60GHz
stepping: 1
microcode   : 0x25
cpu MHz : 2795.034
cache size  : 3072 KB
physical id : 0
siblings: 4
core id : 1
cpu cores   : 2
apicid  : 3
initial apicid  : 3
fpu : yes
fpu_exception   : yes
cpuid level : 13
wp  : yes
flags   : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov 
pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb 
rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology 
nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 
ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt 
tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm cpuid_fault epb 
invpcid_single ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid 
ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida 
arat pln pts md_clear flush_l1d
vmx flags   : vnmi preemption_timer invvpid ept_x_only ept_ad ept_1gb 
flexpriority tsc_offset vtpr mtf vapic ept vpid unrestricted_guest ple
bugs: cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds 
swapgs itlb_multihit
bogomips: 5199.87
clflush size: 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual


KVM worked fine in kernels somewhere prior to 5.4-5.5.

KVM works fine in later kernels up to and including 5.7.0-rc6 after a clean 
boot. It does not work after a suspend.

I can't actually bisect this because there is a bug in earlier kernels that 
breaks the suspend method used which requires manual patching to work around.

This is using qemu version 5.0.0, but also happens with 4.2.0.

In kernels earlier than 5.7 it results in either an immediate hard lock, or a 
GPF that results in progressive system freeze until a hard reboot is required 
(won't flush to disk so no logs get recorded and I have no serial or netconsole 
ability). In 5.7-rc6 it results in the following trace and thankfully no 
further issues (so I can get the logs and report it).

I can and will perform any required testing and debugging, but this machine 
suspends with pm-utils s2both, and that is broken between about 5.4 & 5.6 due 
to swapfile locking issues, which makes actual bisection very, very difficult as it 
*requires* a suspend/resume to trigger the bug.

[  227.715173] [ cut here ]
[  227.715176] VMXON faulted, MSR_IA32_FEAT_CTL (0x3a) = 0x4
[  227.715194] WARNING: CPU: 0 PID: 5502 at arch/x86/kvm/vmx/vmx.c:2239 
hardware_enable+0x167/0x180 [kvm_intel]
[  227.715195] Modules linked in: brcmfmac xhci_pci xhci_hcd cmac bnep 
iptable_nat xt_MASQUERADE nf_nat nf_conntrack nf_defrag_ipv4 ip_tables x_tables 
nfsd bridge stp llc appletouch brcmutil snd_hda_codec_hdmi sha256_ssse3 
snd_hda_codec_cirrus snd_hda_codec_generic sha256_generic libsha256 
x86_pkg_temp_thermal coretemp btusb kvm_intel btrtl kvm btbcm btintel irqbypass 
bluetooth cfg80211 snd_hda_intel ecdh_generic ecc snd_intel_dspcfg bcm5974 
rfkill snd_hda_codec snd_hwdep snd_hda_core snd_pcm_oss snd_pcm snd_seq_midi 
snd_seq_midi_event snd_rawmidi i915 snd_seq snd_seq_device snd_timer 
i2c_algo_bit iosf_mbi drm_kms_helper syscopyarea sysfillrect sysimgblt 
fb_sys_fops snd drm intel_gtt agpgart evdev apple_bl video soundcore hid_apple 
usb_storage hid_generic usbhid hid dm_crypt dm_mod i2c_i801 i2c_core sg usbcore 
usb_common [last unloaded: xhci_hcd]
[  227.715221] CPU: 0 PID: 5502 Comm: qemu Not tainted 5.7.0-rc6+ #15
[  227.715222] Hardware name: Apple Inc. MacBookPro11,1/Mac-189A3D4F975D5FFC, 
BIOS 159.0.0.0.0 02/05/2020
[  227.715225] RIP: 0010:hardware_enable+0x167/0x180 [kvm_intel]
[  227.715227] Code: 01 00 01 b9 3a 00 00 00 0f 32 31 c9 48 c1 e2 20 be ef be ad de 
48 c7 c7 68 fd bb c0 48 09 c2 85 c9 48 0f 44 f2 e8 43 78 4f dc <0f> 0b eb 8a 48 
8b 15 ce 89 06 dd e9 c7 fe ff ff 66 0f 1f 84 00 00
[  227.715228] RSP: 0018:97091d873df8 EFLAGS: 00010092
[  227.715229] RAX: 002d RBX: 0046 RCX: 0007
[  227.715230] RDX: 0007 RSI: 0082 RDI: 97091f2187a0
[  227.715231] RBP: 97091d873e10 R08: 0008 R09: 0495
[  227.715232] R10: 0010 R11: 97091d873c6d R12: 
[  227.715233] R13: 0286 R14: b5d08015e010 R15: 
[  227.715234] FS:  7f1468fd33c0() GS:97091f20() 
knlGS:
[  227.715235] CS:  0010 DS:  ES:  CR0: 80050033
[  227.715236] CR2: 563b54c7201d CR3: 00043f43f001 CR4: 001626f0
[  227.715237] DR0:  DR1:  DR2: 
[  227.715238] DR3: 

[PATCH v7 4/4] gpio: xilinx: Utilize for_each_set_clump macro

2020-05-23 Thread Syed Nayyar Waris
This patch reimplements the xgpio_set_multiple function in
drivers/gpio/gpio-xilinx.c to use the new for_each_set_clump macro.
Instead of looping for each bit in xgpio_set_multiple
function, now we can check each channel at a time and save cycles.

Cc: Bartosz Golaszewski 
Cc: Michal Simek 
Signed-off-by: Syed Nayyar Waris 
Signed-off-by: William Breathitt Gray 
---
Changes in v7:
 - No change.

Changes in v6:
 - No change.

Changes in v5:
 - Minor change: Inline values '32' and '64' in code for better
   code readability.

Changes in v4:
 - Minor change: Inline values '32' and '64' in code for better
   code readability.

Changes in v3:
 - No change.

Changes in v2:
 - No change.

 drivers/gpio/gpio-xilinx.c | 62 --
 1 file changed, 32 insertions(+), 30 deletions(-)

diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c
index 67f9f82e0db0..e81092dea27e 100644
--- a/drivers/gpio/gpio-xilinx.c
+++ b/drivers/gpio/gpio-xilinx.c
@@ -136,39 +136,41 @@ static void xgpio_set(struct gpio_chip *gc, unsigned int 
gpio, int val)
 static void xgpio_set_multiple(struct gpio_chip *gc, unsigned long *mask,
   unsigned long *bits)
 {
-   unsigned long flags;
+   unsigned long flags[2];
struct xgpio_instance *chip = gpiochip_get_data(gc);
-   int index = xgpio_index(chip, 0);
-   int offset, i;
-
-   spin_lock_irqsave(>gpio_lock[index], flags);
-
-   /* Write to GPIO signals */
-   for (i = 0; i < gc->ngpio; i++) {
-   if (*mask == 0)
-   break;
-   /* Once finished with an index write it out to the register */
-   if (index !=  xgpio_index(chip, i)) {
-   xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET +
-  index * XGPIO_CHANNEL_OFFSET,
-  chip->gpio_state[index]);
-   spin_unlock_irqrestore(>gpio_lock[index], flags);
-   index =  xgpio_index(chip, i);
-   spin_lock_irqsave(>gpio_lock[index], flags);
-   }
-   if (__test_and_clear_bit(i, mask)) {
-   offset =  xgpio_offset(chip, i);
-   if (test_bit(i, bits))
-   chip->gpio_state[index] |= BIT(offset);
-   else
-   chip->gpio_state[index] &= ~BIT(offset);
-   }
+   u32 *const state = chip->gpio_state;
+   unsigned int *const width = chip->gpio_width;
+   unsigned long offset, clump;
+   size_t index;
+
+   DECLARE_BITMAP(old, 64);
+   DECLARE_BITMAP(new, 64);
+   DECLARE_BITMAP(changed, 64);
+
+   spin_lock_irqsave(>gpio_lock[0], flags[0]);
+   spin_lock_irqsave(>gpio_lock[1], flags[1]);
+
+   bitmap_set_value(old, state[0], 0, width[0]);
+   bitmap_set_value(old, state[1], width[0], width[1]);
+   bitmap_replace(new, old, bits, mask, gc->ngpio);
+
+   bitmap_set_value(old, state[0], 0, 32);
+   bitmap_set_value(old, state[1], 32, 32);
+   state[0] = bitmap_get_value(new, 0, width[0]);
+   state[1] = bitmap_get_value(new, width[0], width[1]);
+   bitmap_set_value(new, state[0], 0, 32);
+   bitmap_set_value(new, state[1], 32, 32);
+   bitmap_xor(changed, old, new, 64);
+
+   for_each_set_clump(offset, clump, changed, 64, 32) {
+   index = offset / 32;
+   xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET +
+   index * XGPIO_CHANNEL_OFFSET,
+   state[index]);
}
 
-   xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET +
-  index * XGPIO_CHANNEL_OFFSET, chip->gpio_state[index]);
-
-   spin_unlock_irqrestore(>gpio_lock[index], flags);
+   spin_unlock_irqrestore(>gpio_lock[1], flags[1]);
+   spin_unlock_irqrestore(>gpio_lock[0], flags[0]);
 }
 
 /**
-- 
2.26.2



[PATCH v7 3/4] gpio: thunderx: Utilize for_each_set_clump macro

2020-05-23 Thread Syed Nayyar Waris
This patch reimplements the thunderx_gpio_set_multiple function in
drivers/gpio/gpio-thunderx.c to use the new for_each_set_clump macro.
Instead of looping for each bank in thunderx_gpio_set_multiple
function, now we can skip bank which is not set and save cycles.

Cc: Robert Richter 
Cc: Bartosz Golaszewski 
Signed-off-by: Syed Nayyar Waris 
Signed-off-by: William Breathitt Gray 
---
Changes in v7:
 - No change.

Changes in v6:
 - No change.

Changes in v5:
 - No change.

Changes in v4:
 - Minor change: Inline value '64' in code for better code readability.

Changes in v3:
 - Change datatype of some variables from u64 to unsigned long
   in function thunderx_gpio_set_multiple.

Changes in v2:
 - No change.

 drivers/gpio/gpio-thunderx.c | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/gpio/gpio-thunderx.c b/drivers/gpio/gpio-thunderx.c
index 9f66deab46ea..58c9bb25a377 100644
--- a/drivers/gpio/gpio-thunderx.c
+++ b/drivers/gpio/gpio-thunderx.c
@@ -275,12 +275,15 @@ static void thunderx_gpio_set_multiple(struct gpio_chip 
*chip,
   unsigned long *bits)
 {
int bank;
-   u64 set_bits, clear_bits;
+   unsigned long set_bits, clear_bits, gpio_mask;
+   unsigned long offset;
+
struct thunderx_gpio *txgpio = gpiochip_get_data(chip);
 
-   for (bank = 0; bank <= chip->ngpio / 64; bank++) {
-   set_bits = bits[bank] & mask[bank];
-   clear_bits = ~bits[bank] & mask[bank];
+   for_each_set_clump(offset, gpio_mask, mask, chip->ngpio, 64) {
+   bank = offset / 64;
+   set_bits = bits[bank] & gpio_mask;
+   clear_bits = ~bits[bank] & gpio_mask;
writeq(set_bits, txgpio->register_base + (bank * GPIO_2ND_BANK) 
+ GPIO_TX_SET);
writeq(clear_bits, txgpio->register_base + (bank * 
GPIO_2ND_BANK) + GPIO_TX_CLR);
}
-- 
2.26.2



Re: [PATCH V3] thermal: imx: Add missing of_node_put()

2020-05-23 Thread Daniel Lezcano
On 24/05/2020 05:26, Anson Huang wrote:
> Gentle ping...

It is applied, sorry for not letting you know.

>> Subject: [PATCH V3] thermal: imx: Add missing of_node_put()
>>
>> After finishing using cpu node got from of_get_cpu_node(), of_node_put()
>> needs to be called, the cpufreq policy also needs to be put unconditionally.
>>
>> Signed-off-by: Anson Huang 
>> ---
>> Changes since V2:
>>  - call cpufreq_cpu_put() unconditionally after cooling register done.
>> ---
>>  drivers/thermal/imx_thermal.c | 13 ++---
>>  1 file changed, 6 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c
>> index e761c9b..8764cb5 100644
>> --- a/drivers/thermal/imx_thermal.c
>> +++ b/drivers/thermal/imx_thermal.c
>> @@ -649,7 +649,7 @@ MODULE_DEVICE_TABLE(of, of_imx_thermal_match);
>> static int imx_thermal_register_legacy_cooling(struct imx_thermal_data *data)
>> {
>>  struct device_node *np;
>> -int ret;
>> +int ret = 0;
>>
>>  data->policy = cpufreq_cpu_get(0);
>>  if (!data->policy) {
>> @@ -661,20 +661,19 @@ static int
>> imx_thermal_register_legacy_cooling(struct imx_thermal_data *data)
>>
>>  if (!np || !of_find_property(np, "#cooling-cells", NULL)) {
>>  data->cdev = cpufreq_cooling_register(data->policy);
>> -if (IS_ERR(data->cdev)) {
>> +if (IS_ERR(data->cdev))
>>  ret = PTR_ERR(data->cdev);
>> -cpufreq_cpu_put(data->policy);
>> -return ret;
>> -}
>>  }
>>
>> -return 0;
>> +cpufreq_cpu_put(data->policy);
>> +of_node_put(np);
>> +
>> +return ret;
>>  }
>>
>>  static void imx_thermal_unregister_legacy_cooling(struct imx_thermal_data
>> *data)  {
>>  cpufreq_cooling_unregister(data->cdev);
>> -cpufreq_cpu_put(data->policy);
>>  }
>>
>>  #else
>> --
>> 2.7.4
> 


-- 
 Linaro.org │ Open source software for ARM SoCs

Follow Linaro:   Facebook |
 Twitter |
 Blog


[PATCH v7 2/4] lib/test_bitmap.c: Add for_each_set_clump test cases

2020-05-23 Thread Syed Nayyar Waris
The introduction of the generic for_each_set_clump macro need test
cases to verify the implementation. This patch adds test cases for
scenarios in which clump sizes are 8 bits, 24 bits, 30 bits and 6 bits.
The cases contain situations where clump is getting split at the word
boundary and also when zeroes are present in the start and middle of
bitmap.

Signed-off-by: Syed Nayyar Waris 
Reviewed-by: Andy Shevchenko 
Signed-off-by: William Breathitt Gray 
---
Changes in v7:
 - Minor changes: Use macro 'DECLARE_BITMAP()' and split 'struct'
   definition and test data.

Changes in v6:
 - Make 'for loop' inside 'test_for_each_set_clump' more succinct.

Changes in v5:
 - No change.

Changes in v4:
 - Use 'for' loop in test function of 'for_each_set_clump'.

Changes in v3:
 - No Change.

Changes in v2:
 - Unify different tests for 'for_each_set_clump'. Pass test data as
   function parameters.
 - Remove unnecessary bitmap_zero calls.

 lib/test_bitmap.c | 144 ++
 1 file changed, 144 insertions(+)

diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index 6b13150667f5..31b3cd920c93 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -155,6 +155,38 @@ static bool __init __check_eq_clump8(const char *srcfile, 
unsigned int line,
return true;
 }
 
+static bool __init __check_eq_clump(const char *srcfile, unsigned int line,
+   const unsigned int offset,
+   const unsigned int size,
+   const unsigned long *const clump_exp,
+   const unsigned long *const clump,
+   const unsigned long clump_size)
+{
+   unsigned long exp;
+
+   if (offset >= size) {
+   pr_warn("[%s:%u] bit offset for clump out-of-bounds: expected 
less than %u, got %u\n",
+   srcfile, line, size, offset);
+   return false;
+   }
+
+   exp = clump_exp[offset / clump_size];
+   if (!exp) {
+   pr_warn("[%s:%u] bit offset for zero clump: expected nonzero 
clump, got bit offset %u with clump value 0",
+   srcfile, line, offset);
+   return false;
+   }
+
+   if (*clump != exp) {
+   pr_warn("[%s:%u] expected clump value of 0x%lX, got clump value 
of 0x%lX",
+   srcfile, line, exp, *clump);
+   return false;
+   }
+
+   return true;
+}
+
+
 #define __expect_eq(suffix, ...)   \
({  \
int result = 0; \
@@ -172,6 +204,7 @@ static bool __init __check_eq_clump8(const char *srcfile, 
unsigned int line,
 #define expect_eq_pbl(...) __expect_eq(pbl, ##__VA_ARGS__)
 #define expect_eq_u32_array(...)   __expect_eq(u32_array, ##__VA_ARGS__)
 #define expect_eq_clump8(...)  __expect_eq(clump8, ##__VA_ARGS__)
+#define expect_eq_clump(...)   __expect_eq(clump, ##__VA_ARGS__)
 
 static void __init test_zero_clear(void)
 {
@@ -577,6 +610,28 @@ static void noinline __init test_mem_optimisations(void)
}
 }
 
+static const unsigned long clump_bitmap_data[] __initconst = {
+   0x38000201,
+   0x05ff0f38,
+   0xeffedcba,
+   0xabcd,
+   0x00aa,
+   0x00aa,
+   0x00ff,
+   0xaa00,
+   0xff00,
+   0x00aa,
+   0x,
+   0x,
+   0x,
+   0x0f00,
+   0x00ff,
+   0xaa00,
+   0xff00,
+   0x00aa,
+   0x0ac0,
+};
+
 static const unsigned char clump_exp[] __initconst = {
0x01,   /* 1 bit set */
0x02,   /* non-edge 1 bit set */
@@ -588,6 +643,94 @@ static const unsigned char clump_exp[] __initconst = {
0x05,   /* non-adjacent 2 bits set */
 };
 
+static const unsigned long clump_exp1[] __initconst = {
+   0x01,   /* 1 bit set */
+   0x02,   /* non-edge 1 bit set */
+   0x00,   /* zero bits set */
+   0x38,   /* 3 bits set across 4-bit boundary */
+   0x38,   /* Repeated clump */
+   0x0F,   /* 4 bits set */
+   0xFF,   /* all bits set */
+   0x05,   /* non-adjacent 2 bits set */
+};
+
+static const unsigned long clump_exp2[] __initconst = {
+   0xfedcba,   /* 24 bits */
+   0xabcdef,
+   0xaa,   /* Clump split between 2 words */
+   0x00,   /* zeroes in between */
+   0xaa,
+   0x00,
+   0xff,
+   0xaa,
+   0x00,
+   0xff,
+};
+
+static const unsigned long clump_exp3[] __initconst = {
+   0x, /* starting with 0s*/
+   0x, /* All 0s */
+   0x,
+   0x,
+   0x3f0f, /* Non zero set */
+   0x2aa80003,
+   0x0aaa,
+   0x3fc0,
+};
+
+static const 

[PATCH v7 1/4] bitops: Introduce the the for_each_set_clump macro

2020-05-23 Thread Syed Nayyar Waris
This macro iterates for each group of bits (clump) with set bits,
within a bitmap memory region. For each iteration, "start" is set to
the bit offset of the found clump, while the respective clump value is
stored to the location pointed by "clump". Additionally, the
bitmap_get_value and bitmap_set_value functions are introduced to
respectively get and set a value of n-bits in a bitmap memory region.
The n-bits can have any size less than or equal to BITS_PER_LONG.
Moreover, during setting value of n-bit in bitmap, if a situation arise
that the width of next n-bit is exceeding the word boundary, then it
will divide itself such that some portion of it is stored in that word,
while the remaining portion is stored in the next higher word. Similar
situation occurs while retrieving value of n-bits from bitmap.

Cc: Arnd Bergmann 
Signed-off-by: Syed Nayyar Waris 
Reviewed-by: Andy Shevchenko 
Signed-off-by: William Breathitt Gray 
---
Changes in v7:
 - No change.

Changes in v6:
 - No change.

Changes in v5:
 - No change.

Changes in v4:
 - No change.

Changes in v3:
 - No change.

Changes in v2:
 - No change.

 include/asm-generic/bitops/find.h | 19 ++
 include/linux/bitmap.h| 61 +++
 include/linux/bitops.h| 13 +++
 lib/find_bit.c| 14 +++
 4 files changed, 107 insertions(+)

diff --git a/include/asm-generic/bitops/find.h 
b/include/asm-generic/bitops/find.h
index 9fdf21302fdf..4e6600759455 100644
--- a/include/asm-generic/bitops/find.h
+++ b/include/asm-generic/bitops/find.h
@@ -97,4 +97,23 @@ extern unsigned long find_next_clump8(unsigned long *clump,
 #define find_first_clump8(clump, bits, size) \
find_next_clump8((clump), (bits), (size), 0)
 
+/**
+ * find_next_clump - find next clump with set bits in a memory region
+ * @clump: location to store copy of found clump
+ * @addr: address to base the search on
+ * @size: bitmap size in number of bits
+ * @offset: bit offset at which to start searching
+ * @clump_size: clump size in bits
+ *
+ * Returns the bit offset for the next set clump; the found clump value is
+ * copied to the location pointed by @clump. If no bits are set, returns @size.
+ */
+extern unsigned long find_next_clump(unsigned long *clump,
+ const unsigned long *addr,
+ unsigned long size, unsigned long offset,
+ unsigned long clump_size);
+
+#define find_first_clump(clump, bits, size, clump_size) \
+   find_next_clump((clump), (bits), (size), 0, (clump_size))
+
 #endif /*_ASM_GENERIC_BITOPS_FIND_H_ */
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index 99058eb81042..7ab2c65fc964 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -75,7 +75,11 @@
  *  bitmap_from_arr32(dst, buf, nbits)  Copy nbits from u32[] buf to 
dst
  *  bitmap_to_arr32(buf, src, nbits)Copy nbits from buf to u32[] 
dst
  *  bitmap_get_value8(map, start)   Get 8bit value from map at 
start
+ *  bitmap_get_value(map, start, nbits)Get bit value of size
+ * 'nbits' from map at start
  *  bitmap_set_value8(map, value, start)Set 8bit value to map at start
+ *  bitmap_set_value(map, value, start, nbits) Set bit value of size 'nbits'
+ * of map at start
  *
  * Note, bitmap_zero() and bitmap_fill() operate over the region of
  * unsigned longs, that is, bits behind bitmap till the unsigned long
@@ -563,6 +567,34 @@ static inline unsigned long bitmap_get_value8(const 
unsigned long *map,
return (map[index] >> offset) & 0xFF;
 }
 
+/**
+ * bitmap_get_value - get a value of n-bits from the memory region
+ * @map: address to the bitmap memory region
+ * @start: bit offset of the n-bit value
+ * @nbits: size of value in bits
+ *
+ * Returns value of nbits located at the @start bit offset within the @map
+ * memory region.
+ */
+static inline unsigned long bitmap_get_value(const unsigned long *map,
+ unsigned long start,
+ unsigned long nbits)
+{
+   const size_t index = BIT_WORD(start);
+   const unsigned long offset = start % BITS_PER_LONG;
+   const unsigned long ceiling = roundup(start + 1, BITS_PER_LONG);
+   const unsigned long space = ceiling - start;
+   unsigned long value_low, value_high;
+
+   if (space >= nbits)
+   return (map[index] >> offset) & GENMASK(nbits - 1, 0);
+   else {
+   value_low = map[index] & BITMAP_FIRST_WORD_MASK(start);
+   value_high = map[index + 1] & BITMAP_LAST_WORD_MASK(start + 
nbits);
+   return (value_low >> offset) | (value_high << space);
+   }
+}
+
 /**
  * bitmap_set_value8 - set an 8-bit value within a memory region
  * @map: address to the 

[PATCH v7 0/4] Introduce the for_each_set_clump macro

2020-05-23 Thread Syed Nayyar Waris
Hello Linus,

Since this patchset primarily affects GPIO drivers, would you like
to pick it up through your GPIO tree?

This patchset introduces a new generic version of for_each_set_clump. 
The previous version of for_each_set_clump8 used a fixed size 8-bit
clump, but the new generic version can work with clump of any size but
less than or equal to BITS_PER_LONG. The patchset utilizes the new macro 
in several GPIO drivers.

The earlier 8-bit for_each_set_clump8 facilitated a
for-loop syntax that iterates over a memory region entire groups of set
bits at a time.

For example, suppose you would like to iterate over a 32-bit integer 8
bits at a time, skipping over 8-bit groups with no set bit, where
 represents the current 8-bit group:

Example:1010   00110011
First loop: 1010   
Second loop:1010   00110011
Third loop:    00110011

Each iteration of the loop returns the next 8-bit group that has at
least one set bit.

But with the new for_each_set_clump the clump size can be different from 8 bits.
Moreover, the clump can be split at word boundary in situations where word 
size is not multiple of clump size. Following are examples showing the working 
of new macro for clump sizes of 24 bits and 6 bits.

Example 1:
clump size: 24 bits, Number of clumps (or ports): 10
bitmap stores the bit information from where successive clumps are retrieved.

 /* bitmap memory region */
0x00aaff00;  /* Most significant bits */
0xaaff;
0x00aa00aa;
0xabcdeffedcba;  /* Least significant bits */

Different iterations of for_each_set_clump:-
'offset' is the bit position and 'clump' is the 24 bit clump from the
above bitmap.
Iteration first:offset: 0 clump: 0xfedcba
Iteration second:   offset: 24 clump: 0xabcdef
Iteration third:offset: 48 clump: 0xaa
Iteration fourth:   offset: 96 clump: 0xaa
Iteration fifth:offset: 144 clump: 0xff
Iteration sixth:offset: 168 clump: 0xaa
Iteration seventh:  offset: 216 clump: 0xff
Loop breaks because in the end the remaining bits (0x00aa) size was less
than clump size of 24 bits.

In above example it can be seen that in iteration third, the 24 bit clump
that was retrieved was split between bitmap[0] and bitmap[1]. This example 
also shows that 24 bit zeroes if present in between, were skipped (preserving
the previous for_each_set_macro8 behaviour). 

Example 2:
clump size = 6 bits, Number of clumps (or ports) = 3.

 /* bitmap memory region */
0x00aaff00;  /* Most significant bits */
0xaaff;
0x0f00;
0x0ac0;  /* Least significant bits */

Different iterations of for_each_set_clump:
'offset' is the bit position and 'clump' is the 6 bit clump from the
above bitmap.
Iteration first:offset: 6 clump: 0x2b
Loop breaks because 6 * 3 = 18 bits traversed in bitmap.
Here 6 * 3 is clump size * no. of clumps.

Changes in v7:
 - [Patch 2/4]: Minor changes: Use macro 'DECLARE_BITMAP()' and split 'struct'
   definition and test data.

Changes in v6:
 - [Patch 2/4]: Make 'for loop' inside test_for_each_set_clump more
   succinct.

Changes in v5:
 - [Patch 4/4]: Minor change: Hardcode value for better code readability.

Changes in v4:
 - [Patch 2/4]: Use 'for' loop in test function of for_each_set_clump.
 - [Patch 3/4]: Minor change: Inline value for better code readability.
 - [Patch 4/4]: Minor change: Inline value for better code readability.

Changes in v3:
 - [Patch 3/4]: Change datatype of some variables from u64 to unsigned long
   in function thunderx_gpio_set_multiple.

CHanges in v2:
 - [Patch 2/4]: Unify different tests for 'for_each_set_clump'. Pass test data 
as
   function parameters.
 - [Patch 2/4]: Remove unnecessary bitmap_zero calls.

Syed Nayyar Waris (4):
  bitops: Introduce the the for_each_set_clump macro
  lib/test_bitmap.c: Add for_each_set_clump test cases
  gpio: thunderx: Utilize for_each_set_clump macro
  gpio: xilinx: Utilize for_each_set_clump macro

 drivers/gpio/gpio-thunderx.c  |  11 ++-
 drivers/gpio/gpio-xilinx.c|  62 ++---
 include/asm-generic/bitops/find.h |  19 
 include/linux/bitmap.h|  61 +
 include/linux/bitops.h|  13 +++
 lib/find_bit.c|  14 +++
 lib/test_bitmap.c | 144 ++
 7 files changed, 290 insertions(+), 34 deletions(-)


base-commit: b9bbe6ed63b2b9f2c9ee5cbd0f2c946a2723f4ce
-- 
2.26.2



[PATCH] arm64: ptrace: Fix PTRACE_SINGLESTEP into signal handler

2020-05-23 Thread Keno Fischer
Executing PTRACE_SINGLESTEP at a signal stop is special. It
is supposed to step merely the signal setup work that the
kernel does, but not any instructions in user space. Since
not all architectures have the ability to generate a
single-step exception directly upon return from user-space,
there is a generic pseudo-single-step-stop that may be used
for this purpose (tracehook_signal_handler). Now, arm64 does
have the ability to generate single-step exceptions directly
upon return to userspace and was using this capability (rather
than the generic pseudo-trap) to obtain a similar effect. However,
there is actually a subtle difference that becomes noticeable
when the signal handler in question attempts to block SIGTRAP
(either because it is set in sa_mask, or because it is a handler
for SIGTRAP itself and SA_NODEFER is not set). In such a
situation, a real single step exception will cause the SIGTRAP
signal to be forcibly unblocked and the signal disposition
to be reset to SIG_DFL. The generic pseudo-single-step does
not suffer from this problem, because the SIGTRAP it delivers
is not real. The arm64 behavior is problematic, because a forced
reset of the signal disposition can be quite disruptive to the
userspace program. This patch brings the arm64 behavior in line
with the other major architectures by using the generic
pseudo-single-step-stop, avoiding the problematic interaction
with SIGTRAP masks.

Fixes: 2c020ed8 ("arm64: Signal handling support")
Signed-off-by: Keno Fischer 
---
 arch/arm64/kernel/signal.c | 9 +
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
index 339882db5a91..cf237ee9443b 100644
--- a/arch/arm64/kernel/signal.c
+++ b/arch/arm64/kernel/signal.c
@@ -808,14 +808,7 @@ static void handle_signal(struct ksignal *ksig, struct 
pt_regs *regs)
 */
ret |= !valid_user_regs(>user_regs, current);
 
-   /*
-* Fast forward the stepping logic so we step into the signal
-* handler.
-*/
-   if (!ret)
-   user_fastforward_single_step(tsk);
-
-   signal_setup_done(ret, ksig, 0);
+   signal_setup_done(ret, ksig, test_thread_flag(TIF_SINGLESTEP));
 }
 
 /*
-- 
2.25.1



[PATCH] media: venus: venc: Fix runtime PM imbalance in venc_open

2020-05-23 Thread Dinghao Liu
pm_runtime_get_sync() increments the runtime PM usage counter even
when it returns an error code. Thus a pairing decrement is needed on
the error handling path to keep the counter balanced.

Signed-off-by: Dinghao Liu 
---
 drivers/media/platform/qcom/venus/venc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/platform/qcom/venus/venc.c 
b/drivers/media/platform/qcom/venus/venc.c
index 9981a2a27c90..eefcfbb8f211 100644
--- a/drivers/media/platform/qcom/venus/venc.c
+++ b/drivers/media/platform/qcom/venus/venc.c
@@ -1169,7 +1169,7 @@ static int venc_open(struct file *file)
 
ret = pm_runtime_get_sync(core->dev_enc);
if (ret < 0)
-   goto err_free_inst;
+   goto err_put_sync;
 
ret = venc_ctrl_init(inst);
if (ret)
@@ -1214,7 +1214,6 @@ static int venc_open(struct file *file)
venc_ctrl_deinit(inst);
 err_put_sync:
pm_runtime_put_sync(core->dev_enc);
-err_free_inst:
kfree(inst);
return ret;
 }
-- 
2.17.1



[linux-next RFC v2] mm/gup.c: Convert to use get_user_{page|pages}_fast_only()

2020-05-23 Thread Souptick Joarder
API __get_user_pages_fast() renamed to get_user_pages_fast_only()
to align with pin_user_pages_fast_only().

As part of this we will get rid of write parameter. Instead caller
will pass FOLL_WRITE to get_user_pages_fast_only(). This will not
change any existing functionality of the API.

All the callers are changed to pass FOLL_WRITE.

There are few places where 1 is passed to 2nd parameter of
__get_user_pages_fast() and return value is checked for 1
like [1]. Those are replaced with new inline
get_user_page_fast_only().

[1] if (__get_user_pages_fast(hva, 1, 1, ) == 1)

Updated the documentation of the API.

Signed-off-by: Souptick Joarder 
Cc: John Hubbard 
Cc: Matthew Wilcox 
---
v2:
Updated the subject line and change log.
Address Matthew's comment to fix a bug and added
new inline get_user_page_fast_only().

 arch/powerpc/kvm/book3s_64_mmu_hv.c|  2 +-
 arch/powerpc/kvm/book3s_64_mmu_radix.c |  2 +-
 arch/powerpc/perf/callchain_64.c   |  4 +---
 include/linux/mm.h | 10 --
 kernel/events/core.c   |  4 ++--
 mm/gup.c   | 29 -
 virt/kvm/kvm_main.c|  8 +++-
 7 files changed, 32 insertions(+), 27 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c 
b/arch/powerpc/kvm/book3s_64_mmu_hv.c
index 18aed97..ddfc4c9 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
@@ -581,7 +581,7 @@ int kvmppc_book3s_hv_page_fault(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
 * We always ask for write permission since the common case
 * is that the page is writable.
 */
-   if (__get_user_pages_fast(hva, 1, 1, ) == 1) {
+   if (get_user_page_fast_only(hva, FOLL_WRITE, )) {
write_ok = true;
} else {
/* Call KVM generic code to do the slow-path check */
diff --git a/arch/powerpc/kvm/book3s_64_mmu_radix.c 
b/arch/powerpc/kvm/book3s_64_mmu_radix.c
index 3248f78..5d4c087 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_radix.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_radix.c
@@ -795,7 +795,7 @@ int kvmppc_book3s_instantiate_page(struct kvm_vcpu *vcpu,
 * is that the page is writable.
 */
hva = gfn_to_hva_memslot(memslot, gfn);
-   if (!kvm_ro && __get_user_pages_fast(hva, 1, 1, ) == 1) {
+   if (!kvm_ro && get_user_page_fast_only(hva, FOLL_WRITE, )) {
upgrade_write = true;
} else {
unsigned long pfn;
diff --git a/arch/powerpc/perf/callchain_64.c b/arch/powerpc/perf/callchain_64.c
index 1bff896d..814d1c2 100644
--- a/arch/powerpc/perf/callchain_64.c
+++ b/arch/powerpc/perf/callchain_64.c
@@ -29,11 +29,9 @@ int read_user_stack_slow(void __user *ptr, void *buf, int nb)
unsigned long addr = (unsigned long) ptr;
unsigned long offset;
struct page *page;
-   int nrpages;
void *kaddr;
 
-   nrpages = __get_user_pages_fast(addr, 1, 1, );
-   if (nrpages == 1) {
+   if (get_user_page_fast_only(addr, FOLL_WRITE, )) {
kaddr = page_address(page);
 
/* align address to page boundary */
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 93d93bd..8d4597f 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1817,10 +1817,16 @@ extern int mprotect_fixup(struct vm_area_struct *vma,
 /*
  * doesn't attempt to fault and will return short.
  */
-int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
- struct page **pages);
+int get_user_pages_fast_only(unsigned long start, int nr_pages,
+   unsigned int gup_flags, struct page **pages);
 int pin_user_pages_fast_only(unsigned long start, int nr_pages,
 unsigned int gup_flags, struct page **pages);
+
+static inline bool get_user_page_fast_only(unsigned long addr,
+   unsigned int gup_flags, struct page **pagep)
+{
+   return get_user_pages_fast_only(addr, 1, gup_flags, pagep) == 1;
+}
 /*
  * per-process(per-mm_struct) statistics.
  */
diff --git a/kernel/events/core.c b/kernel/events/core.c
index c94eb27..856d98c 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -6934,12 +6934,12 @@ static u64 perf_virt_to_phys(u64 virt)
 * Walking the pages tables for user address.
 * Interrupts are disabled, so it prevents any tear down
 * of the page tables.
-* Try IRQ-safe __get_user_pages_fast first.
+* Try IRQ-safe get_user_page_fast_only first.
 * If failed, leave phys_addr as 0.
 */
if (current->mm != NULL) {
pagefault_disable();
-   if (__get_user_pages_fast(virt, 1, 0, ) == 1)
+   if (get_user_page_fast_only(virt, 0, ))
phys_addr = 

Re: [PATCH v2] Makefile: support compressed debug info

2020-05-23 Thread Masahiro Yamada
On Fri, May 22, 2020 at 6:57 AM 'Nick Desaulniers' via Clang Built
Linux  wrote:
>
> On Wed, May 20, 2020 at 7:48 PM Masahiro Yamada  wrote:
> >
> > > Suggested-by: Fangrui Song 
> >
> >
> > Suggested-by -> Reviewed-by
> >
> > https://patchwork.kernel.org/patch/11524939/#23349551
>
> Yes, my mistake.
>
> > > Suggested-by: Nick Clifton 
> >
> >
> > I do not know where this tag came from.
> >
> > Nick Clifton taught us the version rule of binutils,but did not state
> > anything about this patch itself.
> >
> > https://patchwork.kernel.org/patch/11524939/#23355175
> >
> >
> > > Suggested-by: Sedat Dilek 
> >
> > I do not see the source of this tag, either...
>
> Not all contributions to open source need to be in the form of
> patches.  Both Sedat and Nick gave suggestions which ultimately
> informed the contents of this patch.  They should be rewarded for
> their efforts, and incentivized to help improve the code base further.
> I think suggested by tags are a good way to do that; but if it's
> against a written convention or if you still disagree, it's not the
> end of the world to me, and you may drop those tags from the v3.


Documentation/process/submitting-patches.rst
gives the guideline.


"A Suggested-by: tag indicates that the patch idea is suggested by the person
named and ensures credit to the person for the idea. Please note that this
tag should not be added without the reporter's permission, especially if the
idea was not posted in a public forum. That said, if we diligently credit our
idea reporters, they will, hopefully, be inspired to help us again in the
future."


I think this tag should be given to people who
gave the main idea to come up with
the main part of the patch.


Is that David Blaikie who suggested to
compress the debug info ?
If so, definitely he deserves to have Suggested-by tag.

For the others, I do not think Suggested-by is a good fit.

I appreciate their contribution to improve this patch.
So, maybe you can give credit in other form, for example,
mention it in the commit log explicitly?

Nick Clifton helped us to provide the minimal binutils version.
Sedat Dilet found an increase in size of debug .deb package.


Thanks.

>
> > > --- a/lib/Kconfig.debug
> > > +++ b/lib/Kconfig.debug
> > > @@ -225,6 +225,21 @@ config DEBUG_INFO_REDUCED
> > >   DEBUG_INFO build and compile times are reduced too.
> > >   Only works with newer gcc versions.
> > >
> > > +config DEBUG_INFO_COMPRESSED
> > > +   bool "Compressed debugging information"
> > > +   depends on DEBUG_INFO
> > > +   depends on $(cc-option,-gz=zlib)
> > > +   depends on $(as-option,-Wa,--compress-debug-sections=zlib)
> >
> > This does not work. (always false)
>
> Technically, always true. `-Wa` disables all warnings from the
> assembler.  Also, I did test this via `make menuconfig`.
>
> > You cannot enable this option.
> >
> > The comma between -Wa and --compress-debug-sections=zlib
> > is eaten by Kconfig parser because commas are delimiters
> > of function parameters.
> >
> >
> > Please write like this.
> >
> > depends on $(as-option,-Wa$(comma)--compress-debug-sections=zlib)
>
> You're right, I knew this bug forgot. Will fix in v3.
>
> > > +   depends on $(ld-option,--compress-debug-sections=zlib)
> > > +   help
> > > + Compress the debug information using zlib.  Requires GCC 5.0+ 
> > > or Clang
> > > + 5.0+, binutils 2.26+, and zlib.
> > > +
> > > + Users of dpkg-deb via scripts/package/builddeb may
> > > + wish to set the $KDEB_COMPRESS env var to "none" to avoid 
> > > recompressing
> > > + the debug info again with a different compression scheme, which 
> > > can
> > > + result in larger binaries.
> >
> > No. This is not correct.
> >
> > CONFIG_DEBUG_INFO_COMPRESSED compresses the only debug info part.
> > The other parts still get by benefit from the default KDEB_COMPRESS=xz.
> >
> >
> > The numbers are here:
> >
> >
> > CONFIG_DEBUG_INFO_COMPRESSED=y
> > -rw-r--r-- 1 masahiro masahiro 209077584 May 21 11:19
> > linux-image-5.7.0-rc5+-dbg_5.7.0-rc5+-26_amd64.deb
> >
> >
> > CONFIG_DEBUG_INFO_COMPRESSED=y and KDEB_COMPRESS=none
> > -rw-r--r-- 1 masahiro masahiro 643051712 May 21 11:22
> > linux-image-5.7.0-rc5+-dbg_5.7.0-rc5+-27_amd64.deb
> >
> >
> > CONFIG_DEBUG_INFO_COMPRESSED=n
> > -rw-r--r-- 1 masahiro masahiro 112200308 May 21 11:40
> > linux-image-5.7.0-rc5+-dbg_5.7.0-rc5+-30_amd64.deb
> >
> >
> >
> >
> > For the deb package size perspective,
> > it is better to keep KDEB_COMPRESS as default.
> >
> > The main motivation for changing KDEB_COMPRESS
> > is the build speed.  (see commit 1a7f0a34ea7d05)
> >
> >
> >
> >
> > CONFIG_DEBUG_INFO_COMPRESSED has a downside
> > for the debug deb package, but we need to accept it.
>
> Ah, I see. Thank you for those measurements.  I'll send a v3 with
> fixed up help text, but ultimately, I don't really care what it says
> here.  Please feel empowered to reword it should you choose to 

[PATCH V2] media: s3c-camif: fix missing disable in tegra_adma_probe().

2020-05-23 Thread wu000273
From: Qiushi Wu 

"pm_runtime_enable()" was not handled by "pm_runtime_disable()"
after a call of the function “pm_runtime_get_sync()” failed.
Thus move the jump target “err_pm” before calling function 
"calling pm_runtime_disable()".

Fixes: babde1c243b2 ("[media] V4L: Add driver for S3C24XX/S3C64XX SoC series 
camera interface")
Signed-off-by: Qiushi Wu 
---

V2: improving commit messages.

---
 drivers/media/platform/s3c-camif/camif-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/s3c-camif/camif-core.c 
b/drivers/media/platform/s3c-camif/camif-core.c
index c6fbcd7036d6..12ee49638f44 100644
--- a/drivers/media/platform/s3c-camif/camif-core.c
+++ b/drivers/media/platform/s3c-camif/camif-core.c
@@ -500,8 +500,8 @@ static int s3c_camif_probe(struct platform_device *pdev)
camif_unregister_media_entities(camif);
 err_alloc:
pm_runtime_put(dev);
-   pm_runtime_disable(dev);
 err_pm:
+   pm_runtime_disable(dev);
camif_clk_put(camif);
 err_clk:
s3c_camif_unregister_subdev(camif);
-- 
2.17.1



drivers/gpu/drm/i915/display/intel_color.c:1840 ilk_read_lut_8() error: potential null dereference 'blob'. (drm_property_create_blob returns null)

2020-05-23 Thread kbuild test robot
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
master
head:   caffb99b6929f41a69edbb5aef3a359bf45f3315
commit: 100882673ab83b55ea0e9ed3ad301125d36039a3 drm/i915: Split 
i9xx_read_lut_8() to gmch vs. ilk variants
date:   3 months ago
config: i386-allyesconfig (attached as .config)
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
reproduce (this is a W=1 build):
git checkout 100882673ab83b55ea0e9ed3ad301125d36039a3
# save the attached .config to linux build tree
make ARCH=i386 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot 

New smatch warnings:
drivers/gpu/drm/i915/display/intel_color.c:1840 ilk_read_lut_8() error: 
potential null dereference 'blob'.  (drm_property_create_blob returns null)

Old smatch warnings:
drivers/gpu/drm/i915/display/intel_color.c:1706 i9xx_read_lut_8() error: 
potential null dereference 'blob'.  (drm_property_create_blob returns null)
drivers/gpu/drm/i915/display/intel_color.c:1747 i965_read_lut_10p6() error: 
potential null dereference 'blob'.  (drm_property_create_blob returns null)
drivers/gpu/drm/i915/display/intel_color.c:1799 chv_read_cgm_lut() error: 
potential null dereference 'blob'.  (drm_property_create_blob returns null)
drivers/gpu/drm/i915/display/intel_color.c:1873 ilk_read_lut_10() error: 
potential null dereference 'blob'.  (drm_property_create_blob returns null)
drivers/gpu/drm/i915/display/intel_color.c:1920 glk_read_lut_10() error: 
potential null dereference 'blob'.  (drm_property_create_blob returns null)

vim +/blob +1840 drivers/gpu/drm/i915/display/intel_color.c

  1823  
  1824  static struct drm_property_blob *
  1825  ilk_read_lut_8(const struct intel_crtc_state *crtc_state)
  1826  {
  1827  struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
  1828  struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  1829  enum pipe pipe = crtc->pipe;
  1830  struct drm_property_blob *blob;
  1831  struct drm_color_lut *blob_data;
  1832  u32 i, val;
  1833  
  1834  blob = drm_property_create_blob(_priv->drm,
  1835  sizeof(struct drm_color_lut) * 
LEGACY_LUT_LENGTH,
  1836  NULL);
  1837  if (IS_ERR(blob))
  1838  return NULL;
  1839  
> 1840  blob_data = blob->data;
  1841  
  1842  for (i = 0; i < LEGACY_LUT_LENGTH; i++) {
  1843  val = intel_de_read(dev_priv, LGC_PALETTE(pipe, i));
  1844  
  1845  blob_data[i].red = intel_color_lut_pack(REG_FIELD_GET(
  1846  
LGC_PALETTE_RED_MASK, val), 8);
  1847  blob_data[i].green = intel_color_lut_pack(REG_FIELD_GET(
  1848
LGC_PALETTE_GREEN_MASK, val), 8);
  1849  blob_data[i].blue = intel_color_lut_pack(REG_FIELD_GET(
  1850   
LGC_PALETTE_BLUE_MASK, val), 8);
  1851  }
  1852  
  1853  return blob;
  1854  }
  1855  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org


.config.gz
Description: application/gzip


[PATCH] media: exynos4-is: Fix runtime PM imbalance in isp_video_open

2020-05-23 Thread Dinghao Liu
pm_runtime_get_sync() increments the runtime PM usage counter even
when it returns an error code. Thus a pairing decrement is needed on
the error handling path to keep the counter balanced.

Signed-off-by: Dinghao Liu 
---
 drivers/media/platform/exynos4-is/fimc-isp-video.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c 
b/drivers/media/platform/exynos4-is/fimc-isp-video.c
index 15f443fa7208..612b9872afc8 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
+++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
@@ -293,6 +293,7 @@ static int isp_video_open(struct file *file)
if (!ret)
goto unlock;
 rel_fh:
+   pm_runtime_put_noidle(>pdev->dev);
v4l2_fh_release(file);
 unlock:
mutex_unlock(>video_lock);
-- 
2.17.1



next-20200522 - build fail in fs/binfmt_elf_fdpic.c

2020-05-23 Thread Valdis Klētnieks
Eric:  looks like you missed one?

commit b8a61c9e7b4a0fec493d191429e9653d66a79ccc
Author: Eric W. Biederman 
Date:   Thu May 14 15:17:40 2020 -0500

exec: Generic execfd support

  CHECK   fs/binfmt_elf_fdpic.c
fs/binfmt_elf_fdpic.c:591:34: error: undefined identifier 'BINPRM_FLAGS_EXECFD'
  CC  fs/binfmt_elf_fdpic.o
fs/binfmt_elf_fdpic.c: In function 'create_elf_fdpic_tables':
fs/binfmt_elf_fdpic.c:591:27: error: 'BINPRM_FLAGS_EXECFD' undeclared (first 
use in this function); did you mean 'VM_DATA_FLAGS_EXEC'?
  if (bprm->interp_flags & BINPRM_FLAGS_EXECFD)
   ^~~
   VM_DATA_FLAGS_EXEC
fs/binfmt_elf_fdpic.c:591:27: note: each undeclared identifier is reported only 
once for each function it appears in
make[1]: *** [scripts/Makefile.build:273: fs/binfmt_elf_fdpic.o] Error 1
23:14:07 0 [/usr/src/linux-next]2



pgpWk3LL93PKY.pgp
Description: PGP signature


RE: [PATCH V3] thermal: imx: Add missing of_node_put()

2020-05-23 Thread Anson Huang
Gentle ping...


> Subject: [PATCH V3] thermal: imx: Add missing of_node_put()
> 
> After finishing using cpu node got from of_get_cpu_node(), of_node_put()
> needs to be called, the cpufreq policy also needs to be put unconditionally.
> 
> Signed-off-by: Anson Huang 
> ---
> Changes since V2:
>   - call cpufreq_cpu_put() unconditionally after cooling register done.
> ---
>  drivers/thermal/imx_thermal.c | 13 ++---
>  1 file changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c
> index e761c9b..8764cb5 100644
> --- a/drivers/thermal/imx_thermal.c
> +++ b/drivers/thermal/imx_thermal.c
> @@ -649,7 +649,7 @@ MODULE_DEVICE_TABLE(of, of_imx_thermal_match);
> static int imx_thermal_register_legacy_cooling(struct imx_thermal_data *data)
> {
>   struct device_node *np;
> - int ret;
> + int ret = 0;
> 
>   data->policy = cpufreq_cpu_get(0);
>   if (!data->policy) {
> @@ -661,20 +661,19 @@ static int
> imx_thermal_register_legacy_cooling(struct imx_thermal_data *data)
> 
>   if (!np || !of_find_property(np, "#cooling-cells", NULL)) {
>   data->cdev = cpufreq_cooling_register(data->policy);
> - if (IS_ERR(data->cdev)) {
> + if (IS_ERR(data->cdev))
>   ret = PTR_ERR(data->cdev);
> - cpufreq_cpu_put(data->policy);
> - return ret;
> - }
>   }
> 
> - return 0;
> + cpufreq_cpu_put(data->policy);
> + of_node_put(np);
> +
> + return ret;
>  }
> 
>  static void imx_thermal_unregister_legacy_cooling(struct imx_thermal_data
> *data)  {
>   cpufreq_cooling_unregister(data->cdev);
> - cpufreq_cpu_put(data->policy);
>  }
> 
>  #else
> --
> 2.7.4



Re: [RFC PATCH 2/2] drm: xlnx: driver for Xilinx DSI TX Subsystem

2020-05-23 Thread Laurent Pinchart
Hi GVRao,

Thank you for the patch.

On Mon, May 04, 2020 at 11:43:48AM -0700, Hyun Kwon wrote:
> On Mon, 2020-04-20 at 14:20:56 -0700, Venkateshwar Rao Gannavarapu wrote:
> > The Xilinx MIPI DSI Tx Subsystem soft IP is used to display video
> > data from AXI-4 stream interface.
> > 
> > It supports upto 4 lanes, optional register interface for the DPHY,
> 
> I don't see the register interface for dphy support.

I think the D-PHY should be supported through a PHY driver, as it seems
to be shared between different subsystems.

> > multiple RGB color formats, command mode and video mode.
> > This is a MIPI-DSI host driver and provides DSI bus for panels.
> > This driver also helps to communicate with its panel using panel
> > framework.
> > 
> > Signed-off-by: Venkateshwar Rao Gannavarapu 
> > 
> > ---
> >  drivers/gpu/drm/xlnx/Kconfig|  11 +
> >  drivers/gpu/drm/xlnx/Makefile   |   2 +
> >  drivers/gpu/drm/xlnx/xlnx_dsi.c | 755 
> > 

Daniel Vetter has recently expressed his opiion that bridge drivers
should go to drivers/gpu/drm/bridge/. It would then be
drivers/gpu/drm/bridge/xlnx/. I don't have a strong opinion myself.

> >  3 files changed, 768 insertions(+)
> >  create mode 100644 drivers/gpu/drm/xlnx/xlnx_dsi.c
> > 
> > diff --git a/drivers/gpu/drm/xlnx/Kconfig b/drivers/gpu/drm/xlnx/Kconfig
> > index aa6cd88..73873cf 100644
> > --- a/drivers/gpu/drm/xlnx/Kconfig
> > +++ b/drivers/gpu/drm/xlnx/Kconfig
> > @@ -11,3 +11,14 @@ 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_XLNX_DSI
> > +tristate "Xilinx DRM DSI Subsystem Driver"
> > +select DRM_MIPI_DSI
> > +select DRM_PANEL
> > +select DRM_PANEL_SIMPLE
> > +help
> > + This enables support for Xilinx MIPI-DSI.
> 
> This sentence is not needed with below. Could you please rephrase the whole?
> 
> > + This is a DRM/KMS driver for Xilinx programmable DSI controller.
> > + Choose this option if you have a Xilinx MIPI DSI-TX controller
> > + subsytem.
> 
> These seem incorrectly indented.
> 
> > diff --git a/drivers/gpu/drm/xlnx/Makefile b/drivers/gpu/drm/xlnx/Makefile
> > index 2b844c6..b7ee6ef 100644
> > --- a/drivers/gpu/drm/xlnx/Makefile
> > +++ b/drivers/gpu/drm/xlnx/Makefile
> > @@ -1,2 +1,4 @@
> >  zynqmp-dpsub-objs += zynqmp_disp.o zynqmp_dpsub.o zynqmp_dp.o
> >  obj-$(CONFIG_DRM_ZYNQMP_DPSUB) += zynqmp-dpsub.o
> > +
> > +obj-$(CONFIG_DRM_XLNX_DSI) += xlnx_dsi.o
> > diff --git a/drivers/gpu/drm/xlnx/xlnx_dsi.c 
> > b/drivers/gpu/drm/xlnx/xlnx_dsi.c
> > new file mode 100644
> > index 000..b8cae59
> > --- /dev/null
> > +++ b/drivers/gpu/drm/xlnx/xlnx_dsi.c
> > @@ -0,0 +1,755 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Xilinx FPGA MIPI DSI Tx Controller driver
> > + *
> > + * Copyright (C) 2017 - 2019 Xilinx, Inc.
> > + *
> > + * Authors:
> > + * - Saurabh Sengar 
> > + * - Venkateshwar Rao Gannavarapu 
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include 
> > +#include 
> > +
> > +/* DSI Tx IP registers */
> > +#define XDSI_CCR   0x00
> > +#define XDSI_CCR_COREENB   BIT(0)
> > +#define XDSI_CCR_SOFTRST   BIT(1)
> > +#define XDSI_CCR_CRREADY   BIT(2)
> > +#define XDSI_CCR_CMDMODE   BIT(3)
> > +#define XDSI_CCR_DFIFORST  BIT(4)
> > +#define XDSI_CCR_CMDFIFORSTBIT(5)
> > +#define XDSI_PCR   0x04
> > +#define XDSI_PCR_VIDEOMODE(x)  (((x) & 0x3) << 3)
> > +#define XDSI_PCR_VIDEOMODE_MASK(0x3 << 3)
> > +#define XDSI_PCR_VIDEOMODE_SHIFT   3
> > +#define XDSI_PCR_BLLPTYPE(x)   ((x) << 5)
> > +#define XDSI_PCR_BLLPMODE(x)   ((x) << 6)
> > +#define XDSI_PCR_EOTPENABLE(x) ((x) << 13)
> > +#define XDSI_GIER  0x20
> > +#define XDSI_ISR   0x24
> > +#define XDSI_IER   0x28
> > +#define XDSI_STR   0x2C
> > +#define XDSI_STR_RDY_SHPKT BIT(6)
> > +#define XDSI_STR_RDY_LNGPKTBIT(7)
> > +#define XDSI_STR_DFIFO_FULLBIT(8)
> > +#define XDSI_STR_DFIFO_EMPTY   BIT(9)
> > +#define XDSI_STR_WAITFR_DATA   BIT(10)
> > +#define XDSI_STR_CMD_EXE_PGS   BIT(11)
> > +#define XDSI_STR_CCMD_PROC BIT(12)
> > +#define XDSI_STR_LPKT_MASK (0x5 << 7)
> > +#define XDSI_CMD   0x30
> > +#define XDSI_CMD_QUEUE_PACKET(x)   ((x) & GENMASK(23, 0))
> > +#define XDSI_DFR   0x34
> > +#define XDSI_TIME1 0x50
> > +#define 

Re: [RFC PATCH 1/2] dt-bindings: display: xlnx: Add Xilinx DSI TX subsystem bindings

2020-05-23 Thread Laurent Pinchart
Hi GVRao,

On Sat, Apr 25, 2020 at 10:29:19PM +0200, Sam Ravnborg wrote:
> On Tue, Apr 21, 2020 at 02:50:55AM +0530, Venkateshwar Rao Gannavarapu wrote:
> > This add a dt binding for Xilinx DSI TX subsystem.
> > 
> > The Xilinx MIPI DSI (Display serial interface) Transmitter Subsystem
> > implements the Mobile Industry Processor Interface (MIPI) based display
> > interface. It supports the interface with the programmable logic (FPGA).
> > 
> > Signed-off-by: Venkateshwar Rao Gannavarapu 
> > 
> > ---
> >  .../devicetree/bindings/display/xlnx/xlnx,dsi.txt  | 68 
> > ++
> 
> Sorry, but new bindings in DT Schema format (.yaml) please.
> We are working on migrating all bindings to DT Schema and do not want
> to add new bindings in the old format.
> 
> >  1 file changed, 68 insertions(+)
> >  create mode 100644 
> > Documentation/devicetree/bindings/display/xlnx/xlnx,dsi.txt
> > 
> > diff --git a/Documentation/devicetree/bindings/display/xlnx/xlnx,dsi.txt 
> > b/Documentation/devicetree/bindings/display/xlnx/xlnx,dsi.txt
> > new file mode 100644
> > index 000..ef69729
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/display/xlnx/xlnx,dsi.txt
> > @@ -0,0 +1,68 @@
> > +Device-Tree bindings for Xilinx MIPI DSI Tx IP core
> > +
> > +The IP core supports transmission of video data in MIPI DSI protocol.
> > +
> > +Required properties:
> > + - compatible: Should be "xlnx-dsi".

The compatible value should start with the vendor name, followed by a
comma, and then the device identifier. This should thus be "xlnx,dsi".
However, I think calling it just "dsi" isn't specific enough, as it
could also be a DSI RX. "xlnx,dsi-tx" would be a better value. As the IP
core is versioned, I would make it "xlnx,dsi-tx-v2.0" (assuming that's
the version you want to support). If you want to support v1.0 as well,
you can add "xlnx,dsi-tx-v1.0" as an option.

> > + - reg: physical base address and length of the registers set for the 
> > device.

Does this cover both the DSI TX registers and the D-PHY registers, or
only the DSI TX registers ? It should be specified.

> > + - xlnx,dsi-num-lanes: Possible number of DSI lanes for the Tx controller.
> > +   The values should be 1, 2, 3 or 4. Based on xlnx,dsi-num-lanes and
> > +   line rate for the MIPI D-PHY core in Mbps, the AXI4-stream received by
> > +   Xilinx MIPI DSI Tx IP core adds markers as per DSI protocol and the 
> > packet
> > +   thus framed is convered to serial data by MIPI D-PHY core. Please refer
> > +   Xilinx pg238 for more details. This value should be equal to the number
> > +   of lanes supported by the connected DSI panel. Panel has to support this
> > +   value or has to be programmed to the same value that DSI Tx controller 
> > is
> > +   configured to.

The protocol configuration register has an Active Lanes field that
reports the number of lanes. Could we read the information from the
register, and drop this property ?

> > + - xlnx,dsi-datatype: Color format. The value should be one of 
> > "MIPI_DSI_FMT_RGB888",
> > +  "MIPI_DSI_FMT_RGB666", "MIPI_DSI_FMT_RGB666_PACKED" or 
> > "MIPI_DSI_FMT_RGB565".

The example below (and the driver) use "xlnx,dsi-data-type".

Same comment as above, should this be read from the Pixel Format field
instead of being specified in DT ?

> > + - #address-cells, #size-cells: should be set respectively to <1> and <0>
> > +   according to DSI host bindings (see MIPI DSI bindings [1])
> > + - clock-names: Must contain "s_axis_aclk" and "dphy_clk_200M" in same 
> > order as
> > +   clocks listed in clocks property.
> > + - clocks: List of phandles to Video and 200Mhz DPHY clocks.
> > + - port: Logical block can be used / connected independently with
> > +   external device. In the display controller port nodes, topology
> > +   for entire pipeline should be described using the DT bindings defined in
> > +   Documentation/devicetree/bindings/graph.txt.

I think you should put the "port" node in a "ports" node, as there's
also a panel subnode. Otherwise both the port and panel will compete for
#address-cells and #size-cells. It happens that both need those
properties to be 1 and 0 respectively, but isolating the two would be
cleaner.

There should also be a port for the AXI4-Stream interface. The common
practice is to number the input port@0 and the output port@1.

> > + - simple_panel: The subnode for connected panel. This represents the

This should be panel, not simple_panel.

> > +   DSI peripheral connected to the DSI host node. Please refer to
> > +   Documentation/devicetree/bindings/display/mipi-dsi-bus.txt. The
> > +   simple-panel driver has auo,b101uan01 panel timing parameters added 
> > along
> > +   with other existing panels. DSI driver derive the required Tx IP 
> > controller
> > +   timing values from the panel timing parameters.

You can drop the last two sentences, DT bindings shouldn't mention
driver-specific implementations.

> Please always use either a port or a ports node.
> 

[PATCH] media: exynos4-is: Fix runtime PM imbalance in fimc_is_probe

2020-05-23 Thread Dinghao Liu
pm_runtime_get_sync() increments the runtime PM usage counter even
when it returns an error code. Thus a pairing decrement is needed on
the error handling path to keep the counter balanced. For all error
paths after pm_runtime_get_sync(), things are the same.

Signed-off-by: Dinghao Liu 
---
 drivers/media/platform/exynos4-is/fimc-is.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/platform/exynos4-is/fimc-is.c 
b/drivers/media/platform/exynos4-is/fimc-is.c
index 64148b7e0d98..a474014f0a0f 100644
--- a/drivers/media/platform/exynos4-is/fimc-is.c
+++ b/drivers/media/platform/exynos4-is/fimc-is.c
@@ -871,6 +871,7 @@ static int fimc_is_probe(struct platform_device *pdev)
 err_sd:
fimc_is_unregister_subdevs(is);
 err_pm:
+   pm_runtime_put_noidle(dev);
if (!pm_runtime_enabled(dev))
fimc_is_runtime_suspend(dev);
 err_irq:
-- 
2.17.1



Re: [PATCH 0/3] fs: reduce export usage of kerne_read*() calls

2020-05-23 Thread Mimi Zohar
On Fri, 2020-05-22 at 16:25 -0700, Scott Branden wrote:
> Hi Kees,
> 
> On 2020-05-22 4:04 p.m., Kees Cook wrote:
> > On Fri, May 22, 2020 at 03:24:32PM -0700, Scott Branden wrote:
> >> On 2020-05-18 5:37 a.m., Mimi Zohar wrote:
> >>> On Sun, 2020-05-17 at 23:22 -0700, Christoph Hellwig wrote:
>  On Fri, May 15, 2020 at 09:29:33PM +, Luis Chamberlain wrote:
> > On Wed, May 13, 2020 at 11:17:36AM -0700, Christoph Hellwig wrote:
> >> Can you also move kernel_read_* out of fs.h?  That header gets pulled
> >> in just about everywhere and doesn't really need function not related
> >> to the general fs interface.
> > Sure, where should I dump these?
>  Maybe a new linux/kernel_read_file.h?  Bonus points for a small top
>  of the file comment explaining the point of the interface, which I
>  still don't get :)
> >>> Instead of rolling your own method of having the kernel read a file,
> >>> which requires call specific security hooks, this interface provides a
> >>> single generic set of pre and post security hooks.  The
> >>> kernel_read_file_id enumeration permits the security hook to
> >>> differentiate between callers.
> >>>
> >>> To comply with secure and trusted boot concepts, a file cannot be
> >>> accessible to the caller until after it has been measured and/or the
> >>> integrity (hash/signature) appraised.
> >>>
> >>> In some cases, the file was previously read twice, first to measure
> >>> and/or appraise the file and then read again into a buffer for
> >>> use.  This interface reads the file into a buffer once, calls the
> >>> generic post security hook, before providing the buffer to the caller.
> >>>    (Note using firmware pre-allocated memory might be an issue.)
> >>>
> >>> Partial reading firmware will result in needing to pre-read the entire
> >>> file, most likely on the security pre hook.
> >> The entire file may be very large and not fit into a buffer.
> >> Hence one of the reasons for a partial read of the file.
> >> For security purposes, you need to change your code to limit the amount
> >> of data it reads into a buffer at one time to not consume or run out of 
> >> much
> >> memory.
> > Hm? That's not how whole-file hashing works. :)
> 
> >
> > These hooks need to finish their hashing and policy checking before they
> > can allow the rest of the code to move forward. (That's why it's a
> > security hook.) If kernel memory utilization is the primary concern,
> > then sure, things could be rearranged to do partial read and update the
> > hash incrementally, but the entire file still needs to be locked,
> > entirely hashed by hook, then read by the caller, then unlocked and
> > released.

Exactly.

> >
> > So, if you want to have partial file reads work, you'll need to
> > rearchitect the way this works to avoid regressing the security coverage
> > of these operations.
> I am not familiar with how the security handling code works at all.
> Is the same security check run on files opened from user space?
> A file could be huge.
> 
> If it assumes there is there is enough memory available to read the 
> entire file into kernel space then the improvement below can be left as
> a memory optimization to be done in an independent (or future) patch series.

There are two security hooks - security_kernel_read_file(),
security_kernel_post_read_file - in kernel_read_file().  The first
hook is called before the file is read into a buffer, while the second
hook is called afterwards.

For partial reads, measuring the firmware and verifying the firmware's
signature will need to be done on the security_kernel_read_file()
hook.

> 
> > So, probably, the code will look something like:
> >
> >
> > file = kernel_open_file_for_reading(...)
> > file = open...
> > disallow_writes(file);
> > while (processed < size-of-file) {
> > buf = read(file, size...)
> > security_file_read_partial(buf)
> > }
> > ret = security_file_read_finished(file);
> > if (ret < 0) {
> > allow_writes(file);
> > return PTR_ERR(ret);
> > }
> > return file;
> >
> > while (processed < size-of-file) {
> > buf = read(file, size...)
> > firmware_send_partial(buf);
> > }
> >
> > kernel_close_file_for_reading(file)
> > allow_writes(file);

Right, the ima_file_mmap(), ima_bprm_check(), and ima_file_check()
hooks call process_measurement() to do this.  ima_post_read_file()
passes a buffer to process_measurement() instead.

Scott, the change should be straight forward.  The additional patch
needs to:
- define a new kernel_read_file_id enumeration, like
FIRMWARE_PARTIAL_READ.
- Currently ima_read_file() has a comment about pre-allocated firmware
buffers.  Update ima_read_file() to call process_measurement() for the
new enumeration FIRMWARE_PARTIAL_READ and update ima_post_read_file()
to return immediately.

The built-in IMA measurement policy contains a rule to measure
firmware.  The policy can be specified on the boot 

[PATCH] iio: magnetometer: ak8974: Fix runtime PM imbalance on error

2020-05-23 Thread Dinghao Liu
When devm_regmap_init_i2c() returns an error code, a pairing
runtime PM usage counter decrement is needed to keep the
counter balanced. For error paths after ak8974_set_power(),
ak8974_detect() and ak8974_reset(), things are the same.

However, When iio_triggered_buffer_setup() returns an error
code, we don't need such a decrement because there is already
one before this call. Things are the same for other error paths
after it.

Signed-off-by: Dinghao Liu 
---
 drivers/iio/magnetometer/ak8974.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/magnetometer/ak8974.c 
b/drivers/iio/magnetometer/ak8974.c
index d32996702110..c1bdb304eb9e 100644
--- a/drivers/iio/magnetometer/ak8974.c
+++ b/drivers/iio/magnetometer/ak8974.c
@@ -764,18 +764,24 @@ static int ak8974_probe(struct i2c_client *i2c,
ak8974->map = devm_regmap_init_i2c(i2c, _regmap_config);
if (IS_ERR(ak8974->map)) {
dev_err(>dev, "failed to allocate register map\n");
+   pm_runtime_put_noidle(>dev);
+   pm_runtime_disable(>dev);
return PTR_ERR(ak8974->map);
}
 
ret = ak8974_set_power(ak8974, AK8974_PWR_ON);
if (ret) {
dev_err(>dev, "could not power on\n");
+   pm_runtime_put_noidle(>dev);
+   pm_runtime_disable(>dev);
goto power_off;
}
 
ret = ak8974_detect(ak8974);
if (ret) {
dev_err(>dev, "neither AK8974 nor AMI30x found\n");
+   pm_runtime_put_noidle(>dev);
+   pm_runtime_disable(>dev);
goto power_off;
}
 
@@ -786,6 +792,8 @@ static int ak8974_probe(struct i2c_client *i2c,
ret = ak8974_reset(ak8974);
if (ret) {
dev_err(>dev, "AK8974 reset failed\n");
+   pm_runtime_put_noidle(>dev);
+   pm_runtime_disable(>dev);
goto power_off;
}
 
@@ -851,7 +859,6 @@ static int ak8974_probe(struct i2c_client *i2c,
 cleanup_buffer:
iio_triggered_buffer_cleanup(indio_dev);
 disable_pm:
-   pm_runtime_put_noidle(>dev);
pm_runtime_disable(>dev);
ak8974_set_power(ak8974, AK8974_PWR_OFF);
 power_off:
-- 
2.17.1



[PATCH 4/6] arm64: dts: qcom: sm8250: Add USB and PHY device nodes

2020-05-23 Thread Jonathan Marek
Add device nodes for the USB3 controller, QMP SS PHY and
SNPS HS PHY.

Signed-off-by: Jonathan Marek 
---
 arch/arm64/boot/dts/qcom/sm8250.dtsi | 180 +++
 1 file changed, 180 insertions(+)

diff --git a/arch/arm64/boot/dts/qcom/sm8250.dtsi 
b/arch/arm64/boot/dts/qcom/sm8250.dtsi
index 43c5e48c15e2..3bdce658c08a 100644
--- a/arch/arm64/boot/dts/qcom/sm8250.dtsi
+++ b/arch/arm64/boot/dts/qcom/sm8250.dtsi
@@ -387,6 +387,186 @@ tcsr_mutex: hwlock@1f4 {
#hwlock-cells = <1>;
};
 
+   usb_1_hsphy: phy@88e3000 {
+   compatible = "qcom,sm8250-usb-hs-phy",
+"qcom,usb-snps-hs-7nm-phy";
+   reg = <0 0x088e3000 0 0x400>;
+   status = "disabled";
+   #phy-cells = <0>;
+
+   clocks = < RPMH_CXO_CLK>;
+   clock-names = "ref";
+
+   resets = < GCC_QUSB2PHY_PRIM_BCR>;
+   };
+
+   usb_2_hsphy: phy@88e4000 {
+   compatible = "qcom,sm8250-usb-hs-phy",
+"qcom,usb-snps-hs-7nm-phy";
+   reg = <0 0x088e4000 0 0x400>;
+   status = "disabled";
+   #phy-cells = <0>;
+
+   clocks = < RPMH_CXO_CLK>;
+   clock-names = "ref";
+
+   resets = < GCC_QUSB2PHY_SEC_BCR>;
+   };
+
+   usb_1_qmpphy: phy@88e9000 {
+   compatible = "qcom,sm8250-qmp-usb3-phy";
+   reg = <0 0x088e9000 0 0x200>,
+ <0 0x088e8000 0 0x20>;
+   reg-names = "reg-base", "dp_com";
+   status = "disabled";
+   #clock-cells = <1>;
+   #address-cells = <2>;
+   #size-cells = <2>;
+   ranges;
+
+   clocks = < GCC_USB3_PRIM_PHY_AUX_CLK>,
+< RPMH_CXO_CLK>,
+< GCC_USB3_PRIM_PHY_COM_AUX_CLK>;
+   clock-names = "aux", "ref_clk_src", "com_aux";
+
+   resets = < GCC_USB3_DP_PHY_PRIM_BCR>,
+< GCC_USB3_PHY_PRIM_BCR>;
+   reset-names = "phy", "common";
+
+   usb_1_ssphy: lanes@88e9200 {
+   reg = <0 0x088e9200 0 0x200>,
+ <0 0x088e9400 0 0x200>,
+ <0 0x088e9c00 0 0x400>,
+ <0 0x088e9600 0 0x200>,
+ <0 0x088e9800 0 0x200>,
+ <0 0x088e9a00 0 0x100>;
+   #phy-cells = <0>;
+   clocks = < GCC_USB3_PRIM_PHY_PIPE_CLK>;
+   clock-names = "pipe0";
+   clock-output-names = "usb3_phy_pipe_clk_src";
+   };
+   };
+
+   usb_2_qmpphy: phy@88eb000 {
+   compatible = "qcom,sm8250-qmp-usb3-uni-phy";
+   reg = <0 0x088eb000 0 0x200>;
+   status = "disabled";
+   #clock-cells = <1>;
+   #address-cells = <2>;
+   #size-cells = <2>;
+   ranges;
+
+   clocks = < GCC_USB3_SEC_PHY_AUX_CLK>,
+< RPMH_CXO_CLK>,
+< GCC_USB3_SEC_CLKREF_EN>,
+< GCC_USB3_SEC_PHY_COM_AUX_CLK>;
+   clock-names = "aux", "ref_clk_src", "ref", "com_aux";
+
+   resets = < GCC_USB3PHY_PHY_SEC_BCR>,
+< GCC_USB3_PHY_SEC_BCR>;
+   reset-names = "phy", "common";
+
+   usb_2_ssphy: lane@88eb200 {
+   reg = <0 0x088eb200 0 0x200>,
+ <0 0x088eb400 0 0x200>,
+ <0 0x088eb800 0 0x800>;
+   #phy-cells = <0>;
+   clocks = < GCC_USB3_SEC_PHY_PIPE_CLK>;
+   clock-names = "pipe0";
+   clock-output-names = 
"usb3_uni_phy_pipe_clk_src";
+   };
+   };
+
+   usb_1: usb@a6f8800 {
+   compatible = "qcom,sm8250-dwc3", "qcom,dwc3";
+   reg = <0 0x0a6f8800 0 0x400>;
+   status = "disabled";
+   #address-cells = <2>;
+   #size-cells = <2>;
+   ranges;
+   dma-ranges;
+
+   clocks = < 

[PATCH 2/6] arm64: dts: qcom: sm8250: add apps_smmu node

2020-05-23 Thread Jonathan Marek
Add the apps_smmu node for sm8250. Note that adding the iommus field for
UFS is required because initializing the iommu removes the bypass mapping
that created by the bootloader.

Signed-off-by: Jonathan Marek 
---
 arch/arm64/boot/dts/qcom/sm8250.dtsi | 107 +++
 1 file changed, 107 insertions(+)

diff --git a/arch/arm64/boot/dts/qcom/sm8250.dtsi 
b/arch/arm64/boot/dts/qcom/sm8250.dtsi
index 2f99c350c287..43c5e48c15e2 100644
--- a/arch/arm64/boot/dts/qcom/sm8250.dtsi
+++ b/arch/arm64/boot/dts/qcom/sm8250.dtsi
@@ -323,6 +323,8 @@ ufs_mem_hc: ufshc@1d84000 {
 
power-domains = < UFS_PHY_GDSC>;
 
+   iommus = <_smmu 0x0e0 0>, <_smmu 0x4e0 0>;
+
clock-names =
"core_clk",
"bus_aggr_clk",
@@ -428,6 +430,111 @@ tlmm: pinctrl@f10 {
wakeup-parent = <>;
};
 
+   apps_smmu: iommu@1500 {
+   compatible = "qcom,sdm845-smmu-500", "arm,mmu-500";
+   reg = <0 0x1500 0 0x10>;
+   #iommu-cells = <2>;
+   #global-interrupts = <2>;
+   interrupts =,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   ,
+   

[PATCH 0/6] arm64: dts: qcom: smmu/USB nodes and HDK855/HDK865 dts

2020-05-23 Thread Jonathan Marek
Add dts nodes for apps_smmu and USB for both sm8150 and sm8250.

Also add initial dts files for HDK855 and HDK865, based on mtp dts, with a
few changes. Notably, the HDK865 dts has regulator config changed a bit based
on downstream (I think sm8250-mtp.dts is wrong and copied too much from sm8150).

Jonathan Marek (6):
  arm64: dts: qcom: sm8150: add apps_smmu node
  arm64: dts: qcom: sm8250: add apps_smmu node
  arm64: dts: qcom: sm8150: Add secondary USB and PHY nodes
  arm64: dts: qcom: sm8250: Add USB and PHY device nodes
  arm64: dts: qcom: add sm8150 hdk dts
  arm64: dts: qcom: add sm8250 hdk dts

 arch/arm64/boot/dts/qcom/Makefile   |   2 +
 arch/arm64/boot/dts/qcom/sm8150-hdk.dts | 461 
 arch/arm64/boot/dts/qcom/sm8150.dtsi| 180 +
 arch/arm64/boot/dts/qcom/sm8250-hdk.dts | 454 +++
 arch/arm64/boot/dts/qcom/sm8250.dtsi| 287 +++
 5 files changed, 1384 insertions(+)
 create mode 100644 arch/arm64/boot/dts/qcom/sm8150-hdk.dts
 create mode 100644 arch/arm64/boot/dts/qcom/sm8250-hdk.dts

-- 
2.26.1



[PATCH 5/6] arm64: dts: qcom: add sm8150 hdk dts

2020-05-23 Thread Jonathan Marek
Add initial HDK855 dts, based on sm8150-mtp, with a few changes.

Signed-off-by: Jonathan Marek 
---
 arch/arm64/boot/dts/qcom/Makefile   |   1 +
 arch/arm64/boot/dts/qcom/sm8150-hdk.dts | 461 
 2 files changed, 462 insertions(+)
 create mode 100644 arch/arm64/boot/dts/qcom/sm8150-hdk.dts

diff --git a/arch/arm64/boot/dts/qcom/Makefile 
b/arch/arm64/boot/dts/qcom/Makefile
index cc103f7020fd..e5dbd8b63951 100644
--- a/arch/arm64/boot/dts/qcom/Makefile
+++ b/arch/arm64/boot/dts/qcom/Makefile
@@ -22,6 +22,7 @@ dtb-$(CONFIG_ARCH_QCOM)   += sdm845-cheza-r3.dtb
 dtb-$(CONFIG_ARCH_QCOM)+= sdm845-db845c.dtb
 dtb-$(CONFIG_ARCH_QCOM)+= sdm845-mtp.dtb
 dtb-$(CONFIG_ARCH_QCOM)+= sdm850-lenovo-yoga-c630.dtb
+dtb-$(CONFIG_ARCH_QCOM)+= sm8150-hdk.dtb
 dtb-$(CONFIG_ARCH_QCOM)+= sm8150-mtp.dtb
 dtb-$(CONFIG_ARCH_QCOM)+= sm8250-mtp.dtb
 dtb-$(CONFIG_ARCH_QCOM)+= qcs404-evb-1000.dtb
diff --git a/arch/arm64/boot/dts/qcom/sm8150-hdk.dts 
b/arch/arm64/boot/dts/qcom/sm8150-hdk.dts
new file mode 100644
index ..95b54fa8254a
--- /dev/null
+++ b/arch/arm64/boot/dts/qcom/sm8150-hdk.dts
@@ -0,0 +1,461 @@
+// SPDX-License-Identifier: BSD-3-Clause
+/*
+ * Copyright (c) 2020, The Linux Foundation. All rights reserved.
+ */
+
+/dts-v1/;
+
+#include 
+#include 
+#include "sm8150.dtsi"
+#include "pm8150.dtsi"
+#include "pm8150b.dtsi"
+#include "pm8150l.dtsi"
+
+/ {
+   model = "Qualcomm Technologies, Inc. SM8150 HDK";
+   compatible = "qcom,sm8150-hdk";
+
+   aliases {
+   serial0 = 
+   };
+
+   chosen {
+   stdout-path = "serial0:115200n8";
+   };
+
+   vph_pwr: vph-pwr-regulator {
+   compatible = "regulator-fixed";
+   regulator-name = "vph_pwr";
+   regulator-min-microvolt = <370>;
+   regulator-max-microvolt = <370>;
+   };
+
+   /*
+* Apparently RPMh does not provide support for PM8150 S4 because it
+* is always-on; model it as a fixed regulator.
+*/
+   vreg_s4a_1p8: pm8150-s4 {
+   compatible = "regulator-fixed";
+   regulator-name = "vreg_s4a_1p8";
+
+   regulator-min-microvolt = <180>;
+   regulator-max-microvolt = <180>;
+
+   regulator-always-on;
+   regulator-boot-on;
+
+   vin-supply = <_pwr>;
+   };
+
+   gpio_keys {
+   compatible = "gpio-keys";
+
+   vol-up {
+   label = "Volume Up";
+   linux,code = ;
+   gpios = <_gpios 6 GPIO_ACTIVE_LOW>;
+   };
+   };
+};
+
+_rsc {
+   pm8150-rpmh-regulators {
+   compatible = "qcom,pm8150-rpmh-regulators";
+   qcom,pmic-id = "a";
+
+   vdd-s1-supply = <_pwr>;
+   vdd-s2-supply = <_pwr>;
+   vdd-s3-supply = <_pwr>;
+   vdd-s4-supply = <_pwr>;
+   vdd-s5-supply = <_pwr>;
+   vdd-s6-supply = <_pwr>;
+   vdd-s7-supply = <_pwr>;
+   vdd-s8-supply = <_pwr>;
+   vdd-s9-supply = <_pwr>;
+   vdd-s10-supply = <_pwr>;
+
+   vdd-l1-l8-l11-supply = <_s6a_0p9>;
+   vdd-l2-l10-supply = <_bob>;
+   vdd-l3-l4-l5-l18-supply = <_s6a_0p9>;
+   vdd-l6-l9-supply = <_s8c_1p3>;
+   vdd-l7-l12-l14-l15-supply = <_s5a_2p0>;
+   vdd-l13-l16-l17-supply = <_bob>;
+
+   vreg_s5a_2p0: smps5 {
+   regulator-min-microvolt = <1904000>;
+   regulator-max-microvolt = <200>;
+   };
+
+   vreg_s6a_0p9: smps6 {
+   regulator-min-microvolt = <92>;
+   regulator-max-microvolt = <1128000>;
+   };
+
+   vdda_wcss_pll:
+   vreg_l1a_0p75: ldo1 {
+   regulator-min-microvolt = <752000>;
+   regulator-max-microvolt = <752000>;
+   regulator-initial-mode = ;
+   };
+
+   vdd_pdphy:
+   vdda_usb_hs_3p1:
+   vreg_l2a_3p1: ldo2 {
+   regulator-min-microvolt = <3072000>;
+   regulator-max-microvolt = <3072000>;
+   regulator-initial-mode = ;
+   };
+
+   vreg_l3a_0p8: ldo3 {
+   regulator-min-microvolt = <48>;
+   regulator-max-microvolt = <932000>;
+   regulator-initial-mode = ;
+   };
+
+   vdd_usb_hs_core:
+   vdda_csi_0_0p9:
+   vdda_csi_1_0p9:
+   vdda_csi_2_0p9:
+   vdda_csi_3_0p9:
+   vdda_dsi_0_0p9:
+   vdda_dsi_1_0p9:
+   vdda_dsi_0_pll_0p9:
+   

[PATCH 3/6] arm64: dts: qcom: sm8150: Add secondary USB and PHY nodes

2020-05-23 Thread Jonathan Marek
Add dts nodes for the secondary USB controller and related PHY nodes.

Signed-off-by: Jonathan Marek 
---
 arch/arm64/boot/dts/qcom/sm8150.dtsi | 89 
 1 file changed, 89 insertions(+)

diff --git a/arch/arm64/boot/dts/qcom/sm8150.dtsi 
b/arch/arm64/boot/dts/qcom/sm8150.dtsi
index acb839427b12..903514fc299f 100644
--- a/arch/arm64/boot/dts/qcom/sm8150.dtsi
+++ b/arch/arm64/boot/dts/qcom/sm8150.dtsi
@@ -636,6 +636,19 @@ usb_1_hsphy: phy@88e2000 {
resets = < GCC_QUSB2PHY_PRIM_BCR>;
};
 
+   usb_2_hsphy: phy@88e3000 {
+   compatible = "qcom,sm8150-usb-hs-phy",
+"qcom,usb-snps-hs-7nm-phy";
+   reg = <0 0x088e3000 0 0x400>;
+   status = "disabled";
+   #phy-cells = <0>;
+
+   clocks = < RPMH_CXO_CLK>;
+   clock-names = "ref";
+
+   resets = < GCC_QUSB2PHY_SEC_BCR>;
+   };
+
usb_1_qmpphy: phy@88e9000 {
compatible = "qcom,sm8150-qmp-usb3-phy";
reg = <0 0x088e9000 0 0x18c>,
@@ -671,6 +684,37 @@ usb_1_ssphy: lanes@88e9200 {
};
};
 
+   usb_2_qmpphy: phy@88eb000 {
+   compatible = "qcom,sm8150-qmp-usb3-uni-phy";
+   reg = <0 0x088eb000 0 0x200>;
+   status = "disabled";
+   #clock-cells = <1>;
+   #address-cells = <2>;
+   #size-cells = <2>;
+   ranges;
+
+   clocks = < GCC_USB3_SEC_PHY_AUX_CLK>,
+< RPMH_CXO_CLK>,
+< GCC_USB3_SEC_CLKREF_CLK>,
+< GCC_USB3_SEC_PHY_COM_AUX_CLK>;
+   clock-names = "aux", "ref_clk_src", "ref", "com_aux";
+
+   resets = < GCC_USB3PHY_PHY_SEC_BCR>,
+< GCC_USB3_PHY_SEC_BCR>;
+   reset-names = "phy", "common";
+
+   usb_2_ssphy: lane@88eb200 {
+   reg = <0 0x088eb200 0 0x200>,
+ <0 0x088eb400 0 0x200>,
+ <0 0x088eb800 0 0x800>,
+ <0 0x088eb600 0 0x200>;
+   #phy-cells = <0>;
+   clocks = < GCC_USB3_SEC_PHY_PIPE_CLK>;
+   clock-names = "pipe0";
+   clock-output-names = 
"usb3_uni_phy_pipe_clk_src";
+   };
+   };
+
usb_1: usb@a6f8800 {
compatible = "qcom,sm8150-dwc3", "qcom,dwc3";
reg = <0 0x0a6f8800 0 0x400>;
@@ -716,6 +760,51 @@ usb_1_dwc3: dwc3@a60 {
};
};
 
+   usb_2: usb@a8f8800 {
+   compatible = "qcom,sm8150-dwc3", "qcom,dwc3";
+   reg = <0 0x0a8f8800 0 0x400>;
+   status = "disabled";
+   #address-cells = <2>;
+   #size-cells = <2>;
+   ranges;
+   dma-ranges;
+
+   clocks = < GCC_CFG_NOC_USB3_SEC_AXI_CLK>,
+< GCC_USB30_SEC_MASTER_CLK>,
+< GCC_AGGRE_USB3_SEC_AXI_CLK>,
+< GCC_USB30_SEC_MOCK_UTMI_CLK>,
+< GCC_USB30_SEC_SLEEP_CLK>,
+< GCC_USB3_SEC_CLKREF_CLK>;
+   clock-names = "cfg_noc", "core", "iface", "mock_utmi",
+ "sleep", "xo";
+
+   assigned-clocks = < GCC_USB30_SEC_MOCK_UTMI_CLK>,
+ < GCC_USB30_SEC_MASTER_CLK>;
+   assigned-clock-rates = <1920>, <2>;
+
+   interrupts = ,
+,
+,
+;
+   interrupt-names = "hs_phy_irq", "ss_phy_irq",
+ "dm_hs_phy_irq", "dp_hs_phy_irq";
+
+   power-domains = < USB30_SEC_GDSC>;
+
+   resets = < GCC_USB30_SEC_BCR>;
+
+   usb_2_dwc3: dwc3@a80 {
+   compatible = "snps,dwc3";
+   reg = <0 0x0a80 0 0xcd00>;
+   interrupts = ;
+   iommus = <_smmu 0x160 0>;
+   snps,dis_u2_susphy_quirk;
+   snps,dis_enblslpm_quirk;
+   phys = 

[PATCH 6/6] arm64: dts: qcom: add sm8250 hdk dts

2020-05-23 Thread Jonathan Marek
Add initial HDK865 dts, based on sm8250-mtp, with a few changes.
Notably, regulator configs are changed a bit.

Signed-off-by: Jonathan Marek 
---
 arch/arm64/boot/dts/qcom/Makefile   |   1 +
 arch/arm64/boot/dts/qcom/sm8250-hdk.dts | 454 
 2 files changed, 455 insertions(+)
 create mode 100644 arch/arm64/boot/dts/qcom/sm8250-hdk.dts

diff --git a/arch/arm64/boot/dts/qcom/Makefile 
b/arch/arm64/boot/dts/qcom/Makefile
index e5dbd8b63951..4649e8bc5034 100644
--- a/arch/arm64/boot/dts/qcom/Makefile
+++ b/arch/arm64/boot/dts/qcom/Makefile
@@ -24,6 +24,7 @@ dtb-$(CONFIG_ARCH_QCOM)   += sdm845-mtp.dtb
 dtb-$(CONFIG_ARCH_QCOM)+= sdm850-lenovo-yoga-c630.dtb
 dtb-$(CONFIG_ARCH_QCOM)+= sm8150-hdk.dtb
 dtb-$(CONFIG_ARCH_QCOM)+= sm8150-mtp.dtb
+dtb-$(CONFIG_ARCH_QCOM)+= sm8250-hdk.dtb
 dtb-$(CONFIG_ARCH_QCOM)+= sm8250-mtp.dtb
 dtb-$(CONFIG_ARCH_QCOM)+= qcs404-evb-1000.dtb
 dtb-$(CONFIG_ARCH_QCOM)+= qcs404-evb-4000.dtb
diff --git a/arch/arm64/boot/dts/qcom/sm8250-hdk.dts 
b/arch/arm64/boot/dts/qcom/sm8250-hdk.dts
new file mode 100644
index ..d35014bf4f81
--- /dev/null
+++ b/arch/arm64/boot/dts/qcom/sm8250-hdk.dts
@@ -0,0 +1,454 @@
+// SPDX-License-Identifier: BSD-3-Clause
+/*
+ * Copyright (c) 2020, The Linux Foundation. All rights reserved.
+ */
+
+/dts-v1/;
+
+#include 
+#include 
+#include "sm8250.dtsi"
+#include "pm8150.dtsi"
+#include "pm8150b.dtsi"
+#include "pm8150l.dtsi"
+
+/ {
+   model = "Qualcomm Technologies, Inc. SM8250 HDK";
+   compatible = "qcom,sm8250-hdk";
+
+   aliases {
+   serial0 = 
+   };
+
+   chosen {
+   stdout-path = "serial0:115200n8";
+   };
+
+   vph_pwr: vph-pwr-regulator {
+   compatible = "regulator-fixed";
+   regulator-name = "vph_pwr";
+   regulator-min-microvolt = <370>;
+   regulator-max-microvolt = <370>;
+   };
+
+   vreg_s4a_1p8: pm8150-s4 {
+   compatible = "regulator-fixed";
+   regulator-name = "vreg_s4a_1p8";
+
+   regulator-min-microvolt = <180>;
+   regulator-max-microvolt = <180>;
+
+   regulator-always-on;
+   regulator-boot-on;
+
+   vin-supply = <_pwr>;
+   };
+
+   vreg_s6c_0p88: smpc6-regulator {
+   compatible = "regulator-fixed";
+   regulator-name = "vreg_s6c_0p88";
+
+   regulator-min-microvolt = <88>;
+   regulator-max-microvolt = <88>;
+   regulator-always-on;
+   vin-supply = <_pwr>;
+   };
+
+   gpio_keys {
+   compatible = "gpio-keys";
+
+   vol-up {
+   label = "Volume Up";
+   linux,code = ;
+   gpios = <_gpios 6 GPIO_ACTIVE_LOW>;
+   };
+   };
+};
+
+_rsc {
+   pm8150-rpmh-regulators {
+   compatible = "qcom,pm8150-rpmh-regulators";
+   qcom,pmic-id = "a";
+
+   vdd-s1-supply = <_pwr>;
+   vdd-s2-supply = <_pwr>;
+   vdd-s3-supply = <_pwr>;
+   vdd-s4-supply = <_pwr>;
+   vdd-s5-supply = <_pwr>;
+   vdd-s6-supply = <_pwr>;
+   vdd-s7-supply = <_pwr>;
+   vdd-s8-supply = <_pwr>;
+   vdd-s9-supply = <_pwr>;
+   vdd-s10-supply = <_pwr>;
+   vdd-l1-l8-l11-supply = <_s6c_0p88>;
+   vdd-l2-l10-supply = <_bob>;
+   vdd-l3-l4-l5-l18-supply = <_s6a_0p95>;
+   vdd-l6-l9-supply = <_s8c_1p3>;
+   vdd-l7-l12-l14-l15-supply = <_s5a_1p9>;
+   vdd-l13-l16-l17-supply = <_bob>;
+
+   vreg_s5a_1p9: smps5 {
+   regulator-name = "vreg_s5a_1p9";
+   regulator-min-microvolt = <1824000>;
+   regulator-max-microvolt = <200>;
+   regulator-initial-mode = ;
+   };
+
+   vreg_s6a_0p95: smps6 {
+   regulator-name = "vreg_s6a_0p95";
+   regulator-min-microvolt = <60>;
+   regulator-max-microvolt = <1128000>;
+   regulator-initial-mode = ;
+   };
+
+   vreg_l2a_3p1: ldo2 {
+   regulator-name = "vreg_l2a_3p1";
+   regulator-min-microvolt = <3072000>;
+   regulator-max-microvolt = <3072000>;
+   regulator-initial-mode = ;
+   };
+
+   vreg_l3a_0p9: ldo3 {
+   regulator-name = "vreg_l3a_0p9";
+   regulator-min-microvolt = <928000>;
+   regulator-max-microvolt = <932000>;
+   regulator-initial-mode = ;
+   };
+
+   vreg_l5a_0p88: ldo5 {
+  

[PATCH 1/6] arm64: dts: qcom: sm8150: add apps_smmu node

2020-05-23 Thread Jonathan Marek
Add the apps_smmu node for sm8150. Note that adding the iommus field for
UFS is required because initializing the iommu removes the bypass mapping
that created by the bootloader.

Signed-off-by: Jonathan Marek 
---
 arch/arm64/boot/dts/qcom/sm8150.dtsi | 91 
 1 file changed, 91 insertions(+)

diff --git a/arch/arm64/boot/dts/qcom/sm8150.dtsi 
b/arch/arm64/boot/dts/qcom/sm8150.dtsi
index a36512d1f6a1..acb839427b12 100644
--- a/arch/arm64/boot/dts/qcom/sm8150.dtsi
+++ b/arch/arm64/boot/dts/qcom/sm8150.dtsi
@@ -442,6 +442,8 @@ ufs_mem_hc: ufshc@1d84000 {
resets = < GCC_UFS_PHY_BCR>;
reset-names = "rst";
 
+   iommus = <_smmu 0x300 0>;
+
clock-names =
"core_clk",
"bus_aggr_clk",
@@ -706,6 +708,7 @@ usb_1_dwc3: dwc3@a60 {
compatible = "snps,dwc3";
reg = <0 0x0a60 0 0xcd00>;
interrupts = ;
+   iommus = <_smmu 0x140 0>;
snps,dis_u2_susphy_quirk;
snps,dis_enblslpm_quirk;
phys = <_1_hsphy>, <_1_ssphy>;
@@ -742,6 +745,94 @@ spmi_bus: spmi@c44 {
cell-index = <0>;
};
 
+   apps_smmu: iommu@1500 {
+   compatible = "qcom,sdm845-smmu-500", "arm,mmu-500";
+   reg = <0 0x1500 0 0x10>;
+   #iommu-cells = <2>;
+   #global-interrupts = <1>;
+   interrupts = ,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+;
+   };
+
remoteproc_adsp: remoteproc@1730 {
compatible = "qcom,sm8150-adsp-pas";

Re: [PATCH v13 2/2] media: v4l: xilinx: Add Xilinx MIPI CSI-2 Rx Subsystem driver

2020-05-23 Thread Laurent Pinchart
Hi Vishal,

Thank you for the patch.

On Tue, May 12, 2020 at 08:49:47PM +0530, Vishal Sagar wrote:
> The Xilinx MIPI CSI-2 Rx Subsystem soft IP is used to capture images
> from MIPI CSI-2 camera sensors and output AXI4-Stream video data ready
> for image processing. Please refer to PG232 for details.
> 
> The CSI2 Rx controller filters out all packets except for the packets
> with data type fixed in hardware. RAW8 packets are always allowed to
> pass through.
> 
> It is also used to setup and handle interrupts and enable the core. It
> logs all the events in respective counters between streaming on and off.
> 
> The driver supports only the video format bridge enabled configuration.
> Some data types like YUV 422 10bpc, RAW16, RAW20 are supported when the
> CSI v2.0 feature is enabled in design. When the VCX feature is enabled,
> the maximum number of virtual channels becomes 16 from 4.
> 
> Signed-off-by: Vishal Sagar 
> Reviewed-by: Hyun Kwon 
> Reviewed-by: Laurent Pinchart 
> ---
> v13
> - Based on Laurent's suggestions
> - Removed unnecessary debug statement for vep
> - Added TODO for clock to enable disable at streamon/off
> - Fix for index to start from 0 for get_nth_mbus_format
> - Removed macro XCSI_TIMEOUT_VAL
> - Remove ndelay from hard reset
> - Remove hard reset from irq handler
> - Fix short packet fifo clear
> - Add TODO for v4l2_subdev_notify for SLBF error
> - Fix the enable condition in s_stream
> - Fix condition in xcsi2rxss_set_format
> - Fix enum_mbus_code for double enumeration of RAW8 Data type
> - Removed core struct
> - Added reviewed by Laurent
> 
> v12
> - Changes done as suggested by Laurent Pinchart and Luca Ceresoli
> - Removed unused macros
> - No local storage of supported formats
> - Dropped init mbus fmts and removed xcsi2rxss_init_mbus_fmts()
> - XCSI_GET_BITSET_STR removed
> - Add data type and mbus LUT
>   - Added xcsi2rxss_get_nth_mbus() and xcsi2rxss_get_dt()
> - Replaced all core->dev with dev in dev_dbg() and related debug prints
> - Replaced xcsi2rxss_log_ipconfig() with single line
> - Removed small functions to enable/disable interrupts and core
> - Now save remote subdev in state struct before streaming on
> - Made xcsi2rxss_reset as soft_reset()
> - Added hard reset using video-reset gpio
>   - 2 modes one with delay and another sleep
> - Instead of reset-gpios it is not video-reset-gpios
> - In irq handler
>   - Moved clearing of ISR up
>   - Dump / empty short packet fifo
>   - Irq handler is now threaded 
> - Added init_cfg pad ops and removed open()
> - Updated xcsi2rxss_set_format(), xcsi2rxss_enum_mbus_code() to use the dt 
> mbus lut
> - xcsi2rxss_set_default_format() updated
> - Moved mutex_init()
> - Updated graph handling
> - Removed unnecessary prints
> - Use devm_platform_ioremap_resource() and platform_get_irq()
> - Update KConfig description
> 
> v11
> - Fixed changes as suggested by Sakari Ailus
> - Removed VIDEO_XILINX from KConfig
> - Minor formatting
> - Start / Stop upstream sub-device in xcsi2rxss_start_stream()
>   and xcsi2rxss_stop_stream()
> - Added v4l2_subdev_link_validate_default() in v4l2_subdev_pad_ops()
> - Use fwnode_graph_get_endpoint_by_id() instead of parsing by self
> - Set bus type as V4L2_MBUS_CSI2_DPHY in struct v4l2_fwnode_endpoint
> - Remove num_clks from core. Instead use ARRAY_SIZE()
> - Fixed SPDX header to GPL-2.0
> - Update copyright year to 2020
> 
> v10
> - Removed all V4L2 controls and events based on Sakari's comments.
> - Now stop_stream() before toggling rst_gpio
> - Updated init_mbus() to throw error on array out of bound access
> - Make events and vcx_events as counters instead of structures
> - Minor fixes in set_format() enum_mbus_code() as suggested by Sakari
> 
> v9
> - Moved all controls and events to xilinx-csi2rxss.h
> - Updated name and description of controls and events
> - Get control base address from v4l2-controls.h (0x10c0)
> - Fix KConfig for dependency on VIDEO_XILINX
> - Added enum_mbus_code() support
> - Added default format to be returned on open()
> - Mark variables are const
> - Remove references to short packet in comments
> - Add check for streaming before setting active lanes control
> - strlcpy -> strscpy
> - Fix xcsi2rxss_set_format()
> 
> v8
> - Use clk_bulk* APIs
> - Add gpio reset for asserting video_aresetn when stream line buffer occurs
> - Removed short packet related events and irq handling
>   - V4L2_EVENT_XLNXCSIRX_SPKT and V4L2_EVENT_XLNXCSIRX_SPKT_OVF removed
> - Removed frame counter control V4L2_CID_XILINX_MIPICSISS_FRAME_COUNTER
>   and xcsi2rxss_g_volatile_ctrl()
> - Minor formatting fixes
> 
> v7
> - No change
> 
> v6
> - No change
> 
> v5
> - Removed bayer and updated related parts like set default format based
>   on Luca Cersoli's comments.
> - Added correct YUV422 10bpc media bus format
> 
> v4
> - Removed irq member from core structure
> - Consolidated IP config prints in xcsi2rxss_log_ipconfig()
> - Return -EINVAL in case of invalid ioctl
> - Code formatting
> 

[PATCH] drm/qxl: Replace deprecated function in qxl_display

2020-05-23 Thread Sidong Yang
Hi, Dave.

This is resended e-mail for your advice.

I'm a newbie interested in linux kernel and qxl module.
Please check this patch and give me advice for me.
Also I'll be glad if there is any task that you bothered.
Thanks.

Sidong.

Replace deprecated function drm_modeset_lock/unlock_all with
helper function DRM_MODESET_LOCK_ALL_BEGIN/END.

Signed-off-by: Sidong Yang 
---
 drivers/gpu/drm/qxl/qxl_display.c | 21 +++--
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/qxl/qxl_display.c 
b/drivers/gpu/drm/qxl/qxl_display.c
index 1082cd5d2fd4..07e164cee868 100644
--- a/drivers/gpu/drm/qxl/qxl_display.c
+++ b/drivers/gpu/drm/qxl/qxl_display.c
@@ -162,7 +162,8 @@ static void qxl_update_offset_props(struct qxl_device *qdev)
 void qxl_display_read_client_monitors_config(struct qxl_device *qdev)
 {
struct drm_device *dev = >ddev;
-   int status, retries;
+   struct drm_modeset_acquire_ctx ctx;
+   int status, retries, ret;
 
for (retries = 0; retries < 10; retries++) {
status = qxl_display_copy_rom_client_monitors_config(qdev);
@@ -183,9 +184,9 @@ void qxl_display_read_client_monitors_config(struct 
qxl_device *qdev)
return;
}
 
-   drm_modeset_lock_all(dev);
+   DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE, 
ret);
qxl_update_offset_props(qdev);
-   drm_modeset_unlock_all(dev);
+   DRM_MODESET_LOCK_ALL_END(ctx, ret);
if (!drm_helper_hpd_irq_event(dev)) {
/* notify that the monitor configuration changed, to
   adjust at the arbitrary resolution */
@@ -403,18 +404,17 @@ static int qxl_framebuffer_surface_dirty(struct 
drm_framebuffer *fb,
struct qxl_device *qdev = to_qxl(fb->dev);
struct drm_clip_rect norect;
struct qxl_bo *qobj;
+   struct drm_modeset_acquire_ctx ctx;
bool is_primary;
-   int inc = 1;
+   int inc = 1, ret;
 
-   drm_modeset_lock_all(fb->dev);
+   DRM_MODESET_LOCK_ALL_BEGIN(fb->dev, ctx, 
DRM_MODESET_ACQUIRE_INTERRUPTIBLE, ret);
 
qobj = gem_to_qxl_bo(fb->obj[0]);
/* if we aren't primary surface ignore this */
is_primary = qobj->shadow ? qobj->shadow->is_primary : qobj->is_primary;
-   if (!is_primary) {
-   drm_modeset_unlock_all(fb->dev);
-   return 0;
-   }
+   if (!is_primary)
+   goto out_lock_end;
 
if (!num_clips) {
num_clips = 1;
@@ -430,7 +430,8 @@ static int qxl_framebuffer_surface_dirty(struct 
drm_framebuffer *fb,
qxl_draw_dirty_fb(qdev, fb, qobj, flags, color,
  clips, num_clips, inc, 0);
 
-   drm_modeset_unlock_all(fb->dev);
+out_lock_end:
+   DRM_MODESET_LOCK_ALL_END(ctx, ret);
 
return 0;
 }
-- 
2.17.1



[PATCH] drm/panfrost: Fix runtime PM imbalance in panfrost_perfcnt_enable_locked

2020-05-23 Thread Dinghao Liu
pm_runtime_get_sync() increments the runtime PM usage counter even
when it returns an error code. Thus a pairing decrement is needed on
the error handling path to keep the counter balanced. For all error
paths after pm_runtime_get_sync(), things are the same.

Signed-off-by: Dinghao Liu 
---
 drivers/gpu/drm/panfrost/panfrost_perfcnt.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/panfrost/panfrost_perfcnt.c 
b/drivers/gpu/drm/panfrost/panfrost_perfcnt.c
index 6913578d5aa7..d99bd2f0503a 100644
--- a/drivers/gpu/drm/panfrost/panfrost_perfcnt.c
+++ b/drivers/gpu/drm/panfrost/panfrost_perfcnt.c
@@ -83,11 +83,13 @@ static int panfrost_perfcnt_enable_locked(struct 
panfrost_device *pfdev,
 
ret = pm_runtime_get_sync(pfdev->dev);
if (ret < 0)
-   return ret;
+   goto err_pm_get;
 
bo = drm_gem_shmem_create(pfdev->ddev, perfcnt->bosize);
-   if (IS_ERR(bo))
-   return PTR_ERR(bo);
+   if (IS_ERR(bo)) {
+   ret = PTR_ERR(bo);
+   goto err_pm_get;
+   }
 
/* Map the perfcnt buf in the address space attached to file_priv. */
ret = panfrost_gem_open(>base, file_priv);
@@ -168,6 +170,8 @@ static int panfrost_perfcnt_enable_locked(struct 
panfrost_device *pfdev,
panfrost_gem_close(>base, file_priv);
 err_put_bo:
drm_gem_object_put_unlocked(>base);
+err_pm_get:
+   pm_runtime_put_noidle(pfdev->dev);
return ret;
 }
 
-- 
2.17.1



[PATCH 2/3] phy: qcom-qmp: Add QMP V4 USB3 UNIPHY

2020-05-23 Thread Jonathan Marek
Add support for the USB3 PHY used by the secondary usb controller on sm8150

Signed-off-by: Jonathan Marek 
---
 drivers/phy/qualcomm/phy-qcom-qmp.c | 150 
 drivers/phy/qualcomm/phy-qcom-qmp.h |   5 +
 2 files changed, 155 insertions(+)

diff --git a/drivers/phy/qualcomm/phy-qcom-qmp.c 
b/drivers/phy/qualcomm/phy-qcom-qmp.c
index b3e07afca3ca..9367f8f793b5 100644
--- a/drivers/phy/qualcomm/phy-qcom-qmp.c
+++ b/drivers/phy/qualcomm/phy-qcom-qmp.c
@@ -199,6 +199,17 @@ static const unsigned int 
qmp_v4_usb3phy_regs_layout[QPHY_LAYOUT_SIZE] = {
[QPHY_START_CTRL]   = 0x44,
[QPHY_PCS_STATUS]   = 0x14,
[QPHY_PCS_POWER_DOWN_CONTROL]   = 0x40,
+   [QPHY_PCS_AUTONOMOUS_MODE_CTRL] = 0x308,
+   [QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR] = 0x314,
+};
+
+static const unsigned int qmp_v4_usb3_uniphy_regs_layout[QPHY_LAYOUT_SIZE] = {
+   [QPHY_SW_RESET] = 0x00,
+   [QPHY_START_CTRL]   = 0x44,
+   [QPHY_PCS_STATUS]   = 0x14,
+   [QPHY_PCS_POWER_DOWN_CONTROL]   = 0x40,
+   [QPHY_PCS_AUTONOMOUS_MODE_CTRL] = 0x608,
+   [QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR]  = 0x614,
 };
 
 static const unsigned int sdm845_ufsphy_regs_layout[QPHY_LAYOUT_SIZE] = {
@@ -1413,6 +1424,114 @@ static const struct qmp_phy_init_tbl 
sm8150_usb3_pcs_tbl[] = {
QMP_PHY_INIT_CFG(QPHY_V4_PCS_USB3_RXEQTRAINING_DFE_TIME_S2, 0x07),
 };
 
+static const struct qmp_phy_init_tbl sm8150_usb3_uniphy_serdes_tbl[] = {
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_SYSCLK_EN_SEL, 0x1a),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIN_VCOCAL_HSCLK_SEL, 0x11),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_HSCLK_SEL, 0x01),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_DEC_START_MODE0, 0x82),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_DIV_FRAC_START1_MODE0, 0xab),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_DIV_FRAC_START2_MODE0, 0xea),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_DIV_FRAC_START3_MODE0, 0x02),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIN_VCOCAL_CMP_CODE1_MODE0, 0xca),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIN_VCOCAL_CMP_CODE2_MODE0, 0x1e),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_CP_CTRL_MODE0, 0x06),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_RCTRL_MODE0, 0x16),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_CCTRL_MODE0, 0x36),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_VCO_TUNE1_MODE0, 0x24),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP2_MODE0, 0x34),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP1_MODE0, 0x14),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP_EN, 0x04),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_SYSCLK_BUF_ENABLE, 0x0a),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_VCO_TUNE2_MODE1, 0x02),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_VCO_TUNE1_MODE1, 0x24),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_CORECLK_DIV_MODE1, 0x08),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_DEC_START_MODE1, 0x82),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_DIV_FRAC_START1_MODE1, 0xab),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_DIV_FRAC_START2_MODE1, 0xea),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_DIV_FRAC_START3_MODE1, 0x02),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP2_MODE1, 0x82),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP1_MODE1, 0x34),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_CP_CTRL_MODE1, 0x06),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_RCTRL_MODE1, 0x16),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_CCTRL_MODE1, 0x36),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIN_VCOCAL_CMP_CODE1_MODE1, 0xca),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIN_VCOCAL_CMP_CODE2_MODE1, 0x1e),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_CMN_IPTRIM, 0x20),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_SSC_EN_CENTER, 0x01),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_SSC_PER1, 0x31),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_SSC_PER2, 0x01),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_SSC_STEP_SIZE1_MODE1, 0xde),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_SSC_STEP_SIZE2_MODE1, 0x07),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_SSC_STEP_SIZE1_MODE0, 0xde),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_SSC_STEP_SIZE2_MODE0, 0x07),
+   QMP_PHY_INIT_CFG(QSERDES_V4_COM_VCO_TUNE_MAP, 0x02),
+};
+
+static const struct qmp_phy_init_tbl sm8150_usb3_uniphy_tx_tbl[] = {
+   QMP_PHY_INIT_CFG(QSERDES_V4_TX_RCV_DETECT_LVL_2, 0x12),
+   QMP_PHY_INIT_CFG(QSERDES_V4_TX_LANE_MODE_1, 0x95),
+   QMP_PHY_INIT_CFG(QSERDES_V4_TX_PI_QEC_CTRL, 0x40),
+   QMP_PHY_INIT_CFG(QSERDES_V4_TX_RES_CODE_LANE_OFFSET_TX, 0x05),
+};
+
+static const struct qmp_phy_init_tbl sm8150_usb3_uniphy_rx_tbl[] = {
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH4, 0xb8),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH3, 0x7f),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH2, 0x37),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH, 0x2f),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_LOW, 0xef),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH4, 0xb3),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH3, 0x0b),

[PATCH 3/3] phy: qcom-qmp: Add QMP V4 USB3 PHY support for sm8250

2020-05-23 Thread Jonathan Marek
Add both the DP and UNI PHY for primary/secondary usb controllers.

The tables are very similar to sm8150 (serdes_tbl is identical), but there
are some differences.

Signed-off-by: Jonathan Marek 
---
 drivers/phy/qualcomm/phy-qcom-qmp.c | 206 
 drivers/phy/qualcomm/phy-qcom-qmp.h |   2 +
 2 files changed, 208 insertions(+)

diff --git a/drivers/phy/qualcomm/phy-qcom-qmp.c 
b/drivers/phy/qualcomm/phy-qcom-qmp.c
index 9367f8f793b5..8a597cedfebe 100644
--- a/drivers/phy/qualcomm/phy-qcom-qmp.c
+++ b/drivers/phy/qualcomm/phy-qcom-qmp.c
@@ -1532,6 +1532,142 @@ static const struct qmp_phy_init_tbl 
sm8150_usb3_uniphy_pcs_tbl[] = {
QMP_PHY_INIT_CFG(QPHY_V4_PCS_PCS_TX_RX_CONFIG, 0x0c),
 };
 
+static const struct qmp_phy_init_tbl sm8250_usb3_tx_tbl[] = {
+   QMP_PHY_INIT_CFG(QSERDES_V4_TX_RES_CODE_LANE_TX, 0x60),
+   QMP_PHY_INIT_CFG(QSERDES_V4_TX_RES_CODE_LANE_RX, 0x60),
+   QMP_PHY_INIT_CFG(QSERDES_V4_TX_RES_CODE_LANE_OFFSET_TX, 0x11),
+   QMP_PHY_INIT_CFG(QSERDES_V4_TX_RES_CODE_LANE_OFFSET_RX, 0x02),
+   QMP_PHY_INIT_CFG(QSERDES_V4_TX_LANE_MODE_1, 0xd5),
+   QMP_PHY_INIT_CFG(QSERDES_V4_TX_RCV_DETECT_LVL_2, 0x12),
+   QMP_PHY_INIT_CFG_LANE(QSERDES_V4_TX_PI_QEC_CTRL, 0x40, 1),
+   QMP_PHY_INIT_CFG_LANE(QSERDES_V4_TX_PI_QEC_CTRL, 0x54, 2),
+};
+
+static const struct qmp_phy_init_tbl sm8250_usb3_rx_tbl[] = {
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SO_GAIN, 0x06),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FASTLOCK_FO_GAIN, 0x2f),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x7f),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FASTLOCK_COUNT_LOW, 0xff),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FASTLOCK_COUNT_HIGH, 0x0f),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_PI_CONTROLS, 0x99),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SB2_THRESH1, 0x04),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SB2_THRESH2, 0x08),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SB2_GAIN1, 0x05),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SB2_GAIN2, 0x05),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_VGA_CAL_CNTRL1, 0x54),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_VGA_CAL_CNTRL2, 0x0c),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL2, 0x0f),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL3, 0x4a),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL4, 0x0a),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_LOW, 0xc0),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_HIGH, 0x00),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1, 0x77),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_SIGDET_CNTRL, 0x04),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_SIGDET_DEGLITCH_CNTRL, 0x0e),
+   QMP_PHY_INIT_CFG_LANE(QSERDES_V4_RX_RX_MODE_00_LOW, 0xff, 1),
+   QMP_PHY_INIT_CFG_LANE(QSERDES_V4_RX_RX_MODE_00_LOW, 0x7f, 2),
+   QMP_PHY_INIT_CFG_LANE(QSERDES_V4_RX_RX_MODE_00_HIGH, 0x7f, 1),
+   QMP_PHY_INIT_CFG_LANE(QSERDES_V4_RX_RX_MODE_00_HIGH, 0xff, 2),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH2, 0x7f),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH3, 0x7f),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH4, 0x97),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_LOW, 0xdc),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH, 0xdc),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH2, 0x5c),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH3, 0x7b),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH4, 0xb4),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_DFE_EN_TIMER, 0x04),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_DFE_CTLE_POST_CAL_OFFSET, 0x38),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_AUX_DATA_TCOARSE_TFINE, 0xa0),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_DCC_CTRL1, 0x0c),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_GM_CAL, 0x1f),
+   QMP_PHY_INIT_CFG(QSERDES_V4_RX_VTH_CODE, 0x10),
+};
+
+static const struct qmp_phy_init_tbl sm8250_usb3_pcs_tbl[] = {
+   QMP_PHY_INIT_CFG(QPHY_V4_PCS_LOCK_DETECT_CONFIG1, 0xd0),
+   QMP_PHY_INIT_CFG(QPHY_V4_PCS_LOCK_DETECT_CONFIG2, 0x07),
+   QMP_PHY_INIT_CFG(QPHY_V4_PCS_LOCK_DETECT_CONFIG3, 0x20),
+   QMP_PHY_INIT_CFG(QPHY_V4_PCS_LOCK_DETECT_CONFIG6, 0x13),
+   QMP_PHY_INIT_CFG(QPHY_V4_PCS_REFGEN_REQ_CONFIG1, 0x21),
+   QMP_PHY_INIT_CFG(QPHY_V4_PCS_RX_SIGDET_LVL, 0xa9),
+   QMP_PHY_INIT_CFG(QPHY_V4_PCS_CDR_RESET_TIME, 0x0a),
+   QMP_PHY_INIT_CFG(QPHY_V4_PCS_ALIGN_DETECT_CONFIG1, 0x88),
+   QMP_PHY_INIT_CFG(QPHY_V4_PCS_ALIGN_DETECT_CONFIG2, 0x13),
+   QMP_PHY_INIT_CFG(QPHY_V4_PCS_PCS_TX_RX_CONFIG, 0x0c),
+   QMP_PHY_INIT_CFG(QPHY_V4_PCS_EQ_CONFIG1, 0x4b),
+   QMP_PHY_INIT_CFG(QPHY_V4_PCS_EQ_CONFIG5, 0x10),
+   QMP_PHY_INIT_CFG(QPHY_V4_PCS_USB3_LFPS_DET_HIGH_COUNT_VAL, 0xf8),
+   QMP_PHY_INIT_CFG(QPHY_V4_PCS_USB3_RXEQTRAINING_DFE_TIME_S2, 0x07),
+};
+
+static const struct qmp_phy_init_tbl sm8250_usb3_uniphy_tx_tbl[] = {
+   QMP_PHY_INIT_CFG(QSERDES_V4_TX_RCV_DETECT_LVL_2, 0x12),
+  

[PATCH 1/3] phy: qcom-qmp: Allow different values for second lane

2020-05-23 Thread Jonathan Marek
The primary USB PHY on sm8250 sets some values differently for the second
lane. This makes it possible to represent that.

Signed-off-by: Jonathan Marek 
---
 drivers/phy/qualcomm/phy-qcom-qmp.c | 52 ++---
 1 file changed, 40 insertions(+), 12 deletions(-)

diff --git a/drivers/phy/qualcomm/phy-qcom-qmp.c 
b/drivers/phy/qualcomm/phy-qcom-qmp.c
index e91040af3394..b3e07afca3ca 100644
--- a/drivers/phy/qualcomm/phy-qcom-qmp.c
+++ b/drivers/phy/qualcomm/phy-qcom-qmp.c
@@ -82,20 +82,34 @@ struct qmp_phy_init_tbl {
 * register part of layout ?
 * if yes, then offset gives index in the reg-layout
 */
-   int in_layout;
+   bool in_layout;
+   /*
+* mask of lanes for which this register is written
+* for cases when second lane needs different values
+*/
+   u8 lane_mask;
 };
 
 #define QMP_PHY_INIT_CFG(o, v) \
{   \
.offset = o,\
.val = v,   \
+   .lane_mask = 0xff,  \
}
 
 #define QMP_PHY_INIT_CFG_L(o, v)   \
{   \
.offset = o,\
.val = v,   \
-   .in_layout = 1, \
+   .in_layout = true,  \
+   .lane_mask = 0xff,  \
+   }
+
+#define QMP_PHY_INIT_CFG_LANE(o, v, l) \
+   {   \
+   .offset = o,\
+   .val = v,   \
+   .lane_mask = l, \
}
 
 /* set of registers with offsets different per-PHY */
@@ -1986,10 +2000,11 @@ static const struct qmp_phy_cfg sm8150_usb3phy_cfg = {
.is_dual_lane_phy   = true,
 };
 
-static void qcom_qmp_phy_configure(void __iomem *base,
-  const unsigned int *regs,
-  const struct qmp_phy_init_tbl tbl[],
-  int num)
+static void qcom_qmp_phy_configure_lane(void __iomem *base,
+   const unsigned int *regs,
+   const struct qmp_phy_init_tbl tbl[],
+   int num,
+   u8 lane_mask)
 {
int i;
const struct qmp_phy_init_tbl *t = tbl;
@@ -1998,6 +2013,9 @@ static void qcom_qmp_phy_configure(void __iomem *base,
return;
 
for (i = 0; i < num; i++, t++) {
+   if (!(t->lane_mask & lane_mask))
+   continue;
+
if (t->in_layout)
writel(t->val, base + regs[t->offset]);
else
@@ -2005,6 +2023,14 @@ static void qcom_qmp_phy_configure(void __iomem *base,
}
 }
 
+static void qcom_qmp_phy_configure(void __iomem *base,
+  const unsigned int *regs,
+  const struct qmp_phy_init_tbl tbl[],
+  int num)
+{
+   qcom_qmp_phy_configure_lane(base, regs, tbl, num, 0xff);
+}
+
 static int qcom_qmp_phy_com_init(struct qmp_phy *qphy)
 {
struct qcom_qmp *qmp = qphy->qmp;
@@ -2219,16 +2245,18 @@ static int qcom_qmp_phy_enable(struct phy *phy)
}
 
/* Tx, Rx, and PCS configurations */
-   qcom_qmp_phy_configure(tx, cfg->regs, cfg->tx_tbl, cfg->tx_tbl_num);
+   qcom_qmp_phy_configure_lane(tx, cfg->regs,
+   cfg->tx_tbl, cfg->tx_tbl_num, 1);
/* Configuration for other LANE for USB-DP combo PHY */
if (cfg->is_dual_lane_phy)
-   qcom_qmp_phy_configure(qphy->tx2, cfg->regs,
-  cfg->tx_tbl, cfg->tx_tbl_num);
+   qcom_qmp_phy_configure_lane(qphy->tx2, cfg->regs,
+   cfg->tx_tbl, cfg->tx_tbl_num, 2);
 
-   qcom_qmp_phy_configure(rx, cfg->regs, cfg->rx_tbl, cfg->rx_tbl_num);
+   qcom_qmp_phy_configure_lane(rx, cfg->regs,
+   cfg->rx_tbl, cfg->rx_tbl_num, 1);
if (cfg->is_dual_lane_phy)
-   qcom_qmp_phy_configure(qphy->rx2, cfg->regs,
-  cfg->rx_tbl, cfg->rx_tbl_num);
+   qcom_qmp_phy_configure_lane(qphy->rx2, cfg->regs,
+   cfg->rx_tbl, cfg->rx_tbl_num, 2);
 
qcom_qmp_phy_configure(pcs, cfg->regs, cfg->pcs_tbl, cfg->pcs_tbl_num);
ret = reset_control_deassert(qmp->ufs_reset);
-- 
2.26.1



[PATCH 0/3] phy: qcom-qmp: add V4 USB PHYs

2020-05-23 Thread Jonathan Marek
Add support for sm8150 secondary USB PHY and both sm8250 USB PHYs.

Jonathan Marek (3):
  phy: qcom-qmp: Allow different values for second lane
  phy: qcom-qmp: Add QMP V4 USB3 UNIPHY
  phy: qcom-qmp: Add QMP V4 USB3 PHY support for sm8250

 drivers/phy/qualcomm/phy-qcom-qmp.c | 408 +++-
 drivers/phy/qualcomm/phy-qcom-qmp.h |   7 +
 2 files changed, 403 insertions(+), 12 deletions(-)

-- 
2.26.1



Re: [RFC PATCH v12 10/11] arm64: add mechanism to let user choose which counter to return

2020-05-23 Thread Richard Cochran
On Fri, May 22, 2020 at 04:37:23PM +0800, Jianyong Wu wrote:
> In general, vm inside will use virtual counter compered with host use
> phyical counter. But in some special scenarios, like nested
> virtualization, phyical counter maybe used by vm. A interface added in
> ptp_kvm driver to offer a mechanism to let user choose which counter
> should be return from host.

Sounds like you have two time sources, one for normal guest, and one
for nested.  Why not simply offer the correct one to user space
automatically?  If that cannot be done, then just offer two PHC
devices with descriptive names.

> diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c
> index fef72f29f3c8..8b0a7b328bcd 100644
> --- a/drivers/ptp/ptp_chardev.c
> +++ b/drivers/ptp/ptp_chardev.c
> @@ -123,6 +123,9 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, 
> unsigned long arg)
>   struct timespec64 ts;
>   int enable, err = 0;
>  
> +#ifdef CONFIG_ARM64
> + static long flag;

static?  This is not going to fly.

> +  * In most cases, we just need virtual counter from host and
> +  * there is limited scenario using this to get physical counter
> +  * in guest.
> +  * Be careful to use this as there is no way to set it back
> +  * unless you reinstall the module.

How on earth is the user supposed to know this?

>From your description, this "flag" really should be a module
parameter.

Thanks,
Richard


Re: [PATCH] sparc32: use PUD rather than PGD to get PMD in srmmu_nocache_init()

2020-05-23 Thread Guenter Roeck
On 5/23/20 5:15 PM, Linus Torvalds wrote:
> On Sat, May 23, 2020 at 3:47 PM Guenter Roeck  wrote:
>>
>> This quite innocent looking patch crashes all my sparc32 boot tests.
>> Crash log and bisect results below. Reverting it fixes the problem.
> 
> It should also fixed by 0cfc8a8d70dc ("sparc32: fix page table
> traversal in srmmu_nocache_init()"). No?
> 

Yes, it is. Sorry for the noise. 0cfc8a8d70dc wasn't available
when I started the bisect, and I didn't re-check afterwards.

Guenter


[PATCH] drm/i915/selftests: Fix runtime PM imbalance on error

2020-05-23 Thread Dinghao Liu
When drm_dev_init() returns an error code, a pairing
runtime PM usage counter decrement is needed to keep
the counter balanced. For error paths after this call,
things are the same.

Signed-off-by: Dinghao Liu 
---
 drivers/gpu/drm/i915/selftests/mock_gem_device.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/i915/selftests/mock_gem_device.c 
b/drivers/gpu/drm/i915/selftests/mock_gem_device.c
index 754d0eb6beaa..fdf01461acc6 100644
--- a/drivers/gpu/drm/i915/selftests/mock_gem_device.c
+++ b/drivers/gpu/drm/i915/selftests/mock_gem_device.c
@@ -200,6 +200,7 @@ struct drm_i915_private *mock_gem_device(void)
drm_mode_config_cleanup(>drm);
drm_dev_fini(>drm);
 put_device:
+   pm_runtime_put_noidle(>dev);
put_device(>dev);
 err:
return NULL;
-- 
2.17.1



Re: [PATCH v13 1/2] media: dt-bindings: media: xilinx: Add Xilinx MIPI CSI-2 Rx Subsystem

2020-05-23 Thread Laurent Pinchart
Hi Vishal,

Thank you for the patch.

On Tue, May 12, 2020 at 08:49:46PM +0530, Vishal Sagar wrote:
> Add bindings documentation for Xilinx MIPI CSI-2 Rx Subsystem.
> 
> The Xilinx MIPI CSI-2 Rx Subsystem consists of a CSI-2 Rx controller, a
> D-PHY in Rx mode and a Video Format Bridge.
> 
> Signed-off-by: Vishal Sagar 
> Reviewed-by: Hyun Kwon 
> Reviewed-by: Rob Herring 
> Reviewed-by: Luca Ceresoli 
> Reviewed-by: Laurent Pinchart 
> ---
> v13
> - Based on Laurent's suggestions
> - Fixed the datatypes values as minimum and maximum
> - condition added for en-vcx property
> 
> v12
> - Moved to yaml format
> - Update CSI-2 and D-PHY
> - Mention that bindings for D-PHY not here
> - reset -> video-reset
> 
> v11
> - Modify compatible string from 4.0 to 5.0
> 
> v10
> - No changes
> 
> v9
> - Fix xlnx,vfb description.
> - s/Optional/Required endpoint property.
> - Move data-lanes description from Ports to endpoint property section.
> 
> v8
> - Added reset-gpios optional property to assert video_aresetn
> 
> v7
> - Removed the control name from dt bindings
> - Updated the example dt node name to csi2rx
> 
> v6
> - Added "control" after V4L2_CID_XILINX_MIPICSISS_ACT_LANES as suggested by 
> Luca
> - Added reviewed by Rob Herring
> 
> v5
> - Incorporated comments by Luca Cersoli
> - Removed DPHY clock from description and example
> - Removed bayer pattern from device tree MIPI CSI IP
>   doesn't deal with bayer pattern.
> 
> v4
> - Added reviewed by Hyun Kwon
> 
> v3
> - removed interrupt parent as suggested by Rob
> - removed dphy clock
> - moved vfb to optional properties
> - Added required and optional port properties section
> - Added endpoint property section
> 
> v2
> - updated the compatible string to latest version supported
> - removed DPHY related parameters
> - added CSI v2.0 related property (including VCX for supporting upto 16
>   virtual channels).
> - modified csi-pxl-format from string to unsigned int type where the value
>   is as per the CSI specification
> - Defined port 0 and port 1 as sink and source ports.
> - Removed max-lanes property as suggested by Rob and Sakari
>  .../bindings/media/xilinx/xlnx,csi2rxss.yaml  | 226 ++
>  1 file changed, 226 insertions(+)
>  create mode 100644 
> Documentation/devicetree/bindings/media/xilinx/xlnx,csi2rxss.yaml
> 
> diff --git 
> a/Documentation/devicetree/bindings/media/xilinx/xlnx,csi2rxss.yaml 
> b/Documentation/devicetree/bindings/media/xilinx/xlnx,csi2rxss.yaml
> new file mode 100644
> index ..b0885f461785
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/media/xilinx/xlnx,csi2rxss.yaml
> @@ -0,0 +1,226 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/media/xilinx/xlnx,csi2rxss.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Xilinx MIPI CSI-2 Receiver Subsystem
> +
> +maintainers:
> +  - Vishal Sagar 
> +
> +description: |
> +  The Xilinx MIPI CSI-2 Receiver Subsystem is used to capture MIPI CSI-2
> +  traffic from compliant camera sensors and send the output as AXI4 Stream
> +  video data for image processing.
> +  The subsystem consists of a MIPI D-PHY in slave mode which captures the
> +  data packets. This is passed along the MIPI CSI-2 Rx IP which extracts the
> +  packet data. The optional Video Format Bridge (VFB) converts this data to
> +  AXI4 Stream video data.
> +  For more details, please refer to PG232 Xilinx MIPI CSI-2 Receiver 
> Subsystem.
> +  Please note that this bindings includes only the MIPI CSI-2 Rx controller
> +  and Video Format Bridge and not D-PHY.
> +
> +properties:
> +  compatible:
> +items:
> +  - enum:
> +- xlnx,mipi-csi2-rx-subsystem-5.0
> +
> +  reg:
> +maxItems: 1
> +
> +  interrupts:
> +maxItems: 1
> +
> +  clocks:
> +description: List of clock specifiers
> +items:
> +  - description: AXI Lite clock
> +  - description: Video clock
> +
> +  clock-names:
> +items:
> +  - const: lite_aclk
> +  - const: video_aclk
> +
> +  xlnx,csi-pxl-format:
> +description: |
> +  This denotes the CSI Data type selected in hw design.
> +  Packets other than this data type (except for RAW8 and
> +  User defined data types) will be filtered out.
> +  Possible values are as below -
> +  0x1e - YUV4228B
> +  0x1f - YUV42210B
> +  0x20 - RGB444
> +  0x21 - RGB555
> +  0x22 - RGB565
> +  0x23 - RGB666
> +  0x24 - RGB888
> +  0x28 - RAW6
> +  0x29 - RAW7
> +  0x2a - RAW8
> +  0x2b - RAW10
> +  0x2c - RAW12
> +  0x2d - RAW14
> +  0x2e - RAW16
> +  0x2f - RAW20
> +allOf:
> +  - $ref: /schemas/types.yaml#/definitions/uint32
> +  - anyOf:
> +- minimum: 0x1e
> +- maximum: 0x24
> +- minimum: 0x28
> +- maximum: 0x2f
> +
> +  xlnx,vfb:
> +type: boolean
> +description: Present when Video Format Bridge is enabled in IP 
> 

[PATCH] mm,thp: stop leaking unreleased file pages

2020-05-23 Thread Hugh Dickins
When collapse_file() calls try_to_release_page(), it has already
isolated the page: so if releasing buffers happens to fail (as it
sometimes does), remember to putback_lru_page(): otherwise that page is
left unreclaimable and unfreeable, and the file extent uncollapsible.

Signed-off-by: Hugh Dickins 
Fixes: 99cb0dbd47a1 ("mm,thp: add read-only THP support for (non-shmem) FS")
Cc: sta...@vger.kernel.org # v5.4+
---

 mm/khugepaged.c |1 +
 1 file changed, 1 insertion(+)

--- 5.7-rc6/mm/khugepaged.c 2020-04-12 16:24:37.710999073 -0700
+++ linux/mm/khugepaged.c   2020-05-10 17:06:21.788398646 -0700
@@ -1692,6 +1692,7 @@ static void collapse_file(struct mm_stru
if (page_has_private(page) &&
!try_to_release_page(page, GFP_KERNEL)) {
result = SCAN_PAGE_HAS_PRIVATE;
+   putback_lru_page(page);
goto out_unlock;
}
 


Re: [RFC PATCH v12 10/11] arm64: add mechanism to let user choose which counter to return

2020-05-23 Thread Richard Cochran
On Fri, May 22, 2020 at 04:37:23PM +0800, Jianyong Wu wrote:

> To use this feature, you should call PTP_EXTTS_REQUEST(2) ioctl with flag
> set bit PTP_KVM_ARM_PHY_COUNTER in its argument then call
> PTP_SYS_OFFSET_PRECISE(2) ioctl to get the cross timestamp and phyical
> counter will return. If the bit not set or no call for PTP_EXTTS_REQUEST2,
> virtual counter will return by default.

I'm sorry, but NAK on this completely bizarre twisting of the user
space API.

> diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c
> index fef72f29f3c8..8b0a7b328bcd 100644
> --- a/drivers/ptp/ptp_chardev.c
> +++ b/drivers/ptp/ptp_chardev.c
> @@ -123,6 +123,9 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, 
> unsigned long arg)
>   struct timespec64 ts;
>   int enable, err = 0;
>  
> +#ifdef CONFIG_ARM64
> + static long flag;
> +#endif
>   switch (cmd) {
>  
>   case PTP_CLOCK_GETCAPS:
> @@ -149,6 +152,24 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, 
> unsigned long arg)
>   err = -EFAULT;
>   break;
>   }
> +
> +#ifdef CONFIG_ARM64
> + /*
> +  * Just using this ioctl to tell kvm ptp driver to get PHC
> +  * with physical counter, so if bit PTP_KVM_ARM_PHY_COUNTER
> +  * is set then just exit directly.
> +  * In most cases, we just need virtual counter from host and
> +  * there is limited scenario using this to get physical counter
> +  * in guest.
> +  * Be careful to use this as there is no way to set it back
> +  * unless you reinstall the module.
> +  * This is only for arm64.
> +  */
> + if (req.extts.flags & PTP_KVM_ARM_PHY_COUNTER) {
> + flag = 1;
> + break;
> + }
> +#endif

This file contains the generic PTP Hardware Clock character device
implementation.  It is no place for platform specific hacks.

Sorry,
Richard


Re: [PATCH v12 1/2] media: dt-bindings: media: xilinx: Add Xilinx MIPI CSI-2 Rx Subsystem

2020-05-23 Thread Laurent Pinchart
Hi Vishal,

On Fri, May 08, 2020 at 01:52:36PM +, Vishal Sagar wrote:
> On Tuesday, May 5, 2020 7:53 PM, Laurent Pinchart wrote:
> > On Thu, Apr 23, 2020 at 09:00:37PM +0530, Vishal Sagar wrote:
> > > Add bindings documentation for Xilinx MIPI CSI-2 Rx Subsystem.
> > >
> > > The Xilinx MIPI CSI-2 Rx Subsystem consists of a CSI-2 Rx controller,
> > > a D-PHY in Rx mode and a Video Format Bridge.
> > >
> > > Signed-off-by: Vishal Sagar 
> > > Reviewed-by: Hyun Kwon 
> > > Reviewed-by: Rob Herring 
> > > Reviewed-by: Luca Ceresoli 
> > > ---
> > > v12
> > > - Moved to yaml format
> > > - Update CSI-2 and D-PHY
> > > - Mention that bindings for D-PHY not here
> > > - reset -> video-reset
> > >
> > > v11
> > > - Modify compatible string from 4.0 to 5.0
> > >
> > > v10
> > > - No changes
> > >
> > > v9
> > > - Fix xlnx,vfb description.
> > > - s/Optional/Required endpoint property.
> > > - Move data-lanes description from Ports to endpoint property section.
> > >
> > > v8
> > > - Added reset-gpios optional property to assert video_aresetn
> > >
> > > v7
> > > - Removed the control name from dt bindings
> > > - Updated the example dt node name to csi2rx
> > >
> > > v6
> > > - Added "control" after V4L2_CID_XILINX_MIPICSISS_ACT_LANES as
> > > suggested by Luca
> > > - Added reviewed by Rob Herring
> > >
> > > v5
> > > - Incorporated comments by Luca Cersoli
> > > - Removed DPHY clock from description and example
> > > - Removed bayer pattern from device tree MIPI CSI IP
> > >   doesn't deal with bayer pattern.
> > >
> > > v4
> > > - Added reviewed by Hyun Kwon
> > >
> > > v3
> > > - removed interrupt parent as suggested by Rob
> > > - removed dphy clock
> > > - moved vfb to optional properties
> > > - Added required and optional port properties section
> > > - Added endpoint property section
> > >
> > > v2
> > > - updated the compatible string to latest version supported
> > > - removed DPHY related parameters
> > > - added CSI v2.0 related property (including VCX for supporting upto 16
> > >   virtual channels).
> > > - modified csi-pxl-format from string to unsigned int type where the value
> > >   is as per the CSI specification
> > > - Defined port 0 and port 1 as sink and source ports.
> > > - Removed max-lanes property as suggested by Rob and Sakari
> > > .../bindings/media/xilinx/xlnx,csi2rxss.yaml  | 215 ++
> > >  1 file changed, 215 insertions(+)
> > >  create mode 100644
> > > Documentation/devicetree/bindings/media/xilinx/xlnx,csi2rxss.yaml
> > >
> > > diff --git
> > > a/Documentation/devicetree/bindings/media/xilinx/xlnx,csi2rxss.yaml
> > > b/Documentation/devicetree/bindings/media/xilinx/xlnx,csi2rxss.yaml
> > > new file mode 100644
> > > index ..365084e27f7e
> > > --- /dev/null
> > > +++ b/Documentation/devicetree/bindings/media/xilinx/xlnx,csi2rxss.yam
> > > +++ l
> > > @@ -0,0 +1,215 @@
> > > +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) %YAML 1.2
> > > +---
> > > +$id: http://devicetree.org/schemas/media/xilinx/xlnx,csi2rxss.yaml#
> > > +$schema: http://devicetree.org/meta-schemas/core.yaml#
> > > +
> > > +title: Xilinx MIPI CSI-2 Receiver Subsystem
> > > +
> > > +maintainers:
> > > +  - Vishal Sagar 
> > > +
> > > +description: |
> > > +  The Xilinx MIPI CSI-2 Receiver Subsystem is used to capture MIPI CSI-2
> > > +  traffic from compliant camera sensors and send the output as AXI4 
> > > Stream
> > > +  video data for image processing.
> > > +  The subsystem consists of a MIPI D-PHY in slave mode which captures the
> > > +  data packets. This is passed along the MIPI CSI-2 Rx IP which extracts 
> > > the
> > > +  packet data. The optional Video Format Bridge (VFB) converts this data 
> > > to
> > > +  AXI4 Stream video data.
> > > +  For more details, please refer to PG232 Xilinx MIPI CSI-2 Receiver 
> > > Subsystem.
> > > +  Please note that this bindings includes only the MIPI CSI-2 Rx 
> > > controller
> > > +  and Video Format Bridge and not D-PHY.
> > 
> > How should the D-PHY be handled, when DPY_EN_REG_IF is set to true ?
> 
> It was suggested in v3 to have a separate D-PHY phy driver which would be 
> initialized / configured from MIPI CSI-2 Rx driver.
> Currently with the D-PHY register interface enabled, we don't have to really 
> configure anything but the following parameters
> 1 - init
> 2 - hs_settle
> 3 - hs_timeout (High Speed mode timeout)  
> 4 - esc_timeout  (Escape mode timeout)
> 5 - idelay tap
> 
> The D-PHY Rx can be enabled/disabled and has a soft reset bit.
> The HS and Escape mode timeout registers can be enabled with a default value 
> via the Vivado IP GUI.
> 
> The above parameters would have to be passed to D-PHY driver as custom 
> control via MIPI CSI-2 Rx driver
> as these depend on the sensor connected.
> Probably these can be a new common control in V4L2 framework for CSI Rx 
> controllers.

It seems that in that case, regardless of whether we go for a separate
PHY driver or not, we will be able to extend the DT 

Re: [RFC PATCH v12 09/11] ptp: extend input argument for getcrosstimestamp API

2020-05-23 Thread Richard Cochran
On Fri, May 22, 2020 at 04:37:22PM +0800, Jianyong Wu wrote:
> sometimes we may need tell getcrosstimestamp call back how to perform
> itself. Extending input arguments for getcrosstimestamp API to offer more
> exquisite control for the operation.

This text does not offer any justification for the change in API.
 
> diff --git a/include/linux/ptp_clock_kernel.h 
> b/include/linux/ptp_clock_kernel.h
> index c602670bbffb..ba765647e54b 100644
> --- a/include/linux/ptp_clock_kernel.h
> +++ b/include/linux/ptp_clock_kernel.h
> @@ -133,7 +133,8 @@ struct ptp_clock_info {
>   int (*gettimex64)(struct ptp_clock_info *ptp, struct timespec64 *ts,
> struct ptp_system_timestamp *sts);
>   int (*getcrosststamp)(struct ptp_clock_info *ptp,
> -   struct system_device_crosststamp *cts);
> +   struct system_device_crosststamp *cts,
> +   long *flag);

Well, you ignored the kernel doc completely.  But in any case, I must
NAK this completely opaque and mysterious change.  You want to add a
random pointer to some flag?  I don't think so.

Thanks,
Richard




Re: [PATCH V4 13/17] arm64/cpufeature: Add remaining feature bits in ID_AA64MMFR1 register

2020-05-23 Thread Anshuman Khandual



On 05/19/2020 07:14 PM, Suzuki K Poulose wrote:
> On 05/19/2020 10:40 AM, Anshuman Khandual wrote:
>> Enable ETS, TWED, XNX and SPECSEI features bits in ID_AA64MMFR1 register as
>> per ARM DDI 0487F.a specification.
>>
>> Cc: Catalin Marinas 
>> Cc: Will Deacon 
>> Cc: Mark Rutland 
>> Cc: Suzuki K Poulose 
>> Cc: linux-arm-ker...@lists.infradead.org
>> Cc: linux-kernel@vger.kernel.org
>>
>> Suggested-by: Will Deacon 
>> Signed-off-by: Anshuman Khandual 
>> ---
>>   arch/arm64/include/asm/sysreg.h | 4 
>>   arch/arm64/kernel/cpufeature.c  | 4 
>>   2 files changed, 8 insertions(+)
>>
>> diff --git a/arch/arm64/include/asm/sysreg.h 
>> b/arch/arm64/include/asm/sysreg.h
>> index 95fdfc5e9bd0..f9dd2c5ab074 100644
>> --- a/arch/arm64/include/asm/sysreg.h
>> +++ b/arch/arm64/include/asm/sysreg.h
>> @@ -734,6 +734,10 @@
>>   #endif
>>     /* id_aa64mmfr1 */
>> +#define ID_AA64MMFR1_ETS_SHIFT    36
>> +#define ID_AA64MMFR1_TWED_SHIFT    32
>> +#define ID_AA64MMFR1_XNX_SHIFT    28
>> +#define ID_AA64MMFR1_SPECSEI_SHIFT    24
>>   #define ID_AA64MMFR1_PAN_SHIFT    20
>>   #define ID_AA64MMFR1_LOR_SHIFT    16
>>   #define ID_AA64MMFR1_HPD_SHIFT    12
>> diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
>> index 7ce19f97ba73..1f10ff7df705 100644
>> --- a/arch/arm64/kernel/cpufeature.c
>> +++ b/arch/arm64/kernel/cpufeature.c
>> @@ -299,6 +299,10 @@ static const struct arm64_ftr_bits ftr_id_aa64mmfr0[] = 
>> {
>>   };
>>     static const struct arm64_ftr_bits ftr_id_aa64mmfr1[] = {
>> +    ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 
>> ID_AA64MMFR1_ETS_SHIFT, 4, 0),
>> +    ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 
>> ID_AA64MMFR1_TWED_SHIFT, 4, 0),
>> +    ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 
>> ID_AA64MMFR1_XNX_SHIFT, 4, 0),
>> +    ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 
>> ID_AA64MMFR1_SPECSEI_SHIFT, 4, 0),
> 
> SpecSEI must be HIGHER_SAFE, like we did for MMFR4 ?

Sure, will change.


Re: [PATCH V4 15/17] arm64/cpufeature: Add remaining feature bits in ID_AA64DFR0 register

2020-05-23 Thread Anshuman Khandual



On 05/20/2020 07:27 PM, Suzuki K Poulose wrote:
> On 05/19/2020 10:40 AM, Anshuman Khandual wrote:
>> Enable MTPMU and TRACEFILT features bits in ID_AA64DFR0 register as per ARM
>> DDI 0487F.a specification.
>>
>> Cc: Catalin Marinas 
>> Cc: Will Deacon 
>> Cc: Mark Rutland 
>> Cc: Suzuki K Poulose 
>> Cc: linux-arm-ker...@lists.infradead.org
>> Cc: linux-kernel@vger.kernel.org
>>
>> Suggested-by: Will Deacon 
>> Signed-off-by: Anshuman Khandual 
>> ---
>>   arch/arm64/include/asm/sysreg.h | 2 ++
>>   arch/arm64/kernel/cpufeature.c  | 2 ++
>>   2 files changed, 4 insertions(+)
>>
>> diff --git a/arch/arm64/include/asm/sysreg.h 
>> b/arch/arm64/include/asm/sysreg.h
>> index a572069ccf6e..4bcd21cc2d68 100644
>> --- a/arch/arm64/include/asm/sysreg.h
>> +++ b/arch/arm64/include/asm/sysreg.h
>> @@ -766,6 +766,8 @@
>>   #define ID_AA64MMFR2_CNP_SHIFT    0
>>     /* id_aa64dfr0 */
>> +#define ID_AA64DFR0_MTPMU_SHIFT    48
>> +#define ID_AA64DFR0_TRACEFILT_SHIFT    40
>>   #define ID_AA64DFR0_PMSVER_SHIFT    32
>>   #define ID_AA64DFR0_CTX_CMPS_SHIFT    28
>>   #define ID_AA64DFR0_WRPS_SHIFT    20
>> diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
>> index 6338151f263c..986974be0178 100644
>> --- a/arch/arm64/kernel/cpufeature.c
>> +++ b/arch/arm64/kernel/cpufeature.c
>> @@ -366,6 +366,8 @@ static const struct arm64_ftr_bits ftr_id_mmfr0[] = {
>>   };
>>     static const struct arm64_ftr_bits ftr_id_aa64dfr0[] = {
>> +    S_ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 
>> ID_AA64DFR0_MTPMU_SHIFT, 4, 0),
>> +    ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 
>> ID_AA64DFR0_TRACEFILT_SHIFT, 4, 0),
> 
> We maske both the fields for KVM in AArch32 ID registers. We should do the 
> same here.

MTPMU is defined for AArch32 ID register ID_DFR1_EL1, even though the
entire register is hidden from KVM with ID_HIDDEN().

static const struct arm64_ftr_bits ftr_id_dfr1[] = {
S_ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 
ID_DFR1_MTPMU_SHIFT, 4, 0),
ARM64_FTR_END,
};

Should the ID_AA64DFR0_EL1 be hidden from KVM as well. But it has many
other existing features apart from MTPMU and TRACEFILT which are being
added here.


Re: [PATCH] mm/compaction: avoid VM_BUG_ON(PageSlab()) in page_mapcount()

2020-05-23 Thread Hugh Dickins
On Wed, 13 May 2020, Konstantin Khlebnikov wrote:

> Function isolate_migratepages_block() runs some checks out of lru_lock
> when choose pages for migration. After checking PageLRU() it checks extra
> page references by comparing page_count() and page_mapcount(). Between
> these two checks page could be removed from lru, freed and taken by slab.
> 
> As a result this race triggers VM_BUG_ON(PageSlab()) in page_mapcount().
> Race window is tiny. For certain workload this happens around once a year.

Around once a year, that was my guess too. I have no record of us ever
hitting this, but yes it could happen when you have CONFIG_DEBUG_VM=y
(which I too like to run with, but would not recommend for users).

> 
> 
>  page:ea0105ca9380 count:1 mapcount:0 mapping:88ff7712c180 index:0x0 
> compound_mapcount: 0
>  flags: 0x5008100(slab|head)
>  raw: 05008100 dead0100 dead0200 88ff7712c180
>  raw:  80200020 0001 
>  page dumped because: VM_BUG_ON_PAGE(PageSlab(page))
>  [ cut here ]
>  kernel BUG at ./include/linux/mm.h:628!
>  invalid opcode:  [#1] SMP NOPTI
>  CPU: 77 PID: 504 Comm: kcompactd1 Tainted: GW 4.19.109-27 #1
>  Hardware name: Yandex T175-N41-Y3N/MY81-EX0-Y3N, BIOS R05 06/20/2019
>  RIP: 0010:isolate_migratepages_block+0x986/0x9b0
> 
> 
> To fix just opencode page_mapcount() in racy check for 0-order case and
> recheck carefully under lru_lock when page cannot escape from lru.
> 
> Also add checking extra references for file pages and swap cache.
> 
> Signed-off-by: Konstantin Khlebnikov 
> Fixes: 119d6d59dcc0 ("mm, compaction: avoid isolating pinned pages")

Not really, that commit was correct at the time it went in.

> Fixes: 1d148e218a0d ("mm: add VM_BUG_ON_PAGE() to page_mapcount()")

Exactly, that commit was well-intentioned, but did not allow for this
(admittedly very exceptional) usage.  How many developers actually
make the mistake of applying page_mapcount() to their slab pages?
None, I expect.  That VM_BUG_ON_PAGE() is there for documentation,
and could just be replaced by a comment - and Linus would be happy
with that.

> ---
>  mm/compaction.c |   17 +
>  1 file changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/mm/compaction.c b/mm/compaction.c
> index 46f0fcc93081..91bb87fd9420 100644
> --- a/mm/compaction.c
> +++ b/mm/compaction.c
> @@ -935,12 +935,16 @@ isolate_migratepages_block(struct compact_control *cc, 
> unsigned long low_pfn,
>   }
>  
>   /*
> -  * Migration will fail if an anonymous page is pinned in memory,
> +  * Migration will fail if an page is pinned in memory,
>* so avoid taking lru_lock and isolating it unnecessarily in an
> -  * admittedly racy check.
> +  * admittedly racy check simplest case for 0-order pages.
> +  *
> +  * Open code page_mapcount() to avoid VM_BUG_ON(PageSlab(page)).

But open coding page_mapcount() is not all that you did.  You have
(understandably) chosen to avoid calling page_mapping(page), but...

> +  * Page could have extra reference from mapping or swap cache.
>*/
> - if (!page_mapping(page) &&
> - page_count(page) > page_mapcount(page))
> + if (!PageCompound(page) &&
> + page_count(page) > atomic_read(>_mapcount) + 1 +
> + (!PageAnon(page) || PageSwapCache(page)))
>   goto isolate_fail;

Isn't that test going to send all the file cache pages with buffer heads
in page->private, off to isolate_fail when they're actually great
candidates for migration?

Given that the actual bug spotted was with the VM_BUG_ON_PAGE(PageSlab),
and nobody has reported any crash from the use of page_mapping() there
(and we only need the test to be right most of the time: all of this 
knowingly racy, as you explain in other mail): I'd go for just replacing
the VM_BUG_ON_PAGE in page_mapcount() by a comment about this case.

But if you think developers are really in danger of coding page_mapcount()
on their slab pages, then you could add a _page_mapcount() to linux/mm.h,
which omits the VM_BUG_ON_PAGE, for use here only.

Then we wouldn't have to think so hard about the counting above!

>  
>   /*
> @@ -975,6 +979,11 @@ isolate_migratepages_block(struct compact_control *cc, 
> unsigned long low_pfn,
>   low_pfn += compound_nr(page) - 1;
>   goto isolate_fail;
>   }
> +
> + /* Recheck page extra references under lock */
> + if (page_count(page) > page_mapcount(page) +
> + (!PageAnon(page) || PageSwapCache(page)))
> + goto isolate_fail;

Well, that lru_lock (and the intervening 

kernel/livepatch/../sched/sched.h:1619:25: sparse: sparse: incompatible types in comparison expression (different address spaces):

2020-05-23 Thread kbuild test robot
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
master
head:   0cfc8a8d70dcd51db783e8e87917e02149c71458
commit: 4104a562e0ca62e971089db9d3c47794a0d7d4eb sched/core: Annotate curr 
pointer in rq with __rcu
date:   3 months ago
config: x86_64-randconfig-s002-20200524 (attached as .config)
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
reproduce:
# apt-get install sparse
# sparse version: v0.6.1-193-gb8fad4bc-dirty
git checkout 4104a562e0ca62e971089db9d3c47794a0d7d4eb
# save the attached .config to linux build tree
make W=1 C=1 ARCH=x86_64 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot 


sparse warnings: (new ones prefixed by >>)

>> kernel/livepatch/../sched/sched.h:1619:25: sparse: sparse: incompatible 
>> types in comparison expression (different address spaces):
>> kernel/livepatch/../sched/sched.h:1619:25: sparse:struct task_struct 
>> [noderef]  *
>> kernel/livepatch/../sched/sched.h:1619:25: sparse:struct task_struct *

vim +1619 kernel/livepatch/../sched/sched.h

029632fbb7b7c9 kernel/sched.h Peter Zijlstra 2011-10-25  1616  
029632fbb7b7c9 kernel/sched.h Peter Zijlstra 2011-10-25  1617  static inline 
int task_current(struct rq *rq, struct task_struct *p)
029632fbb7b7c9 kernel/sched.h Peter Zijlstra 2011-10-25  1618  {
029632fbb7b7c9 kernel/sched.h Peter Zijlstra 2011-10-25 @1619   return rq->curr 
== p;
029632fbb7b7c9 kernel/sched.h Peter Zijlstra 2011-10-25  1620  }
029632fbb7b7c9 kernel/sched.h Peter Zijlstra 2011-10-25  1621  

:: The code at line 1619 was first introduced by commit
:: 029632fbb7b7c9d85063cc9eb470de6c54873df3 sched: Make separate sched*.c 
translation units

:: TO: Peter Zijlstra 
:: CC: Ingo Molnar 

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org


.config.gz
Description: application/gzip


RE: [PATCH] thermal: imx8mm: Add get_trend ops

2020-05-23 Thread Anson Huang
Hi, Daniel

> Subject: Re: [PATCH] thermal: imx8mm: Add get_trend ops
> 
> On 23/05/2020 02:35, Anson Huang wrote:
> > Hi, Daniel
> >
> >
> >> Subject: Re: [PATCH] thermal: imx8mm: Add get_trend ops
> >>
> >> On 13/05/2020 04:58, Anson Huang wrote:
> >>> Add get_trend ops for i.MX8MM thermal to apply fast cooling
> >>> mechanism, when temperature exceeds passive trip point, the highest
> >>> cooling action will be applied, and when temperature drops to lower
> >>> than the margin below passive trip point, the lowest cooling action
> >>> will be applied.
> >>
> >> You are not describing what is the goal of this change.
> >
> > The goal of this change is to make sure whenever temperature exceeds
> > passive trip point, the highest cooling action will be applied
> > immediately, e.g., if there are many cpufreq OPP, the default cooling
> > will be step by step, it will take some more rounds to make cpufreq drop to
> lowest OPP, while on i.MX, we expect the cpufreq drop to lowest OPP
> immediately.
> 
> Whatever the slope of the temperature increase?

Yes.

> 
> >> IIUC, the resulting change will be an on/off action. The thermal zone
> >> is mitigated with the highest cooling effect, so the lowest OPP, then
> >> the temperature trend is stable until it goes below the trip - margin
> >> where the mitigation is stopped.
> >
> > Yes, your understanding is correctly, once the temperature exceeds
> > passive trip point, the highest cooling action will be applied
> > immediately and then it will be stable there until temperature drop to
> > trip - margin, then the cooling action will be cancelled, the margin is to 
> > avoid
> the back and forth near the passive trip point.
> >
> >>
> >> Except, I'm missing something, setting a trip point with a 1
> >> hysteresis and a cooling map min/max set to the highest opp will result on
> the same.
> >
> > Yes setting cooling map min/max cooling state to highest OPP will make
> > the highest cooling action applied immediately, and to have the
> > function of cooling action being cancelled when temperature drops to
> > trip - margin, I have to define another trip point, say passive trip
> > point is 85000, and cooling map min/max set to highest OPP in passive
> > trip point then add another trip point named "active" with 75000, and
> without any cooling map in it, right?
> 
> May be I misunderstood but only the change as below is needed. No need to
> add a trip point, especially an 'active' trip which is a for an active cooling
> device like a fan.
> 
> diff --git a/arch/arm64/boot/dts/freescale/imx8mm.dtsi
> b/arch/arm64/boot/dts/freescale/imx8mm.dtsi
> index cc7152ecedd9..bea263bd06b4 100644
> --- a/arch/arm64/boot/dts/freescale/imx8mm.dtsi
> +++ b/arch/arm64/boot/dts/freescale/imx8mm.dtsi
> @@ -231,10 +231,10 @@ cooling-maps {
>   map0 {
>   trip = <_alert0>;
>   cooling-device =
> - <_0 THERMAL_NO_LIMIT
> THERMAL_NO_LIMIT>,
> - <_1 THERMAL_NO_LIMIT
> THERMAL_NO_LIMIT>,
> - <_2 THERMAL_NO_LIMIT
> THERMAL_NO_LIMIT>,
> - <_3 THERMAL_NO_LIMIT
> THERMAL_NO_LIMIT>;
> + <_0 2 2>,
> + <_1 2 2>,
> + <_2 2 2>,
> + <_3 2 2>
>   };
>   };
>   };
> 
> 

Thanks, I will have a try to see if it meets our expectation.

Anson


Re: [PATCH] x86/reboot/quirks: Add MacBook6,1 reboot quirk

2020-05-23 Thread Hill Ma



gentle ping again and happy weekend to all :)




Re: [PATCH -next] pwm: pca9685: Remove set but not used variable 'pwm'

2020-05-23 Thread Sven Van Asbroeck
Hi Uwe,

On Sat, May 23, 2020 at 4:17 PM Uwe Kleine-König
 wrote:
>
> Is this patch still relevant?

A slightly different version of this patch has already landed in
mainline. Clemens Gruber had
relevant hardware available, and was able to test it out.

See Linus's tree here:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/pwm/pwm-pca9685.c?h=v5.7-rc6=9cc5f232a4b6a0ef6e9b57876d61b88f61bdd7c2

Have a great week-end,
Sven


Re: [GIT] Networking

2020-05-23 Thread pr-tracker-bot
The pull request you sent on Sat, 23 May 2020 17:06:54 -0700 (PDT):

> git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git refs/heads/master

has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/caffb99b6929f41a69edbb5aef3a359bf45f3315

Thank you!

-- 
Deet-doot-dot, I am a bot.
https://korg.wiki.kernel.org/userdoc/prtracker


Re: [PATCH] sparc32: use PUD rather than PGD to get PMD in srmmu_nocache_init()

2020-05-23 Thread Linus Torvalds
On Sat, May 23, 2020 at 3:47 PM Guenter Roeck  wrote:
>
> This quite innocent looking patch crashes all my sparc32 boot tests.
> Crash log and bisect results below. Reverting it fixes the problem.

It should also fixed by 0cfc8a8d70dc ("sparc32: fix page table
traversal in srmmu_nocache_init()"). No?

 Linus


[GIT] Networking

2020-05-23 Thread David Miller


1) Fix RCU warnings in ipv6 multicast router code, from Madhuparna Bhowmik.

2) Nexthop attributes aren't being checked properly because of
   mis-initialized iterator, from David Ahern.

3) Revert iop_idents_reserve() change as it caused performance
   regressions and was just working around what is really a UBSAN bug
   in the compiler.  From Yuqi Jin.

4) Read MAC address properly from ROM in bmac driver (double iteration
   proceeds past end of address array), from Jeremy Kerr.

5) Add Microsoft Surface device IDs to r8152, from Marc Payne.

6) Prevent reference to freed SKB in __netif_receive_skb_core(), from
   Boris Sukholitko.

7) Fix ACK discard behavior in rxrpc, from David Howells.

8) Preserve flow hash across packet scrubbing in wireguard, from
   Jason A. Donenfeld.

9) Cap option length properly for SO_BINDTODEVICE in AX25, from Eric
   Dumazet.

10) Fix encryption error checking in kTLS code, from Vadim Fedorenko.

11) Missing BPF prog ref release in flow dissector, from Jakub
Sitnicki.

12) dst_cache must be used with BH disabled in tipc, from Eric Dumazet.

13) Fix use after free in mlxsw driver, from Jiri Pirko.

14) Order kTLS key destruction properly in mlx5 driver, from Tariq
Toukan.

15) Check devm_platform_ioremap_resource() return value properly in several
drivers, from Tiezhu Yang.

Please pull, thanks a lot!

The following changes since commit f85c1598ddfe83f61d0656bd1d2025fa3b148b99:

  Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net (2020-05-15 
13:10:06 -0700)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git 

for you to fetch changes up to 539d39ad0c61b35f69565a037d7586deaf6d6166:

  net: smsc911x: Fix runtime PM imbalance on error (2020-05-23 16:52:17 -0700)


Alex Elder (1):
  net: ipa: don't be a hog in gsi_channel_poll()

Amit Cohen (1):
  selftests: mlxsw: qos_mc_aware: Specify arping timeout as an integer

Andrii Nakryiko (1):
  bpf: Prevent mmap()'ing read-only maps as writable

Antoine Tenart (1):
  net: phy: mscc: fix initialization of the MACsec protocol mode

Boris Sukholitko (1):
  __netif_receive_skb_core: pass skb by reference

Claudiu Manoil (1):
  felix: Fix initialization of ioremap resources

DENG Qingfang (1):
  net: dsa: mt7530: fix roaming from DSA user ports

David Ahern (1):
  nexthop: Fix attribute checking for groups

David Howells (4):
  rxrpc: Fix the excessive initial retransmission timeout
  rxrpc: Trace discarded ACKs
  rxrpc: Fix ack discard
  rxrpc: Fix a warning

David S. Miller (10):
  Merge tag 'wireless-drivers-2020-05-19' of 
git://git.kernel.org/.../kvalo/wireless-drivers
  Merge branch 'wireguard-fixes'
  Merge branch 'net-ethernet-ti-fix-some-return-value-check'
  Merge branch 'net-tls-fix-encryption-error-path'
  Merge git://git.kernel.org/.../bpf/bpf
  Merge tag 'rxrpc-fixes-20200520' of 
git://git.kernel.org/.../dhowells/linux-fs
  Merge branch 'netdevsim-Two-small-fixes'
  Merge branch 'mlxsw-Various-fixes'
  Merge tag 'rxrpc-fixes-20200523-v2' of 
git://git.kernel.org/.../dhowells/linux-fs
  Merge tag 'mlx5-fixes-2020-05-22' of git://git.kernel.org/.../saeed/linux

Dinghao Liu (1):
  net: smsc911x: Fix runtime PM imbalance on error

Eran Ben Elisha (2):
  net/mlx5: Fix a race when moving command interface to events mode
  net/mlx5: Avoid processing commands before cmdif is ready

Eric Dumazet (2):
  ax25: fix setsockopt(SO_BINDTODEVICE)
  tipc: block BH before using dst_cache

Grygorii Strashko (1):
  net: ethernet: ti: cpsw: fix ASSERT_RTNL() warning during suspend

Heiner Kallweit (1):
  r8169: fix OCP access on RTL8117

Ido Schimmel (2):
  netdevsim: Ensure policer drop counter always increases
  selftests: netdevsim: Always initialize 'RET' variable

Jakub Sitnicki (1):
  flow_dissector: Drop BPF flow dissector prog ref on netns cleanup

Jason A. Donenfeld (4):
  wireguard: selftests: use newer iproute2 for gcc-10
  wireguard: noise: read preshared key while taking lock
  wireguard: queueing: preserve flow hash across packet scrubbing
  wireguard: noise: separate receive counter from send counter

Jere Leppänen (1):
  sctp: Start shutdown on association restart if in SHUTDOWN-SENT state and 
socket is closed

Jeremy Kerr (1):
  net: bmac: Fix read of MAC address from ROM

Jiri Pirko (1):
  mlxsw: spectrum: Fix use-after-free of split/unsplit/type_set in case 
reload fails

Jonathan McDowell (1):
  net: ethernet: stmmac: Enable interface clocks on probe for IPQ806x

KP Singh (1):
  security: Fix hook iteration for secid_to_secctx

Kurt Kanzenbach (1):
  dt-bindings: net: dsa: b53: Add missing size and address cells to example

Leon Romanovsky (1):
  net: phy: propagate an error back to the callers

Re: [PATCH v3 3/3] vfio-pci: Invalidate mmaps and block MMIO access on disabled memory

2020-05-23 Thread Peter Xu
(CC Andrea too)

On Sat, May 23, 2020 at 07:52:57PM -0400, Peter Xu wrote:
> On Sat, May 23, 2020 at 05:06:02PM -0600, Alex Williamson wrote:
> > On Sat, 23 May 2020 15:34:17 -0400
> > Peter Xu  wrote:
> > 
> > > Hi, Alex,
> > > 
> > > On Fri, May 22, 2020 at 01:17:43PM -0600, Alex Williamson wrote:
> > > > @@ -1346,15 +1526,32 @@ static vm_fault_t vfio_pci_mmap_fault(struct 
> > > > vm_fault *vmf)
> > > >  {
> > > > struct vm_area_struct *vma = vmf->vma;
> > > > struct vfio_pci_device *vdev = vma->vm_private_data;
> > > > +   vm_fault_t ret = VM_FAULT_NOPAGE;
> > > > +
> > > > +   mutex_lock(>vma_lock);
> > > > +   down_read(>memory_lock);  
> > > 
> > > I remembered to have seen the fault() handling FAULT_FLAG_RETRY_NOWAIT at 
> > > least
> > > in the very first version, but it's not here any more...  Could I ask 
> > > what's
> > > the reason behind?  I probably have missed something along with the 
> > > versions,
> > > I'm just not sure whether e.g. this would potentially block a GUP caller 
> > > even
> > > if it's with FOLL_NOWAIT.
> > 
> > This is largely what v2 was about, from the cover letter:
> > 
> > Locking in 3/ is substantially changed to avoid the retry scenario
> > within the fault handler, therefore a caller who does not allow
> > retry will no longer receive a SIGBUS on contention.
> > 
> > The discussion thread starts here:
> > 
> > https://lore.kernel.org/kvm/20200501234849.gq26...@ziepe.ca/
> 
> [1]
> 
> > 
> > Feel free to interject if there's something that doesn't make sense,
> > the idea is that since we've fixed the lock ordering we never need to
> > release one lock to wait for another, therefore we can wait for the
> > lock.  I'm under the impression that we can wait for the lock
> > regardless of the flags under these conditions.
> 
> I see; thanks for the link.  Sorry I should probably follow up the discussion
> and ask the question earlier, anyway...
> 
> For what I understand now, IMHO we should still need all those handlings of
> FAULT_FLAG_RETRY_NOWAIT like in the initial version.  E.g., IIUC KVM gup will
> try with FOLL_NOWAIT when async is allowed, before the complete slow path.  
> I'm
> not sure what would be the side effect of that if fault() blocked it.  E.g.,
> the caller could be in an atomic context.
> 
> But now I also agree that VM_FAULT_SIGBUS is probably not correct there in the
> initial version [1] - I thought it was OK initially (after all after the
> multiple fault retry series we should always be with 
> FAULT_FLAG_ALLOW_RETRY..).
> However after some thinking... it should be the common slow path where retry 
> is
> simply not allowed.  So IMHO instead of SIGBUS there, we should also use all
> the slow path of the locks.  That'll be safe then because it's never going to
> be with FAULT_FLAG_RETRY_NOWAIT (FAULT_FLAG_RETRY_NOWAIT depends on
> FAULT_FLAG_ALLOW_RETRY).
> 
> A reference code could be __lock_page_or_retry() where the lock_page could 
> wait
> just like we taking the sems/mutexes, and the previous SIGBUS case would
> corresponds to this chunk of __lock_page_or_retry():
> 
>   } else {
>   if (flags & FAULT_FLAG_KILLABLE) {
>   int ret;
> 
>   ret = __lock_page_killable(page);
>   if (ret) {
>   up_read(>mmap_sem);
>   return 0;
>   }
>   } else
>   __lock_page(page);
>   return 1;
>   }
> 
> Thanks,
> 
> -- 
> Peter Xu

-- 
Peter Xu



Re: [PATCH v2 0/5] net: provide a devres variant of register_netdev()

2020-05-23 Thread David Miller
From: Bartosz Golaszewski 
Date: Sat, 23 May 2020 15:27:06 +0200

> From: Bartosz Golaszewski 
> 
> Using devres helpers allows to shrink the probing code, avoid memory leaks in
> error paths make sure the order in which resources are freed is the exact
> opposite of their allocation. This series proposes to add a devres variant
> of register_netdev() that will only work with net_device structures whose
> memory is also managed.
> 
> First we add the missing documentation entry for the only other networking
> devres helper: devm_alloc_etherdev().
> 
> Next we move devm_alloc_etherdev() into a separate source file.
> 
> We then use a proxy structure in devm_alloc_etherdev() to improve readability.
> 
> Last: we implement devm_register_netdev() and use it in mtk-eth-mac driver.
> 
> v1 -> v2:
> - rebase on top of net-next after driver rename, no functional changes

Series applied, thank you.


Re: [PATCH v3 3/3] vfio-pci: Invalidate mmaps and block MMIO access on disabled memory

2020-05-23 Thread Peter Xu
On Sat, May 23, 2020 at 05:06:02PM -0600, Alex Williamson wrote:
> On Sat, 23 May 2020 15:34:17 -0400
> Peter Xu  wrote:
> 
> > Hi, Alex,
> > 
> > On Fri, May 22, 2020 at 01:17:43PM -0600, Alex Williamson wrote:
> > > @@ -1346,15 +1526,32 @@ static vm_fault_t vfio_pci_mmap_fault(struct 
> > > vm_fault *vmf)
> > >  {
> > >   struct vm_area_struct *vma = vmf->vma;
> > >   struct vfio_pci_device *vdev = vma->vm_private_data;
> > > + vm_fault_t ret = VM_FAULT_NOPAGE;
> > > +
> > > + mutex_lock(>vma_lock);
> > > + down_read(>memory_lock);  
> > 
> > I remembered to have seen the fault() handling FAULT_FLAG_RETRY_NOWAIT at 
> > least
> > in the very first version, but it's not here any more...  Could I ask what's
> > the reason behind?  I probably have missed something along with the 
> > versions,
> > I'm just not sure whether e.g. this would potentially block a GUP caller 
> > even
> > if it's with FOLL_NOWAIT.
> 
> This is largely what v2 was about, from the cover letter:
> 
> Locking in 3/ is substantially changed to avoid the retry scenario
> within the fault handler, therefore a caller who does not allow
> retry will no longer receive a SIGBUS on contention.
> 
> The discussion thread starts here:
> 
> https://lore.kernel.org/kvm/20200501234849.gq26...@ziepe.ca/

[1]

> 
> Feel free to interject if there's something that doesn't make sense,
> the idea is that since we've fixed the lock ordering we never need to
> release one lock to wait for another, therefore we can wait for the
> lock.  I'm under the impression that we can wait for the lock
> regardless of the flags under these conditions.

I see; thanks for the link.  Sorry I should probably follow up the discussion
and ask the question earlier, anyway...

For what I understand now, IMHO we should still need all those handlings of
FAULT_FLAG_RETRY_NOWAIT like in the initial version.  E.g., IIUC KVM gup will
try with FOLL_NOWAIT when async is allowed, before the complete slow path.  I'm
not sure what would be the side effect of that if fault() blocked it.  E.g.,
the caller could be in an atomic context.

But now I also agree that VM_FAULT_SIGBUS is probably not correct there in the
initial version [1] - I thought it was OK initially (after all after the
multiple fault retry series we should always be with FAULT_FLAG_ALLOW_RETRY..).
However after some thinking... it should be the common slow path where retry is
simply not allowed.  So IMHO instead of SIGBUS there, we should also use all
the slow path of the locks.  That'll be safe then because it's never going to
be with FAULT_FLAG_RETRY_NOWAIT (FAULT_FLAG_RETRY_NOWAIT depends on
FAULT_FLAG_ALLOW_RETRY).

A reference code could be __lock_page_or_retry() where the lock_page could wait
just like we taking the sems/mutexes, and the previous SIGBUS case would
corresponds to this chunk of __lock_page_or_retry():

} else {
if (flags & FAULT_FLAG_KILLABLE) {
int ret;

ret = __lock_page_killable(page);
if (ret) {
up_read(>mmap_sem);
return 0;
}
} else
__lock_page(page);
return 1;
}

Thanks,

-- 
Peter Xu



Re: [PATCH] net: smsc911x: Fix runtime PM imbalance on error

2020-05-23 Thread David Miller
From: Dinghao Liu 
Date: Sat, 23 May 2020 16:08:20 +0800

> Remove runtime PM usage counter decrement when the
> increment function has not been called to keep the
> counter balanced.
> 
> Signed-off-by: Dinghao Liu 

Applied, thank you.


Re: [PATCH net-next v2] net: psample: fix build error when CONFIG_INET is not enabled

2020-05-23 Thread David Miller
From: Randy Dunlap 
Date: Fri, 22 May 2020 13:05:26 -0700

> From: Randy Dunlap 
> 
> Fix psample build error when CONFIG_INET is not set/enabled by
> bracketing the tunnel code in #ifdef CONFIG_NET / #endif.
> 
> ../net/psample/psample.c: In function ‘__psample_ip_tun_to_nlattr’:
> ../net/psample/psample.c:216:25: error: implicit declaration of function 
> ‘ip_tunnel_info_opts’; did you mean ‘ip_tunnel_info_opts_set’? 
> [-Werror=implicit-function-declaration]
> 
> Signed-off-by: Randy Dunlap 
> Cc: Yotam Gigi 
> Cc: Cong Wang 
> ---
> v2: Just bracket the new tunnel support code inside ifdef/endif (Cong Wang).

Applied, thanks Randy.


Re: lockdep trace with xfs + mm in it from 5.7.0-rc5

2020-05-23 Thread Dave Chinner
On Fri, May 22, 2020 at 01:43:08PM -0700, Darrick J. Wong wrote:
> On Fri, May 22, 2020 at 10:30:27AM +1000, Dave Chinner wrote:
> > On Thu, May 21, 2020 at 04:13:12PM -0700, Darrick J. Wong wrote:
> > > [cc linux-xfs]
> > > 
> > > On Fri, May 22, 2020 at 08:21:50AM +1000, Dave Airlie wrote:
> > > > Hi,
> > > > 
> > > > Just updated a rawhide VM to the Fedora 5.7.0-rc5 kernel, did some
> > > > package building,
> > > > 
> > > > got the below trace, not sure if it's known and fixed or unknown.
> > > 
> > > It's a known false-positive.  An inode can't simultaneously be getting
> > > reclaimed due to zero refcount /and/ be the target of a getxattr call.
> > > Unfortunately, lockdep can't tell the difference, and it seems a little
> > > strange to set NOFS on the allocation (which increases the chances of a
> > > runtime error) just to quiet that down.
> > 
> > __GFP_NOLOCKDEP is the intended flag to telling memory allocation
> > that lockdep is stupid.
> > 
> > However, it seems that the patches that were in progress some months
> > ago to convert XFS to kmalloc interfaces and using GFP flags
> > directly stalled - being able to mark locations like this with
> > __GFP_NOLOCKDEP was one of the main reasons for getting rid of all
> > the internal XFS memory allocation wrappers...
> 
> Question is, should I spend time adding a GFP_NOLOCKDEP bandaid to XFS
> or would my time be better spent reviewing your async inode reclaim
> series to make this go away for real?

Heh. I started to write that async reclaim would make this go away,
but then I realised it won't because we still do an XFS_ILOCK_EXCL
call in xfs_inode_reclaim() right at the end to synchronise with
anything that was blocked in the ILOCK during a lockless lookup
waiting for reclaim to drop the lock after setting ip->i_ino = 0.

So that patchset doesn't make the lockdep issues go away. I still
need to work out if we can get rid of that ILOCK cycling in
xfs_reclaim_inode() by changing the lockless lookup code, but that's
a separate problem...

Cheers,

Dave.
-- 
Dave Chinner
da...@fromorbit.com


Re: [PATCH v2] net/mlx4_core: fix a memory leak bug.

2020-05-23 Thread David Miller
From: wu000...@umn.edu
Date: Fri, 22 May 2020 14:07:15 -0500

> From: Qiushi Wu 
> 
> In function mlx4_opreq_action(), pointer "mailbox" is not released,
> when mlx4_cmd_box() return and error, causing a memory leak bug.
> Fix this issue by going to "out" label, mlx4_free_cmd_mailbox() can
> free this pointer.
> 
> Fixes: fe6f700d6cbb ("net/mlx4_core: Respond to operation request by 
> firmware")
> Signed-off-by: Qiushi Wu 

Applied.


Re: [PATCH] net: ethernet: ti: cpsw: fix ASSERT_RTNL() warning during suspend

2020-05-23 Thread David Miller
From: Grygorii Strashko 
Date: Fri, 22 May 2020 19:39:31 +0300

> vlan_for_each() are required to be called with rtnl_lock taken, otherwise
> ASSERT_RTNL() warning will be triggered - which happens now during System
> resume from suspend:
>   cpsw_suspend()
>   |- cpsw_ndo_stop()
> |- __hw_addr_ref_unsync_dev()
>   |- cpsw_purge_all_mc()
>  |- vlan_for_each()
> |- ASSERT_RTNL();
> 
> Hence, fix it by surrounding cpsw_ndo_stop() by rtnl_lock/unlock() calls.
> 
> Fixes: 15180eca569b net: ethernet: ti: cpsw: fix vlan mcast
> Signed-off-by: Grygorii Strashko 

Applied.


Re: [PATCH net v2] net: phy: mscc: fix initialization of the MACsec protocol mode

2020-05-23 Thread David Miller
From: Antoine Tenart 
Date: Fri, 22 May 2020 17:55:45 +0200

> At the very end of the MACsec block initialization in the MSCC PHY
> driver, the MACsec "protocol mode" is set. This setting should be set
> based on the PHY id within the package, as the bank used to access the
> register used depends on this. This was not done correctly, and only the
> first bank was used leading to the two upper PHYs being unstable when
> using the VSC8584. This patch fixes it.
> 
> Fixes: 1bbe0ecc2a1a ("net: phy: mscc: macsec initialization")
> Signed-off-by: Antoine Tenart 

Applied and queued up for -stable, thanks.


Re: [PATCH] net: stmmac: don't attach interface until resume finishes

2020-05-23 Thread David Miller
From: Leon Yu 
Date: Fri, 22 May 2020 23:29:43 +0800

> Commit 14b41a2959fb ("net: stmmac: Delete txtimer in suspend") was the
> first attempt to fix a race between mod_timer() and setup_timer()
> during stmmac_resume(). However the issue still exists as the commit
> only addressed half of the issue.
> 
> Same race can still happen as stmmac_resume() re-attaches interface
> way too early - even before hardware is fully initialized.  Worse,
> doing so allows network traffic to restart and stmmac_tx_timer_arm()
> being called in the middle of stmmac_resume(), which re-init tx timers
> in stmmac_init_coalesce().  timer_list will be corrupted and system
> crashes as a result of race between mod_timer() and setup_timer().
> 
>   systemd--19952 552950018us : stmmac_suspend: 4994
>   ksoftirq-9   0..s2 553123133us : stmmac_tx_timer_arm: 2276
>   systemd--19950 553127896us : stmmac_resume: 5101
>   systemd--320 7...2 553132752us : stmmac_tx_timer_arm: 2276
>   (sd-exec-19995...2 553135204us : stmmac_tx_timer_arm: 2276
>   -
>   pc : run_timer_softirq+0x468/0x5e0
>   lr : run_timer_softirq+0x570/0x5e0
>   Call trace:
>run_timer_softirq+0x468/0x5e0
>__do_softirq+0x124/0x398
>irq_exit+0xd8/0xe0
>__handle_domain_irq+0x6c/0xc0
>gic_handle_irq+0x60/0xb0
>el1_irq+0xb8/0x180
>arch_cpu_idle+0x38/0x230
>default_idle_call+0x24/0x3c
>do_idle+0x1e0/0x2b8
>cpu_startup_entry+0x28/0x48
>secondary_start_kernel+0x1b4/0x208
> 
> Fix this by deferring netif_device_attach() to the end of
> stmmac_resume().
> 
> Signed-off-by: Leon Yu 

Applied, thank you.


Re: [PATCH] net: Fix return value about devm_platform_ioremap_resource()

2020-05-23 Thread David Miller
From: Tiezhu Yang 
Date: Fri, 22 May 2020 19:03:21 +0800

> When call function devm_platform_ioremap_resource(), we should use IS_ERR()
> to check the return value and return PTR_ERR() if failed.
> 
> Signed-off-by: Tiezhu Yang 

Applied, thanks.


Re: [PATCH net-next] net: phy: at803x: fix PHY ID masks

2020-05-23 Thread David Miller
From: Michael Walle 
Date: Fri, 22 May 2020 11:53:31 +0200

> Ever since its first commit 0ca7111a38f05 ("phy: add AT803x driver") the
> PHY ID mask was set to 0xffef. It is unclear to me why this mask was
> chosen in the first place. Both the AR8031/AR8033 and the AR8035
> datasheets mention it is always the given value:
>  - for AR8031/AR8033 its 0x004d/0xd074
>  - for AR8035 its 0x004d/0xd072
> 
> Unfortunately, I don't have a datasheet for the AR8030. Therefore, we
> leave its PHY ID mask untouched. For the PHYs mentioned before use the
> handy PHY_ID_MATCH_EXACT() macro.
> 
> I've tried to contact the author of the initial commit, but received no
> answer so far.
> 
> Cc: Matus Ujhelyi 
> Signed-off-by: Michael Walle 

Applied, thank you.


Re: [PATCH v1 1/3] drm/msm: Attach the IOMMU device during initialization

2020-05-23 Thread Rob Clark
On Sat, May 23, 2020 at 12:23 AM Shawn Guo  wrote:
>
> On Fri, May 22, 2020 at 04:03:14PM -0600, Jordan Crouse wrote:
> > diff --git a/drivers/gpu/drm/msm/msm_gpummu.c 
> > b/drivers/gpu/drm/msm/msm_gpummu.c
> > index 34980d8eb7ad..0ad0f848560a 100644
> > --- a/drivers/gpu/drm/msm/msm_gpummu.c
> > +++ b/drivers/gpu/drm/msm/msm_gpummu.c
> > @@ -21,11 +21,6 @@ struct msm_gpummu {
> >  #define GPUMMU_PAGE_SIZE SZ_4K
> >  #define TABLE_SIZE (sizeof(uint32_t) * GPUMMU_VA_RANGE / GPUMMU_PAGE_SIZE)
> >
> > -static int msm_gpummu_attach(struct msm_mmu *mmu)
> > -{
> > - return 0;
> > -}
> > -
> >  static void msm_gpummu_detach(struct msm_mmu *mmu)
> >  {
> >  }
> > @@ -85,7 +80,6 @@ static void msm_gpummu_destroy(struct msm_mmu *mmu)
> >  }
> >
> >  static const struct msm_mmu_funcs funcs = {
> > - .attach = msm_gpummu_attach,
> >   .detach = msm_gpummu_detach,
> >   .map = msm_gpummu_map,
> >   .unmap = msm_gpummu_unmap,
> > diff --git a/drivers/gpu/drm/msm/msm_iommu.c 
> > b/drivers/gpu/drm/msm/msm_iommu.c
> > index ad58cfe5998e..e35dab5792cf 100644
> > --- a/drivers/gpu/drm/msm/msm_iommu.c
> > +++ b/drivers/gpu/drm/msm/msm_iommu.c
> > @@ -66,7 +66,6 @@ static void msm_iommu_destroy(struct msm_mmu *mmu)
> >  }
> >
> >  static const struct msm_mmu_funcs funcs = {
> > - .attach = msm_iommu_attach,
>
> It causes an unused function warning as below.
>
> drivers/gpu/drm/msm/msm_iommu.c:26:12: warning: ‘msm_iommu_attach’ defined 
> but not used [-Wunused-function]
>  static int msm_iommu_attach(struct msm_mmu *mmu)
> ^~~~
>
> Not sure if you will use it again in future patches though.

looks like this was removed in msm_gpummu (a2xx) but not msm_iommu
(a3xx+).. I've squashed a fixup and pushed to msm-next

thx

BR,
-R

> Shawn
>
> >   .detach = msm_iommu_detach,
> >   .map = msm_iommu_map,
> >   .unmap = msm_iommu_unmap,
> > @@ -76,6 +75,7 @@ static const struct msm_mmu_funcs funcs = {
> >  struct msm_mmu *msm_iommu_new(struct device *dev, struct iommu_domain 
> > *domain)
> >  {
> >   struct msm_iommu *iommu;
> > + int ret;
> >
> >   iommu = kzalloc(sizeof(*iommu), GFP_KERNEL);
> >   if (!iommu)
> > @@ -85,5 +85,11 @@ struct msm_mmu *msm_iommu_new(struct device *dev, struct 
> > iommu_domain *domain)
> >   msm_mmu_init(>base, dev, );
> >   iommu_set_fault_handler(domain, msm_fault_handler, iommu);
> >
> > + ret = iommu_attach_device(iommu->domain, dev);
> > + if (ret) {
> > + kfree(iommu);
> > + return ERR_PTR(ret);
> > + }
> > +
> >   return >base;
> >  }
> > diff --git a/drivers/gpu/drm/msm/msm_mmu.h b/drivers/gpu/drm/msm/msm_mmu.h
> > index 67a623f14319..bae9e8e67ec1 100644
> > --- a/drivers/gpu/drm/msm/msm_mmu.h
> > +++ b/drivers/gpu/drm/msm/msm_mmu.h
> > @@ -10,7 +10,6 @@
> >  #include 
> >
> >  struct msm_mmu_funcs {
> > - int (*attach)(struct msm_mmu *mmu);
> >   void (*detach)(struct msm_mmu *mmu);
> >   int (*map)(struct msm_mmu *mmu, uint64_t iova, struct sg_table *sgt,
> >   unsigned len, int prot);
> > --
> > 2.17.1
> >


Re: [PATCH v9 00/14] KVM: Dirty ring interface

2020-05-23 Thread Peter Xu
On Sat, May 23, 2020 at 06:56:45PM -0400, Peter Xu wrote:
> KVM branch:
>   https://github.com/xzpeter/linux/tree/kvm-dirty-ring
> 
> QEMU branch for testing:
>   https://github.com/xzpeter/qemu/tree/kvm-dirty-ring
> 
> v9:
> - patch 3: __x86_set_memory_region: squash another trivial change to return
>   (0xdeadull << 48) always for slot removal [Sean]
> - pick r-bs for Drew

Sorry to always have forgotten to add Drew in the CC list, so it would be a
partial series again...  It'll be there for the next post.  Thanks,

-- 
Peter Xu



[PATCH v9 13/14] KVM: selftests: Let dirty_log_test async for dirty ring test

2020-05-23 Thread Peter Xu
Previously the dirty ring test was working in synchronous way, because
only with a vmexit (with that it was the ring full event) we'll know
the hardware dirty bits will be flushed to the dirty ring.

With this patch we first introduced the vcpu kick mechanism by using
SIGUSR1, meanwhile we can have a guarantee of vmexit and also the
flushing of hardware dirty bits.  With all these, we can keep the vcpu
dirty work asynchronous of the whole collection procedure now.  Still,
we need to be very careful that we can only do it async if the vcpu is
not reaching soft limit (no KVM_EXIT_DIRTY_RING_FULL).  Otherwise we
must collect the dirty bits before continuing the vcpu.

Further increase the dirty ring size to current maximum to make sure
we torture more on the no-ring-full case, which should be the major
scenario when the hypervisors like QEMU would like to use this feature.

Reviewed-by: Andrew Jones 
Signed-off-by: Peter Xu 
---
 tools/testing/selftests/kvm/dirty_log_test.c  | 126 +-
 .../testing/selftests/kvm/include/kvm_util.h  |   1 +
 tools/testing/selftests/kvm/lib/kvm_util.c|   9 ++
 3 files changed, 106 insertions(+), 30 deletions(-)

diff --git a/tools/testing/selftests/kvm/dirty_log_test.c 
b/tools/testing/selftests/kvm/dirty_log_test.c
index 531431cff4fc..4b404dfdc2f9 100644
--- a/tools/testing/selftests/kvm/dirty_log_test.c
+++ b/tools/testing/selftests/kvm/dirty_log_test.c
@@ -13,6 +13,9 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -59,7 +62,9 @@
 # define test_and_clear_bit_le test_and_clear_bit
 #endif
 
-#define TEST_DIRTY_RING_COUNT  1024
+#define TEST_DIRTY_RING_COUNT  65536
+
+#define SIG_IPI SIGUSR1
 
 /*
  * Guest/Host shared variables. Ensure addr_gva2hva() and/or
@@ -135,6 +140,12 @@ static uint64_t host_track_next_count;
 /* Whether dirty ring reset is requested, or finished */
 static sem_t dirty_ring_vcpu_stop;
 static sem_t dirty_ring_vcpu_cont;
+/*
+ * This is updated by the vcpu thread to tell the host whether it's a
+ * ring-full event.  It should only be read until a sem_wait() of
+ * dirty_ring_vcpu_stop and before vcpu continues to run.
+ */
+static bool dirty_ring_vcpu_ring_full;
 
 enum log_mode_t {
/* Only use KVM_GET_DIRTY_LOG for logging */
@@ -156,6 +167,33 @@ enum log_mode_t {
 static enum log_mode_t host_log_mode_option = LOG_MODE_ALL;
 /* Logging mode for current run */
 static enum log_mode_t host_log_mode;
+static pthread_t vcpu_thread;
+
+/* Only way to pass this to the signal handler */
+static struct kvm_vm *current_vm;
+
+static void vcpu_sig_handler(int sig)
+{
+   TEST_ASSERT(sig == SIG_IPI, "unknown signal: %d", sig);
+}
+
+static void vcpu_kick(void)
+{
+   pthread_kill(vcpu_thread, SIG_IPI);
+}
+
+/*
+ * In our test we do signal tricks, let's use a better version of
+ * sem_wait to avoid signal interrupts
+ */
+static void sem_wait_until(sem_t *sem)
+{
+   int ret;
+
+   do
+   ret = sem_wait(sem);
+   while (ret == -1 && errno == EINTR);
+}
 
 static bool clear_log_supported(void)
 {
@@ -189,10 +227,13 @@ static void clear_log_collect_dirty_pages(struct kvm_vm 
*vm, int slot,
kvm_vm_clear_dirty_log(vm, slot, bitmap, 0, num_pages);
 }
 
-static void default_after_vcpu_run(struct kvm_vm *vm)
+static void default_after_vcpu_run(struct kvm_vm *vm, int ret, int err)
 {
struct kvm_run *run = vcpu_state(vm, VCPU_ID);
 
+   TEST_ASSERT(ret == 0 || (ret == -1 && err == EINTR),
+   "vcpu run failed: errno=%d", err);
+
TEST_ASSERT(get_ucall(vm, VCPU_ID, NULL) == UCALL_SYNC,
"Invalid guest sync status: exit_reason=%s\n",
exit_reason_str(run->exit_reason));
@@ -248,27 +289,37 @@ static uint32_t dirty_ring_collect_one(struct 
kvm_dirty_gfn *dirty_gfns,
return count;
 }
 
+static void dirty_ring_wait_vcpu(void)
+{
+   /* This makes sure that hardware PML cache flushed */
+   vcpu_kick();
+   sem_wait_until(_ring_vcpu_stop);
+}
+
+static void dirty_ring_continue_vcpu(void)
+{
+   pr_info("Notifying vcpu to continue\n");
+   sem_post(_ring_vcpu_cont);
+}
+
 static void dirty_ring_collect_dirty_pages(struct kvm_vm *vm, int slot,
   void *bitmap, uint32_t num_pages)
 {
/* We only have one vcpu */
static uint32_t fetch_index = 0;
uint32_t count = 0, cleared;
+   bool continued_vcpu = false;
 
-   /*
-* Before fetching the dirty pages, we need a vmexit of the
-* worker vcpu to make sure the hardware dirty buffers were
-* flushed.  This is not needed for dirty-log/clear-log tests
-* because get dirty log will natually do so.
-*
-* For now we do it in the simple way - we simply wait until
-* the vcpu uses up the soft dirty ring, then it'll always
-* do a vmexit to make sure that PML buffers will be 

[PATCH v9 14/14] KVM: selftests: Add "-c" parameter to dirty log test

2020-05-23 Thread Peter Xu
It's only used to override the existing dirty ring size/count.  If
with a bigger ring count, we test async of dirty ring.  If with a
smaller ring count, we test ring full code path.  Async is default.

It has no use for non-dirty-ring tests.

Reviewed-by: Andrew Jones 
Signed-off-by: Peter Xu 
---
 tools/testing/selftests/kvm/dirty_log_test.c | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/kvm/dirty_log_test.c 
b/tools/testing/selftests/kvm/dirty_log_test.c
index 4b404dfdc2f9..80c42c87265e 100644
--- a/tools/testing/selftests/kvm/dirty_log_test.c
+++ b/tools/testing/selftests/kvm/dirty_log_test.c
@@ -168,6 +168,7 @@ static enum log_mode_t host_log_mode_option = LOG_MODE_ALL;
 /* Logging mode for current run */
 static enum log_mode_t host_log_mode;
 static pthread_t vcpu_thread;
+static uint32_t test_dirty_ring_count = TEST_DIRTY_RING_COUNT;
 
 /* Only way to pass this to the signal handler */
 static struct kvm_vm *current_vm;
@@ -250,7 +251,7 @@ static void dirty_ring_create_vm_done(struct kvm_vm *vm)
 * Switch to dirty ring mode after VM creation but before any
 * of the vcpu creation.
 */
-   vm_enable_dirty_ring(vm, TEST_DIRTY_RING_COUNT *
+   vm_enable_dirty_ring(vm, test_dirty_ring_count *
 sizeof(struct kvm_dirty_gfn));
 }
 
@@ -272,7 +273,7 @@ static uint32_t dirty_ring_collect_one(struct kvm_dirty_gfn 
*dirty_gfns,
uint32_t count = 0;
 
while (true) {
-   cur = _gfns[*fetch_index % TEST_DIRTY_RING_COUNT];
+   cur = _gfns[*fetch_index % test_dirty_ring_count];
if (!dirty_gfn_is_dirtied(cur))
break;
TEST_ASSERT(cur->slot == slot, "Slot number didn't match: "
@@ -778,6 +779,9 @@ static void help(char *name)
printf("usage: %s [-h] [-i iterations] [-I interval] "
   "[-p offset] [-m mode]\n", name);
puts("");
+   printf(" -c: specify dirty ring size, in number of entries\n");
+   printf(" (only useful for dirty-ring test; default: %"PRIu32")\n",
+  TEST_DIRTY_RING_COUNT);
printf(" -i: specify iteration counts (default: %"PRIu64")\n",
   TEST_HOST_LOOP_N);
printf(" -I: specify interval in ms (default: %"PRIu64" ms)\n",
@@ -833,8 +837,11 @@ int main(int argc, char *argv[])
guest_mode_init(VM_MODE_P40V48_4K, true, true);
 #endif
 
-   while ((opt = getopt(argc, argv, "hi:I:p:m:M:")) != -1) {
+   while ((opt = getopt(argc, argv, "c:hi:I:p:m:M:")) != -1) {
switch (opt) {
+   case 'c':
+   test_dirty_ring_count = strtol(optarg, NULL, 10);
+   break;
case 'i':
iterations = strtol(optarg, NULL, 10);
break;
-- 
2.26.2



Re: [PATCH v3 3/3] vfio-pci: Invalidate mmaps and block MMIO access on disabled memory

2020-05-23 Thread Alex Williamson
On Sat, 23 May 2020 15:34:17 -0400
Peter Xu  wrote:

> Hi, Alex,
> 
> On Fri, May 22, 2020 at 01:17:43PM -0600, Alex Williamson wrote:
> > @@ -1346,15 +1526,32 @@ static vm_fault_t vfio_pci_mmap_fault(struct 
> > vm_fault *vmf)
> >  {
> > struct vm_area_struct *vma = vmf->vma;
> > struct vfio_pci_device *vdev = vma->vm_private_data;
> > +   vm_fault_t ret = VM_FAULT_NOPAGE;
> > +
> > +   mutex_lock(>vma_lock);
> > +   down_read(>memory_lock);  
> 
> I remembered to have seen the fault() handling FAULT_FLAG_RETRY_NOWAIT at 
> least
> in the very first version, but it's not here any more...  Could I ask what's
> the reason behind?  I probably have missed something along with the versions,
> I'm just not sure whether e.g. this would potentially block a GUP caller even
> if it's with FOLL_NOWAIT.

This is largely what v2 was about, from the cover letter:

Locking in 3/ is substantially changed to avoid the retry scenario
within the fault handler, therefore a caller who does not allow
retry will no longer receive a SIGBUS on contention.

The discussion thread starts here:

https://lore.kernel.org/kvm/20200501234849.gq26...@ziepe.ca/

Feel free to interject if there's something that doesn't make sense,
the idea is that since we've fixed the lock ordering we never need to
release one lock to wait for another, therefore we can wait for the
lock.  I'm under the impression that we can wait for the lock
regardless of the flags under these conditions.

> Side note: Another thing I thought about when reading this patch - there seems
> to have quite some possibility that the VFIO_DEVICE_PCI_HOT_RESET ioctl will
> start to return -EBUSY now.  Not a problem for this series, but maybe we 
> should
> rememeber to let the userspace handle -EBUSY properly as follow up too, since 
> I
> saw QEMU seemed to not handle -EBUSY for host reset path right now.

I think this has always been the case, whether it's the device lock or
this lock, the only way I know to avoid potential deadlock is to use
the 'try' locking semantics.  In normal scenarios I expect access to
sibling devices is quiesced at this point, so a user driver actually
wanting to achieve a reset shouldn't be affected by this.  Thanks,

Alex



[PATCH v9 07/14] KVM: Don't allocate dirty bitmap if dirty ring is enabled

2020-05-23 Thread Peter Xu
Because kvm dirty rings and kvm dirty log is used in an exclusive way,
Let's avoid creating the dirty_bitmap when kvm dirty ring is enabled.
At the meantime, since the dirty_bitmap will be conditionally created
now, we can't use it as a sign of "whether this memory slot enabled
dirty tracking".  Change users like that to check against the kvm
memory slot flags.

Note that there still can be chances where the kvm memory slot got its
dirty_bitmap allocated, _if_ the memory slots are created before
enabling of the dirty rings and at the same time with the dirty
tracking capability enabled, they'll still with the dirty_bitmap.
However it should not hurt much (e.g., the bitmaps will always be
freed if they are there), and the real users normally won't trigger
this because dirty bit tracking flag should in most cases only be
applied to kvm slots only before migration starts, that should be far
latter than kvm initializes (VM starts).

Signed-off-by: Peter Xu 
---
 arch/x86/kvm/mmu/mmu.c   | 4 ++--
 include/linux/kvm_host.h | 5 +
 virt/kvm/kvm_main.c  | 4 ++--
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 94d84a383b80..ebc86f661db3 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -1276,8 +1276,8 @@ gfn_to_memslot_dirty_bitmap(struct kvm_vcpu *vcpu, gfn_t 
gfn,
slot = kvm_vcpu_gfn_to_memslot(vcpu, gfn);
if (!slot || slot->flags & KVM_MEMSLOT_INVALID)
return NULL;
-   if (no_dirty_log && slot->dirty_bitmap)
-   return NULL;
+   if (no_dirty_log && kvm_slot_dirty_track_enabled(slot))
+   return false;
 
return slot;
 }
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index a7eaef494f45..5081c6e2ae06 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -351,6 +351,11 @@ struct kvm_memory_slot {
u16 as_id;
 };
 
+static inline bool kvm_slot_dirty_track_enabled(struct kvm_memory_slot *slot)
+{
+   return slot->flags & KVM_MEM_LOG_DIRTY_PAGES;
+}
+
 static inline unsigned long kvm_dirty_bitmap_bytes(struct kvm_memory_slot 
*memslot)
 {
return ALIGN(memslot->npages, BITS_PER_LONG) / 8;
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 9639cf8d8c9c..ae7ba67eab63 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1294,7 +1294,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
/* Allocate/free page dirty bitmap as needed */
if (!(new.flags & KVM_MEM_LOG_DIRTY_PAGES))
new.dirty_bitmap = NULL;
-   else if (!new.dirty_bitmap) {
+   else if (!new.dirty_bitmap && !kvm->dirty_ring_size) {
r = kvm_alloc_dirty_bitmap();
if (r)
return r;
@@ -2581,7 +2581,7 @@ static void mark_page_dirty_in_slot(struct kvm *kvm,
struct kvm_memory_slot *memslot,
gfn_t gfn)
 {
-   if (memslot && memslot->dirty_bitmap) {
+   if (memslot && kvm_slot_dirty_track_enabled(memslot)) {
unsigned long rel_gfn = gfn - memslot->base_gfn;
u32 slot = (memslot->as_id << 16) | memslot->id;
 
-- 
2.26.2



[PATCH v9 12/14] KVM: selftests: Add dirty ring buffer test

2020-05-23 Thread Peter Xu
Add the initial dirty ring buffer test.

The current test implements the userspace dirty ring collection, by
only reaping the dirty ring when the ring is full.

So it's still running synchronously like this:

vcpu main thread

  1. vcpu dirties pages
  2. vcpu gets dirty ring full
 (userspace exit)

   3. main thread waits until full
  (so hardware buffers flushed)
   4. main thread collects
   5. main thread continues vcpu

  6. vcpu continues, goes back to 1

We can't directly collects dirty bits during vcpu execution because
otherwise we can't guarantee the hardware dirty bits were flushed when
we collect and we're very strict on the dirty bits so otherwise we can
fail the future verify procedure.  A follow up patch will make this
test to support async just like the existing dirty log test, by adding
a vcpu kick mechanism.

Signed-off-by: Peter Xu 
---
 tools/testing/selftests/kvm/dirty_log_test.c  | 201 +-
 .../testing/selftests/kvm/include/kvm_util.h  |   3 +
 tools/testing/selftests/kvm/lib/kvm_util.c|  59 +
 .../selftests/kvm/lib/kvm_util_internal.h |   4 +
 4 files changed, 265 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/kvm/dirty_log_test.c 
b/tools/testing/selftests/kvm/dirty_log_test.c
index a2160946bcf5..531431cff4fc 100644
--- a/tools/testing/selftests/kvm/dirty_log_test.c
+++ b/tools/testing/selftests/kvm/dirty_log_test.c
@@ -12,8 +12,10 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
+#include 
 
 #include "test_util.h"
 #include "kvm_util.h"
@@ -57,6 +59,8 @@
 # define test_and_clear_bit_le test_and_clear_bit
 #endif
 
+#define TEST_DIRTY_RING_COUNT  1024
+
 /*
  * Guest/Host shared variables. Ensure addr_gva2hva() and/or
  * sync_global_to/from_guest() are used when accessing from
@@ -128,6 +132,10 @@ static uint64_t host_dirty_count;
 static uint64_t host_clear_count;
 static uint64_t host_track_next_count;
 
+/* Whether dirty ring reset is requested, or finished */
+static sem_t dirty_ring_vcpu_stop;
+static sem_t dirty_ring_vcpu_cont;
+
 enum log_mode_t {
/* Only use KVM_GET_DIRTY_LOG for logging */
LOG_MODE_DIRTY_LOG = 0,
@@ -135,6 +143,9 @@ enum log_mode_t {
/* Use both KVM_[GET|CLEAR]_DIRTY_LOG for logging */
LOG_MODE_CLEAR_LOG = 1,
 
+   /* Use dirty ring for logging */
+   LOG_MODE_DIRTY_RING = 2,
+
LOG_MODE_NUM,
 
/* Run all supported modes */
@@ -187,6 +198,120 @@ static void default_after_vcpu_run(struct kvm_vm *vm)
exit_reason_str(run->exit_reason));
 }
 
+static bool dirty_ring_supported(void)
+{
+   return kvm_check_cap(KVM_CAP_DIRTY_LOG_RING);
+}
+
+static void dirty_ring_create_vm_done(struct kvm_vm *vm)
+{
+   /*
+* Switch to dirty ring mode after VM creation but before any
+* of the vcpu creation.
+*/
+   vm_enable_dirty_ring(vm, TEST_DIRTY_RING_COUNT *
+sizeof(struct kvm_dirty_gfn));
+}
+
+static inline bool dirty_gfn_is_dirtied(struct kvm_dirty_gfn *gfn)
+{
+   return gfn->flags == KVM_DIRTY_GFN_F_DIRTY;
+}
+
+static inline void dirty_gfn_set_collected(struct kvm_dirty_gfn *gfn)
+{
+   gfn->flags = KVM_DIRTY_GFN_F_RESET;
+}
+
+static uint32_t dirty_ring_collect_one(struct kvm_dirty_gfn *dirty_gfns,
+  int slot, void *bitmap,
+  uint32_t num_pages, uint32_t 
*fetch_index)
+{
+   struct kvm_dirty_gfn *cur;
+   uint32_t count = 0;
+
+   while (true) {
+   cur = _gfns[*fetch_index % TEST_DIRTY_RING_COUNT];
+   if (!dirty_gfn_is_dirtied(cur))
+   break;
+   TEST_ASSERT(cur->slot == slot, "Slot number didn't match: "
+   "%u != %u", cur->slot, slot);
+   TEST_ASSERT(cur->offset < num_pages, "Offset overflow: "
+   "0x%llx >= 0x%x", cur->offset, num_pages);
+   pr_info("fetch 0x%x page %llu\n", *fetch_index, cur->offset);
+   set_bit(cur->offset, bitmap);
+   dirty_gfn_set_collected(cur);
+   (*fetch_index)++;
+   count++;
+   }
+
+   return count;
+}
+
+static void dirty_ring_collect_dirty_pages(struct kvm_vm *vm, int slot,
+  void *bitmap, uint32_t num_pages)
+{
+   /* We only have one vcpu */
+   static uint32_t fetch_index = 0;
+   uint32_t count = 0, cleared;
+
+   /*
+* Before fetching the dirty pages, we need a vmexit of the
+* worker vcpu to make sure the hardware dirty buffers were
+* flushed.  This is not needed for dirty-log/clear-log tests
+* because get dirty log will natually do so.
+*
+  

[PATCH v9 08/14] KVM: selftests: Always clear dirty bitmap after iteration

2020-05-23 Thread Peter Xu
We don't clear the dirty bitmap before because KVM_GET_DIRTY_LOG will
clear it for us before copying the dirty log onto it.  However we'd
still better to clear it explicitly instead of assuming the kernel
will always do it for us.

More importantly, in the upcoming dirty ring tests we'll start to
fetch dirty pages from a ring buffer, so no one is going to clear the
dirty bitmap for us.

Reviewed-by: Andrew Jones 
Signed-off-by: Peter Xu 
---
 tools/testing/selftests/kvm/dirty_log_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/kvm/dirty_log_test.c 
b/tools/testing/selftests/kvm/dirty_log_test.c
index 752ec158ac59..6a8275a22861 100644
--- a/tools/testing/selftests/kvm/dirty_log_test.c
+++ b/tools/testing/selftests/kvm/dirty_log_test.c
@@ -195,7 +195,7 @@ static void vm_dirty_log_verify(enum vm_guest_mode mode, 
unsigned long *bmap)
page);
}
 
-   if (test_bit_le(page, bmap)) {
+   if (test_and_clear_bit_le(page, bmap)) {
host_dirty_count++;
/*
 * If the bit is set, the value written onto
-- 
2.26.2



[PATCH v9 10/14] KVM: selftests: Use a single binary for dirty/clear log test

2020-05-23 Thread Peter Xu
Remove the clear_dirty_log test, instead merge it into the existing
dirty_log_test.  It should be cleaner to use this single binary to do
both tests, also it's a preparation for the upcoming dirty ring test.

The default behavior will run all the modes in sequence.

Reviewed-by: Andrew Jones 
Signed-off-by: Peter Xu 
---
 tools/testing/selftests/kvm/Makefile  |   2 -
 .../selftests/kvm/clear_dirty_log_test.c  |   6 -
 tools/testing/selftests/kvm/dirty_log_test.c  | 187 +++---
 3 files changed, 156 insertions(+), 39 deletions(-)
 delete mode 100644 tools/testing/selftests/kvm/clear_dirty_log_test.c

diff --git a/tools/testing/selftests/kvm/Makefile 
b/tools/testing/selftests/kvm/Makefile
index 712a2ddd2a27..fee0393f10da 100644
--- a/tools/testing/selftests/kvm/Makefile
+++ b/tools/testing/selftests/kvm/Makefile
@@ -28,13 +28,11 @@ TEST_GEN_PROGS_x86_64 += x86_64/vmx_dirty_log_test
 TEST_GEN_PROGS_x86_64 += x86_64/vmx_set_nested_state_test
 TEST_GEN_PROGS_x86_64 += x86_64/vmx_tsc_adjust_test
 TEST_GEN_PROGS_x86_64 += x86_64/xss_msr_test
-TEST_GEN_PROGS_x86_64 += clear_dirty_log_test
 TEST_GEN_PROGS_x86_64 += demand_paging_test
 TEST_GEN_PROGS_x86_64 += dirty_log_test
 TEST_GEN_PROGS_x86_64 += kvm_create_max_vcpus
 TEST_GEN_PROGS_x86_64 += steal_time
 
-TEST_GEN_PROGS_aarch64 += clear_dirty_log_test
 TEST_GEN_PROGS_aarch64 += demand_paging_test
 TEST_GEN_PROGS_aarch64 += dirty_log_test
 TEST_GEN_PROGS_aarch64 += kvm_create_max_vcpus
diff --git a/tools/testing/selftests/kvm/clear_dirty_log_test.c 
b/tools/testing/selftests/kvm/clear_dirty_log_test.c
deleted file mode 100644
index 11672ec6f74e..
--- a/tools/testing/selftests/kvm/clear_dirty_log_test.c
+++ /dev/null
@@ -1,6 +0,0 @@
-#define USE_CLEAR_DIRTY_LOG
-#define KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE (1 << 0)
-#define KVM_DIRTY_LOG_INITIALLY_SET (1 << 1)
-#define KVM_DIRTY_LOG_MANUAL_CAPS   (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | \
-   KVM_DIRTY_LOG_INITIALLY_SET)
-#include "dirty_log_test.c"
diff --git a/tools/testing/selftests/kvm/dirty_log_test.c 
b/tools/testing/selftests/kvm/dirty_log_test.c
index 6a8275a22861..139ccb550618 100644
--- a/tools/testing/selftests/kvm/dirty_log_test.c
+++ b/tools/testing/selftests/kvm/dirty_log_test.c
@@ -128,6 +128,78 @@ static uint64_t host_dirty_count;
 static uint64_t host_clear_count;
 static uint64_t host_track_next_count;
 
+enum log_mode_t {
+   /* Only use KVM_GET_DIRTY_LOG for logging */
+   LOG_MODE_DIRTY_LOG = 0,
+
+   /* Use both KVM_[GET|CLEAR]_DIRTY_LOG for logging */
+   LOG_MODE_CLEAR_LOG = 1,
+
+   LOG_MODE_NUM,
+
+   /* Run all supported modes */
+   LOG_MODE_ALL = LOG_MODE_NUM,
+};
+
+/* Mode of logging to test.  Default is to run all supported modes */
+static enum log_mode_t host_log_mode_option = LOG_MODE_ALL;
+/* Logging mode for current run */
+static enum log_mode_t host_log_mode;
+
+static bool clear_log_supported(void)
+{
+   return kvm_check_cap(KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2);
+}
+
+static void clear_log_create_vm_done(struct kvm_vm *vm)
+{
+   struct kvm_enable_cap cap = {};
+   u64 manual_caps;
+
+   manual_caps = kvm_check_cap(KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2);
+   TEST_ASSERT(manual_caps, "MANUAL_CAPS is zero!");
+   manual_caps &= (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE |
+   KVM_DIRTY_LOG_INITIALLY_SET);
+   cap.cap = KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2;
+   cap.args[0] = manual_caps;
+   vm_enable_cap(vm, );
+}
+
+static void dirty_log_collect_dirty_pages(struct kvm_vm *vm, int slot,
+ void *bitmap, uint32_t num_pages)
+{
+   kvm_vm_get_dirty_log(vm, slot, bitmap);
+}
+
+static void clear_log_collect_dirty_pages(struct kvm_vm *vm, int slot,
+ void *bitmap, uint32_t num_pages)
+{
+   kvm_vm_get_dirty_log(vm, slot, bitmap);
+   kvm_vm_clear_dirty_log(vm, slot, bitmap, 0, num_pages);
+}
+
+struct log_mode {
+   const char *name;
+   /* Return true if this mode is supported, otherwise false */
+   bool (*supported)(void);
+   /* Hook when the vm creation is done (before vcpu creation) */
+   void (*create_vm_done)(struct kvm_vm *vm);
+   /* Hook to collect the dirty pages into the bitmap provided */
+   void (*collect_dirty_pages) (struct kvm_vm *vm, int slot,
+void *bitmap, uint32_t num_pages);
+} log_modes[LOG_MODE_NUM] = {
+   {
+   .name = "dirty-log",
+   .collect_dirty_pages = dirty_log_collect_dirty_pages,
+   },
+   {
+   .name = "clear-log",
+   .supported = clear_log_supported,
+   .create_vm_done = clear_log_create_vm_done,
+   .collect_dirty_pages = clear_log_collect_dirty_pages,
+   },
+};
+
 /*
  * We use this bitmap to track some pages that should have its dirty
  * bit set in the _next_ iteration.  

[PATCH v9 02/14] KVM: Cache as_id in kvm_memory_slot

2020-05-23 Thread Peter Xu
Cache the address space ID just like the slot ID.  It will be used in
order to fill in the dirty ring entries.

Suggested-by: Paolo Bonzini 
Suggested-by: Sean Christopherson 
Signed-off-by: Peter Xu 
---
 include/linux/kvm_host.h | 1 +
 virt/kvm/kvm_main.c  | 1 +
 2 files changed, 2 insertions(+)

diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 01276e3d01b9..5e7bbaf7a36b 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -346,6 +346,7 @@ struct kvm_memory_slot {
unsigned long userspace_addr;
u32 flags;
short id;
+   u16 as_id;
 };
 
 static inline unsigned long kvm_dirty_bitmap_bytes(struct kvm_memory_slot 
*memslot)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 74bdb7bf3295..ebdd98a30e82 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1243,6 +1243,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
if (!mem->memory_size)
return kvm_delete_memslot(kvm, mem, , as_id);
 
+   new.as_id = as_id;
new.id = id;
new.base_gfn = mem->guest_phys_addr >> PAGE_SHIFT;
new.npages = mem->memory_size >> PAGE_SHIFT;
-- 
2.26.2



[PATCH v9 11/14] KVM: selftests: Introduce after_vcpu_run hook for dirty log test

2020-05-23 Thread Peter Xu
Provide a hook for the checks after vcpu_run() completes.  Preparation
for the dirty ring test because we'll need to take care of another
exit reason.

Reviewed-by: Andrew Jones 
Signed-off-by: Peter Xu 
---
 tools/testing/selftests/kvm/dirty_log_test.c | 36 +---
 1 file changed, 24 insertions(+), 12 deletions(-)

diff --git a/tools/testing/selftests/kvm/dirty_log_test.c 
b/tools/testing/selftests/kvm/dirty_log_test.c
index 139ccb550618..a2160946bcf5 100644
--- a/tools/testing/selftests/kvm/dirty_log_test.c
+++ b/tools/testing/selftests/kvm/dirty_log_test.c
@@ -178,6 +178,15 @@ static void clear_log_collect_dirty_pages(struct kvm_vm 
*vm, int slot,
kvm_vm_clear_dirty_log(vm, slot, bitmap, 0, num_pages);
 }
 
+static void default_after_vcpu_run(struct kvm_vm *vm)
+{
+   struct kvm_run *run = vcpu_state(vm, VCPU_ID);
+
+   TEST_ASSERT(get_ucall(vm, VCPU_ID, NULL) == UCALL_SYNC,
+   "Invalid guest sync status: exit_reason=%s\n",
+   exit_reason_str(run->exit_reason));
+}
+
 struct log_mode {
const char *name;
/* Return true if this mode is supported, otherwise false */
@@ -187,16 +196,20 @@ struct log_mode {
/* Hook to collect the dirty pages into the bitmap provided */
void (*collect_dirty_pages) (struct kvm_vm *vm, int slot,
 void *bitmap, uint32_t num_pages);
+   /* Hook to call when after each vcpu run */
+   void (*after_vcpu_run)(struct kvm_vm *vm);
 } log_modes[LOG_MODE_NUM] = {
{
.name = "dirty-log",
.collect_dirty_pages = dirty_log_collect_dirty_pages,
+   .after_vcpu_run = default_after_vcpu_run,
},
{
.name = "clear-log",
.supported = clear_log_supported,
.create_vm_done = clear_log_create_vm_done,
.collect_dirty_pages = clear_log_collect_dirty_pages,
+   .after_vcpu_run = default_after_vcpu_run,
},
 };
 
@@ -247,6 +260,14 @@ static void log_mode_collect_dirty_pages(struct kvm_vm 
*vm, int slot,
mode->collect_dirty_pages(vm, slot, bitmap, num_pages);
 }
 
+static void log_mode_after_vcpu_run(struct kvm_vm *vm)
+{
+   struct log_mode *mode = _modes[host_log_mode];
+
+   if (mode->after_vcpu_run)
+   mode->after_vcpu_run(vm);
+}
+
 static void generate_random_array(uint64_t *guest_array, uint64_t size)
 {
uint64_t i;
@@ -261,25 +282,16 @@ static void *vcpu_worker(void *data)
struct kvm_vm *vm = data;
uint64_t *guest_array;
uint64_t pages_count = 0;
-   struct kvm_run *run;
-
-   run = vcpu_state(vm, VCPU_ID);
 
guest_array = addr_gva2hva(vm, (vm_vaddr_t)random_array);
-   generate_random_array(guest_array, TEST_PAGES_PER_LOOP);
 
while (!READ_ONCE(host_quit)) {
+   generate_random_array(guest_array, TEST_PAGES_PER_LOOP);
+   pages_count += TEST_PAGES_PER_LOOP;
/* Let the guest dirty the random pages */
ret = _vcpu_run(vm, VCPU_ID);
TEST_ASSERT(ret == 0, "vcpu_run failed: %d\n", ret);
-   if (get_ucall(vm, VCPU_ID, NULL) == UCALL_SYNC) {
-   pages_count += TEST_PAGES_PER_LOOP;
-   generate_random_array(guest_array, TEST_PAGES_PER_LOOP);
-   } else {
-   TEST_FAIL("Invalid guest sync status: "
- "exit_reason=%s\n",
- exit_reason_str(run->exit_reason));
-   }
+   log_mode_after_vcpu_run(vm);
}
 
pr_info("Dirtied %"PRIu64" pages\n", pages_count);
-- 
2.26.2



[PATCH v9 05/14] KVM: X86: Implement ring-based dirty memory tracking

2020-05-23 Thread Peter Xu
This patch is heavily based on previous work from Lei Cao
 and Paolo Bonzini . [1]

KVM currently uses large bitmaps to track dirty memory.  These bitmaps
are copied to userspace when userspace queries KVM for its dirty page
information.  The use of bitmaps is mostly sufficient for live
migration, as large parts of memory are be dirtied from one log-dirty
pass to another.  However, in a checkpointing system, the number of
dirty pages is small and in fact it is often bounded---the VM is
paused when it has dirtied a pre-defined number of pages. Traversing a
large, sparsely populated bitmap to find set bits is time-consuming,
as is copying the bitmap to user-space.

A similar issue will be there for live migration when the guest memory
is huge while the page dirty procedure is trivial.  In that case for
each dirty sync we need to pull the whole dirty bitmap to userspace
and analyse every bit even if it's mostly zeros.

The preferred data structure for above scenarios is a dense list of
guest frame numbers (GFN).  This patch series stores the dirty list in
kernel memory that can be memory mapped into userspace to allow speedy
harvesting.

This patch enables dirty ring for X86 only.  However it should be
easily extended to other archs as well.

[1] https://patchwork.kernel.org/patch/10471409/

Signed-off-by: Lei Cao 
Signed-off-by: Paolo Bonzini 
Signed-off-by: Peter Xu 
---
 Documentation/virt/kvm/api.rst  | 116 +++
 arch/x86/include/asm/kvm_host.h |   3 +
 arch/x86/include/uapi/asm/kvm.h |   1 +
 arch/x86/kvm/Makefile   |   3 +-
 arch/x86/kvm/mmu/mmu.c  |   8 ++
 arch/x86/kvm/vmx/vmx.c  |   8 +-
 arch/x86/kvm/x86.c  |   9 ++
 include/linux/kvm_dirty_ring.h  | 103 +
 include/linux/kvm_host.h|  13 +++
 include/trace/events/kvm.h  |  78 +
 include/uapi/linux/kvm.h|  53 +
 virt/kvm/dirty_ring.c   | 197 
 virt/kvm/kvm_main.c | 112 +-
 13 files changed, 701 insertions(+), 3 deletions(-)
 create mode 100644 include/linux/kvm_dirty_ring.h
 create mode 100644 virt/kvm/dirty_ring.c

diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
index efbbe570aa9b..aa54a34077b7 100644
--- a/Documentation/virt/kvm/api.rst
+++ b/Documentation/virt/kvm/api.rst
@@ -249,6 +249,7 @@ Based on their initialization different VMs may have 
different capabilities.
 It is thus encouraged to use the vm ioctl to query for capabilities (available
 with KVM_CAP_CHECK_EXTENSION_VM on the vm fd)
 
+
 4.5 KVM_GET_VCPU_MMAP_SIZE
 --
 
@@ -262,6 +263,18 @@ The KVM_RUN ioctl (cf.) communicates with userspace via a 
shared
 memory region.  This ioctl returns the size of that region.  See the
 KVM_RUN documentation for details.
 
+Besides the size of the KVM_RUN communication region, other areas of
+the VCPU file descriptor can be mmap-ed, including:
+
+- if KVM_CAP_COALESCED_MMIO is available, a page at
+  KVM_COALESCED_MMIO_PAGE_OFFSET * PAGE_SIZE; for historical reasons,
+  this page is included in the result of KVM_GET_VCPU_MMAP_SIZE.
+  KVM_CAP_COALESCED_MMIO is not documented yet.
+
+- if KVM_CAP_DIRTY_LOG_RING is available, a number of pages at
+  KVM_DIRTY_LOG_PAGE_OFFSET * PAGE_SIZE.  For more information on
+  KVM_CAP_DIRTY_LOG_RING, see section 8.3.
+
 
 4.6 KVM_SET_MEMORY_REGION
 -
@@ -6109,3 +6122,106 @@ KVM can therefore start protected VMs.
 This capability governs the KVM_S390_PV_COMMAND ioctl and the
 KVM_MP_STATE_LOAD MP_STATE. KVM_SET_MP_STATE can fail for protected
 guests when the state change is invalid.
+
+8.24 KVM_CAP_DIRTY_LOG_RING
+
+Architectures: x86
+Parameters: args[0] - size of the dirty log ring
+
+KVM is capable of tracking dirty memory using ring buffers that are
+mmaped into userspace; there is one dirty ring per vcpu.
+
+One dirty ring is defined as below internally:
+
+struct kvm_dirty_ring {
+   u32 dirty_index;
+   u32 reset_index;
+   u32 size;
+   u32 soft_limit;
+   struct kvm_dirty_gfn *dirty_gfns;
+   int index;
+};
+
+Dirty GFNs (Guest Frame Numbers) are stored in the dirty_gfns array.
+For each of the dirty entry it's defined as:
+
+struct kvm_dirty_gfn {
+__u32 flags;
+__u32 slot; /* as_id | slot_id */
+__u64 offset;
+};
+
+Each GFN is a state machine itself.  The state is embeded in the flags
+field, as defined in the uapi header:
+
+/*
+ * KVM dirty GFN flags, defined as:
+ *
+ * |---+---+--|
+ * | bit 1 (reset) | bit 0 (dirty) | Status   |
+ * |---+---+--|
+ * | 0 | 0 | Invalid GFN  |
+ * | 0 | 1 | Dirty GFN|
+ * | 1 | X | GFN to reset |
+ * |---+---+--|
+ *
+ * Lifecycle of a dirty GFN goes like:
+ *
+ *  dirtied 

[PATCH v9 09/14] KVM: selftests: Sync uapi/linux/kvm.h to tools/

2020-05-23 Thread Peter Xu
This will be needed to extend the kvm selftest program.

Signed-off-by: Peter Xu 
---
 tools/include/uapi/linux/kvm.h | 53 ++
 1 file changed, 53 insertions(+)

diff --git a/tools/include/uapi/linux/kvm.h b/tools/include/uapi/linux/kvm.h
index 428c7dde6b4b..74f150c69ee6 100644
--- a/tools/include/uapi/linux/kvm.h
+++ b/tools/include/uapi/linux/kvm.h
@@ -236,6 +236,7 @@ struct kvm_hyperv_exit {
 #define KVM_EXIT_IOAPIC_EOI   26
 #define KVM_EXIT_HYPERV   27
 #define KVM_EXIT_ARM_NISV 28
+#define KVM_EXIT_DIRTY_RING_FULL  29
 
 /* For KVM_EXIT_INTERNAL_ERROR */
 /* Emulate instruction failed. */
@@ -1017,6 +1018,7 @@ struct kvm_ppc_resize_hpt {
 #define KVM_CAP_S390_VCPU_RESETS 179
 #define KVM_CAP_S390_PROTECTED 180
 #define KVM_CAP_PPC_SECURE_GUEST 181
+#define KVM_CAP_DIRTY_LOG_RING 182
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
@@ -1518,6 +1520,9 @@ struct kvm_pv_cmd {
 /* Available with KVM_CAP_S390_PROTECTED */
 #define KVM_S390_PV_COMMAND_IOWR(KVMIO, 0xc5, struct kvm_pv_cmd)
 
+/* Available with KVM_CAP_DIRTY_LOG_RING */
+#define KVM_RESET_DIRTY_RINGS  _IO(KVMIO, 0xc6)
+
 /* Secure Encrypted Virtualization command */
 enum sev_cmd_id {
/* Guest initialization commands */
@@ -1671,4 +1676,52 @@ struct kvm_hyperv_eventfd {
 #define KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE(1 << 0)
 #define KVM_DIRTY_LOG_INITIALLY_SET(1 << 1)
 
+/*
+ * Arch needs to define the macro after implementing the dirty ring
+ * feature.  KVM_DIRTY_LOG_PAGE_OFFSET should be defined as the
+ * starting page offset of the dirty ring structures.
+ */
+#ifndef KVM_DIRTY_LOG_PAGE_OFFSET
+#define KVM_DIRTY_LOG_PAGE_OFFSET 0
+#endif
+
+/*
+ * KVM dirty GFN flags, defined as:
+ *
+ * |---+---+--|
+ * | bit 1 (reset) | bit 0 (dirty) | Status   |
+ * |---+---+--|
+ * | 0 | 0 | Invalid GFN  |
+ * | 0 | 1 | Dirty GFN|
+ * | 1 | X | GFN to reset |
+ * |---+---+--|
+ *
+ * Lifecycle of a dirty GFN goes like:
+ *
+ *  dirtied collectedreset
+ * 00 ---> 01 -> 1X ---+
+ *  ^  |
+ *  |  |
+ *  +--+
+ *
+ * The userspace program is only responsible for the 01->1X state
+ * conversion (to collect dirty bits).  Also, it must not skip any
+ * dirty bits so that dirty bits are always collected in sequence.
+ */
+#define KVM_DIRTY_GFN_F_DIRTY   BIT(0)
+#define KVM_DIRTY_GFN_F_RESET   BIT(1)
+#define KVM_DIRTY_GFN_F_MASK0x3
+
+/*
+ * KVM dirty rings should be mapped at KVM_DIRTY_LOG_PAGE_OFFSET of
+ * per-vcpu mmaped regions as an array of struct kvm_dirty_gfn.  The
+ * size of the gfn buffer is decided by the first argument when
+ * enabling KVM_CAP_DIRTY_LOG_RING.
+ */
+struct kvm_dirty_gfn {
+   __u32 flags;
+   __u32 slot;
+   __u64 offset;
+};
+
 #endif /* __LINUX_KVM_H */
-- 
2.26.2



[PATCH v9 04/14] KVM: Pass in kvm pointer into mark_page_dirty_in_slot()

2020-05-23 Thread Peter Xu
The context will be needed to implement the kvm dirty ring.

Signed-off-by: Peter Xu 
---
 virt/kvm/kvm_main.c | 33 +++--
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index ebdd98a30e82..a7460e93d457 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -144,7 +144,9 @@ static void hardware_disable_all(void);
 
 static void kvm_io_bus_destroy(struct kvm_io_bus *bus);
 
-static void mark_page_dirty_in_slot(struct kvm_memory_slot *memslot, gfn_t 
gfn);
+static void mark_page_dirty_in_slot(struct kvm *kvm,
+   struct kvm_memory_slot *memslot,
+   gfn_t gfn);
 
 __visible bool kvm_rebooting;
 EXPORT_SYMBOL_GPL(kvm_rebooting);
@@ -2120,7 +2122,8 @@ int kvm_vcpu_map(struct kvm_vcpu *vcpu, gfn_t gfn, struct 
kvm_host_map *map)
 }
 EXPORT_SYMBOL_GPL(kvm_vcpu_map);
 
-static void __kvm_unmap_gfn(struct kvm_memory_slot *memslot,
+static void __kvm_unmap_gfn(struct kvm *kvm,
+   struct kvm_memory_slot *memslot,
struct kvm_host_map *map,
struct gfn_to_pfn_cache *cache,
bool dirty, bool atomic)
@@ -2145,7 +2148,7 @@ static void __kvm_unmap_gfn(struct kvm_memory_slot 
*memslot,
 #endif
 
if (dirty)
-   mark_page_dirty_in_slot(memslot, map->gfn);
+   mark_page_dirty_in_slot(kvm, memslot, map->gfn);
 
if (cache)
cache->dirty |= dirty;
@@ -2159,7 +2162,7 @@ static void __kvm_unmap_gfn(struct kvm_memory_slot 
*memslot,
 int kvm_unmap_gfn(struct kvm_vcpu *vcpu, struct kvm_host_map *map, 
  struct gfn_to_pfn_cache *cache, bool dirty, bool atomic)
 {
-   __kvm_unmap_gfn(gfn_to_memslot(vcpu->kvm, map->gfn), map,
+   __kvm_unmap_gfn(vcpu->kvm, gfn_to_memslot(vcpu->kvm, map->gfn), map,
cache, dirty, atomic);
return 0;
 }
@@ -2167,8 +2170,8 @@ EXPORT_SYMBOL_GPL(kvm_unmap_gfn);
 
 void kvm_vcpu_unmap(struct kvm_vcpu *vcpu, struct kvm_host_map *map, bool 
dirty)
 {
-   __kvm_unmap_gfn(kvm_vcpu_gfn_to_memslot(vcpu, map->gfn), map, NULL,
-   dirty, false);
+   __kvm_unmap_gfn(vcpu->kvm, kvm_vcpu_gfn_to_memslot(vcpu, map->gfn),
+   map, NULL, dirty, false);
 }
 EXPORT_SYMBOL_GPL(kvm_vcpu_unmap);
 
@@ -2342,7 +2345,8 @@ int kvm_vcpu_read_guest_atomic(struct kvm_vcpu *vcpu, 
gpa_t gpa,
 }
 EXPORT_SYMBOL_GPL(kvm_vcpu_read_guest_atomic);
 
-static int __kvm_write_guest_page(struct kvm_memory_slot *memslot, gfn_t gfn,
+static int __kvm_write_guest_page(struct kvm *kvm,
+ struct kvm_memory_slot *memslot, gfn_t gfn,
  const void *data, int offset, int len)
 {
int r;
@@ -2354,7 +2358,7 @@ static int __kvm_write_guest_page(struct kvm_memory_slot 
*memslot, gfn_t gfn,
r = __copy_to_user((void __user *)addr + offset, data, len);
if (r)
return -EFAULT;
-   mark_page_dirty_in_slot(memslot, gfn);
+   mark_page_dirty_in_slot(kvm, memslot, gfn);
return 0;
 }
 
@@ -2363,7 +2367,7 @@ int kvm_write_guest_page(struct kvm *kvm, gfn_t gfn,
 {
struct kvm_memory_slot *slot = gfn_to_memslot(kvm, gfn);
 
-   return __kvm_write_guest_page(slot, gfn, data, offset, len);
+   return __kvm_write_guest_page(kvm, slot, gfn, data, offset, len);
 }
 EXPORT_SYMBOL_GPL(kvm_write_guest_page);
 
@@ -2372,7 +2376,7 @@ int kvm_vcpu_write_guest_page(struct kvm_vcpu *vcpu, 
gfn_t gfn,
 {
struct kvm_memory_slot *slot = kvm_vcpu_gfn_to_memslot(vcpu, gfn);
 
-   return __kvm_write_guest_page(slot, gfn, data, offset, len);
+   return __kvm_write_guest_page(vcpu->kvm, slot, gfn, data, offset, len);
 }
 EXPORT_SYMBOL_GPL(kvm_vcpu_write_guest_page);
 
@@ -2491,7 +2495,7 @@ int kvm_write_guest_offset_cached(struct kvm *kvm, struct 
gfn_to_hva_cache *ghc,
r = __copy_to_user((void __user *)ghc->hva + offset, data, len);
if (r)
return -EFAULT;
-   mark_page_dirty_in_slot(ghc->memslot, gpa >> PAGE_SHIFT);
+   mark_page_dirty_in_slot(kvm, ghc->memslot, gpa >> PAGE_SHIFT);
 
return 0;
 }
@@ -2558,7 +2562,8 @@ int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned 
long len)
 }
 EXPORT_SYMBOL_GPL(kvm_clear_guest);
 
-static void mark_page_dirty_in_slot(struct kvm_memory_slot *memslot,
+static void mark_page_dirty_in_slot(struct kvm *kvm,
+   struct kvm_memory_slot *memslot,
gfn_t gfn)
 {
if (memslot && memslot->dirty_bitmap) {
@@ -2573,7 +2578,7 @@ void mark_page_dirty(struct kvm *kvm, gfn_t gfn)
struct kvm_memory_slot *memslot;
 
memslot = gfn_to_memslot(kvm, gfn);
-   mark_page_dirty_in_slot(memslot, gfn);
+   mark_page_dirty_in_slot(kvm, memslot, gfn);
 }
 

[PATCH v9 00/14] KVM: Dirty ring interface

2020-05-23 Thread Peter Xu
KVM branch:
  https://github.com/xzpeter/linux/tree/kvm-dirty-ring

QEMU branch for testing:
  https://github.com/xzpeter/qemu/tree/kvm-dirty-ring

v9:
- patch 3: __x86_set_memory_region: squash another trivial change to return
  (0xdeadull << 48) always for slot removal [Sean]
- pick r-bs for Drew

v8:
- rebase to kvm/next
- fix test bisection issues [Drew]
- reword comment for __x86_set_memory_region [Sean]
- document fixup on "mutual exclusive", etc. [Sean]

For previous versions, please refer to:

V1: https://lore.kernel.org/kvm/20191129213505.18472-1-pet...@redhat.com
V2: https://lore.kernel.org/kvm/20191221014938.58831-1-pet...@redhat.com
V3: https://lore.kernel.org/kvm/20200109145729.32898-1-pet...@redhat.com
V4: https://lore.kernel.org/kvm/20200205025105.367213-1-pet...@redhat.com
V5: https://lore.kernel.org/kvm/20200304174947.69595-1-pet...@redhat.com
V6: https://lore.kernel.org/kvm/20200309214424.330363-1-pet...@redhat.com
V7: https://lore.kernel.org/kvm/20200318163720.93929-1-pet...@redhat.com
V8: https://lore.kernel.org/kvm/2020033119.659614-1-pet...@redhat.com

Overview


This is a continued work from Lei Cao  and Paolo
Bonzini on the KVM dirty ring interface.

The new dirty ring interface is another way to collect dirty pages for
the virtual machines. It is different from the existing dirty logging
interface in a few ways, majorly:

  - Data format: The dirty data was in a ring format rather than a
bitmap format, so dirty bits to sync for dirty logging does not
depend on the size of guest memory any more, but speed of
dirtying.  Also, the dirty ring is per-vcpu, while the dirty
bitmap is per-vm.

  - Data copy: The sync of dirty pages does not need data copy any more,
but instead the ring is shared between the userspace and kernel by
page sharings (mmap() on vcpu fd)

  - Interface: Instead of using the old KVM_GET_DIRTY_LOG,
KVM_CLEAR_DIRTY_LOG interfaces, the new ring uses the new
KVM_RESET_DIRTY_RINGS ioctl when we want to reset the collected
dirty pages to protected mode again (works like
KVM_CLEAR_DIRTY_LOG, but ring based).  To collecting dirty bits,
we only need to read the ring data, no ioctl is needed.

Ring Layout
===

KVM dirty ring is per-vcpu.  Each ring is an array of kvm_dirty_gfn
defined as:

struct kvm_dirty_gfn {
__u32 flags;
__u32 slot; /* as_id | slot_id */
__u64 offset;
};

Each GFN is a state machine itself.  The state is embeded in the flags
field, as defined in the uapi header:

/*
 * KVM dirty GFN flags, defined as:
 *
 * |---+---+--|
 * | bit 1 (reset) | bit 0 (dirty) | Status   |
 * |---+---+--|
 * | 0 | 0 | Invalid GFN  |
 * | 0 | 1 | Dirty GFN|
 * | 1 | X | GFN to reset |
 * |---+---+--|
 *
 * Lifecycle of a dirty GFN goes like:
 *
 *  dirtied collectedreset
 * 00 ---> 01 -> 1X ---+
 *  ^  |
 *  |  |
 *  +--+
 *
 * The userspace program is only responsible for the 01->1X state
 * conversion (to collect dirty bits).  Also, it must not skip any
 * dirty bits so that dirty bits are always collected in sequence.
 */

Testing
===

This series provided both the implementation of the KVM dirty ring and
the test case.  Also I've implemented the QEMU counterpart that can
run with the new KVM, link can be found at the top of the cover
letter.  However that's still a very initial version which is prone to
change and future optimizations.

I did some measurement with the new method with 24G guest running some
dirty workload, I don't see any speedup so far, even in some heavy
dirty load it'll be slower (e.g., when 800MB/s random dirty rate, kvm
dirty ring takes average of ~73s to complete migration while dirty
logging only needs average of ~55s).  However that's understandable
because 24G guest means only 1M dirty bitmap, that's still a suitable
case for dirty logging.  Meanwhile heavier workload means worst case
for dirty ring.

More tests are welcomed if there's bigger host/guest, especially on
COLO-like workload.

Please review, thanks.

Peter Xu (14):
  KVM: X86: Change parameter for fast_page_fault tracepoint
  KVM: Cache as_id in kvm_memory_slot
  KVM: X86: Don't track dirty for KVM_SET_[TSS_ADDR|IDENTITY_MAP_ADDR]
  KVM: Pass in kvm pointer into mark_page_dirty_in_slot()
  KVM: X86: Implement ring-based dirty memory tracking
  KVM: Make dirty ring exclusive to dirty bitmap log
  KVM: Don't allocate dirty bitmap if dirty ring is enabled
  KVM: selftests: Always clear dirty bitmap after iteration
  KVM: selftests: Sync uapi/linux/kvm.h to tools/
  KVM: selftests: Use a single binary for dirty/clear log test
  KVM: selftests: 

[PATCH v9 01/14] KVM: X86: Change parameter for fast_page_fault tracepoint

2020-05-23 Thread Peter Xu
It would be clearer to dump the return value to know easily on whether
did we go through the fast path for handling current page fault.
Remove the old two last parameters because after all the old/new sptes
were dumped in the same line.

Signed-off-by: Peter Xu 
---
 arch/x86/kvm/mmutrace.h | 9 ++---
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kvm/mmutrace.h b/arch/x86/kvm/mmutrace.h
index ffcd96fc02d0..ef523e760743 100644
--- a/arch/x86/kvm/mmutrace.h
+++ b/arch/x86/kvm/mmutrace.h
@@ -244,9 +244,6 @@ TRACE_EVENT(
  __entry->access)
 );
 
-#define __spte_satisfied(__spte)   \
-   (__entry->retry && is_writable_pte(__entry->__spte))
-
 TRACE_EVENT(
fast_page_fault,
TP_PROTO(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, u32 error_code,
@@ -274,12 +271,10 @@ TRACE_EVENT(
),
 
TP_printk("vcpu %d gva %llx error_code %s sptep %p old %#llx"
- " new %llx spurious %d fixed %d", __entry->vcpu_id,
+ " new %llx ret %d", __entry->vcpu_id,
  __entry->cr2_or_gpa, __print_flags(__entry->error_code, "|",
  kvm_mmu_trace_pferr_flags), __entry->sptep,
- __entry->old_spte, __entry->new_spte,
- __spte_satisfied(old_spte), __spte_satisfied(new_spte)
-   )
+ __entry->old_spte, __entry->new_spte, __entry->retry)
 );
 
 TRACE_EVENT(
-- 
2.26.2



[PATCH v9 03/14] KVM: X86: Don't track dirty for KVM_SET_[TSS_ADDR|IDENTITY_MAP_ADDR]

2020-05-23 Thread Peter Xu
Originally, we have three code paths that can dirty a page without
vcpu context for X86:

  - init_rmode_identity_map
  - init_rmode_tss
  - kvmgt_rw_gpa

init_rmode_identity_map and init_rmode_tss will be setup on
destination VM no matter what (and the guest cannot even see them), so
it does not make sense to track them at all.

To do this, allow __x86_set_memory_region() to return the userspace
address that just allocated to the caller.  Then in both of the
functions we directly write to the userspace address instead of
calling kvm_write_*() APIs.

Another trivial change is that we don't need to explicitly clear the
identity page table root in init_rmode_identity_map() because no
matter what we'll write to the whole page with 4M huge page entries.

Suggested-by: Paolo Bonzini 
Signed-off-by: Peter Xu 
---
 arch/x86/include/asm/kvm_host.h |  3 +-
 arch/x86/kvm/svm/avic.c | 11 +++--
 arch/x86/kvm/vmx/vmx.c  | 82 -
 arch/x86/kvm/x86.c  | 44 ++
 4 files changed, 86 insertions(+), 54 deletions(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 42a2d0d3984a..39477f8f3f2c 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1650,7 +1650,8 @@ void __kvm_request_immediate_exit(struct kvm_vcpu *vcpu);
 
 int kvm_is_in_guest(void);
 
-int __x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa, u32 size);
+void __user *__x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa,
+u32 size);
 bool kvm_vcpu_is_reset_bsp(struct kvm_vcpu *vcpu);
 bool kvm_vcpu_is_bsp(struct kvm_vcpu *vcpu);
 
diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c
index e80daa98682f..86e9621ba026 100644
--- a/arch/x86/kvm/svm/avic.c
+++ b/arch/x86/kvm/svm/avic.c
@@ -235,7 +235,9 @@ static u64 *avic_get_physical_id_entry(struct kvm_vcpu 
*vcpu,
  */
 static int avic_update_access_page(struct kvm *kvm, bool activate)
 {
-   int ret = 0;
+   void __user *ret;
+   int r = 0;
+
 
mutex_lock(>slots_lock);
/*
@@ -251,13 +253,16 @@ static int avic_update_access_page(struct kvm *kvm, bool 
activate)
  APIC_ACCESS_PAGE_PRIVATE_MEMSLOT,
  APIC_DEFAULT_PHYS_BASE,
  activate ? PAGE_SIZE : 0);
-   if (ret)
+   if (IS_ERR(ret)) {
+   r = PTR_ERR(ret);
goto out;
+   }
+
 
kvm->arch.apic_access_page_done = activate;
 out:
mutex_unlock(>slots_lock);
-   return ret;
+   return r;
 }
 
 static int avic_init_backing_page(struct kvm_vcpu *vcpu)
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index c2c6335a998c..ad1d9120283e 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -3442,34 +3442,26 @@ static bool guest_state_valid(struct kvm_vcpu *vcpu)
return true;
 }
 
-static int init_rmode_tss(struct kvm *kvm)
+static int init_rmode_tss(struct kvm *kvm, void __user *ua)
 {
-   gfn_t fn;
-   u16 data = 0;
-   int idx, r;
+   const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
+   u16 data;
+   int i, r;
+
+   for (i = 0; i < 3; i++) {
+   r = __copy_to_user(ua + PAGE_SIZE * i, zero_page, PAGE_SIZE);
+   if (r)
+   return -EFAULT;
+   }
 
-   idx = srcu_read_lock(>srcu);
-   fn = to_kvm_vmx(kvm)->tss_addr >> PAGE_SHIFT;
-   r = kvm_clear_guest_page(kvm, fn, 0, PAGE_SIZE);
-   if (r < 0)
-   goto out;
data = TSS_BASE_SIZE + TSS_REDIRECTION_SIZE;
-   r = kvm_write_guest_page(kvm, fn++, ,
-   TSS_IOPB_BASE_OFFSET, sizeof(u16));
-   if (r < 0)
-   goto out;
-   r = kvm_clear_guest_page(kvm, fn++, 0, PAGE_SIZE);
-   if (r < 0)
-   goto out;
-   r = kvm_clear_guest_page(kvm, fn, 0, PAGE_SIZE);
-   if (r < 0)
-   goto out;
+   r = __copy_to_user(ua + TSS_IOPB_BASE_OFFSET, , sizeof(u16));
+   if (r)
+   return -EFAULT;
+
data = ~0;
-   r = kvm_write_guest_page(kvm, fn, ,
-RMODE_TSS_SIZE - 2 * PAGE_SIZE - 1,
-sizeof(u8));
-out:
-   srcu_read_unlock(>srcu, idx);
+   r = __copy_to_user(ua + RMODE_TSS_SIZE - 1, , sizeof(u8));
+
return r;
 }
 
@@ -3478,6 +3470,7 @@ static int init_rmode_identity_map(struct kvm *kvm)
struct kvm_vmx *kvm_vmx = to_kvm_vmx(kvm);
int i, r = 0;
kvm_pfn_t identity_map_pfn;
+   void __user *uaddr;
u32 tmp;
 
/* Protect kvm_vmx->ept_identity_pagetable_done. */
@@ -3490,22 +3483,24 @@ static int init_rmode_identity_map(struct kvm *kvm)
kvm_vmx->ept_identity_map_addr = 
VMX_EPT_IDENTITY_PAGETABLE_ADDR;
identity_map_pfn = 

[PATCH v9 06/14] KVM: Make dirty ring exclusive to dirty bitmap log

2020-05-23 Thread Peter Xu
There's no good reason to use both the dirty bitmap logging and the
new dirty ring buffer to track dirty bits.  We should be able to even
support both of them at the same time, but it could complicate things
which could actually help little.  Let's simply make it the rule
before we enable dirty ring on any arch, that we don't allow these two
interfaces to be used together.

The big world switch would be KVM_CAP_DIRTY_LOG_RING capability
enablement.  That's where we'll switch from the default dirty logging
way to the dirty ring way.  As long as kvm->dirty_ring_size is setup
correctly, we'll once and for all switch to the dirty ring buffer mode
for the current virtual machine.

Signed-off-by: Peter Xu 
---
 Documentation/virt/kvm/api.rst |  7 +++
 virt/kvm/kvm_main.c| 12 
 2 files changed, 19 insertions(+)

diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
index aa54a34077b7..d56f86ba05a0 100644
--- a/Documentation/virt/kvm/api.rst
+++ b/Documentation/virt/kvm/api.rst
@@ -6225,3 +6225,10 @@ make sure all the existing dirty gfns are flushed to the 
dirty rings.
 
 The dirty ring can gets full.  When it happens, the KVM_RUN of the
 vcpu will return with exit reason KVM_EXIT_DIRTY_LOG_FULL.
+
+NOTE: the capability KVM_CAP_DIRTY_LOG_RING and the corresponding
+ioctl KVM_RESET_DIRTY_RINGS are mutual exclusive to the existing ioctl
+KVM_GET_DIRTY_LOG.  After enabling KVM_CAP_DIRTY_LOG_RING with an
+acceptable dirty ring size, the virtual machine will switch to the
+dirty ring tracking mode.  Further ioctls to either KVM_GET_DIRTY_LOG
+or KVM_CLEAR_DIRTY_LOG will fail.
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index daca53ed5a74..9639cf8d8c9c 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1355,6 +1355,10 @@ int kvm_get_dirty_log(struct kvm *kvm, struct 
kvm_dirty_log *log,
unsigned long n;
unsigned long any = 0;
 
+   /* Dirty ring tracking is exclusive to dirty log tracking */
+   if (kvm->dirty_ring_size)
+   return -EINVAL;
+
*memslot = NULL;
*is_dirty = 0;
 
@@ -1416,6 +1420,10 @@ static int kvm_get_dirty_log_protect(struct kvm *kvm, 
struct kvm_dirty_log *log)
unsigned long *dirty_bitmap_buffer;
bool flush;
 
+   /* Dirty ring tracking is exclusive to dirty log tracking */
+   if (kvm->dirty_ring_size)
+   return -EINVAL;
+
as_id = log->slot >> 16;
id = (u16)log->slot;
if (as_id >= KVM_ADDRESS_SPACE_NUM || id >= KVM_USER_MEM_SLOTS)
@@ -1524,6 +1532,10 @@ static int kvm_clear_dirty_log_protect(struct kvm *kvm,
unsigned long *dirty_bitmap_buffer;
bool flush;
 
+   /* Dirty ring tracking is exclusive to dirty log tracking */
+   if (kvm->dirty_ring_size)
+   return -EINVAL;
+
as_id = log->slot >> 16;
id = (u16)log->slot;
if (as_id >= KVM_ADDRESS_SPACE_NUM || id >= KVM_USER_MEM_SLOTS)
-- 
2.26.2



Re: [PATCH] sparc32: use PUD rather than PGD to get PMD in srmmu_nocache_init()

2020-05-23 Thread Guenter Roeck
Hi,

On Fri, May 22, 2020 at 10:23:09PM -0700, Mike Rapoport wrote:
> The kbuild test robot reported the following warning:
> 
>   arch/sparc/mm/srmmu.c: In function 'srmmu_nocache_init': 
> arch/sparc/mm/srmmu.c:300:9: error: variable 'pud' set but not used 
> [-Werror=unused-but-set-variable]
>   300 |  pud_t *pud;
> 
> This warning is caused by misprint in the page table traversal in
> srmmu_nocache_init() function which accessed a PMD entry using PGD
> rather than PUD.
> 
> Since sparc32 has only 3 page table levels, the PGD and PUD are
> essentially the same and usage of __nocache_fix() removed the type
> checking.
> 
> Use PUD for the consistency and to silence the compiler warning.
> 
> Fixes: 7235db268a2777bc38 ("sparc32: use pgtable-nopud instead of 
> 4level-fixup")
> Reported-by: kbuild test robot 
> Signed-off-by: Mike Rapoport 
> Signed-off-by: Andrew Morton 
> Cc: David S. Miller 
> Cc: Anatoly Pugachev 
> Cc: 
> Link: http://lkml.kernel.org/r/20200520132005.gm1059...@linux.ibm.com
> Signed-off-by: Linus Torvalds 
> ---
>  arch/sparc/mm/srmmu.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
> index b7c94de70cca..e9f7af32da07 100644
> --- a/arch/sparc/mm/srmmu.c
> +++ b/arch/sparc/mm/srmmu.c
> @@ -333,7 +333,7 @@ static void __init srmmu_nocache_init(void)
>   pgd = pgd_offset_k(vaddr);
>   p4d = p4d_offset(__nocache_fix(pgd), vaddr);
>   pud = pud_offset(__nocache_fix(p4d), vaddr);
> - pmd = pmd_offset(__nocache_fix(pgd), vaddr);
> + pmd = pmd_offset(__nocache_fix(pud), vaddr);
>   pte = pte_offset_kernel(__nocache_fix(pmd), vaddr);
>  
>   pteval = ((paddr >> 4) | SRMMU_ET_PTE | SRMMU_PRIV);
> -- 
> 2.17.1

This quite innocent looking patch crashes all my sparc32 boot tests.
Crash log and bisect results below. Reverting it fixes the problem.

Guenter

---
# bad: [423b8baf18a8c03f2d6fa99aa447ed0da189bb95] Merge branch 'akpm' (patches 
from Andrew)
# good: [051143e1602d90ea71887d92363edd539d411de5] Merge tag 
'apparmor-pr-2020-05-21' of 
git://git.kernel.org/pub/scm/linux/kernel/git/jj/linux-apparmor
git bisect start 'HEAD' '051143e1602d'
# good: [e644645abf4788e919beeb97925fb6bf43e890a2] Merge tag 'scsi-fixes' of 
git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
git bisect good e644645abf4788e919beeb97925fb6bf43e890a2
# good: [8f261041b18ee80ad8afdd1621c909c4df9f6cc3] Merge tag 'staging-5.7-rc7' 
of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging
git bisect good 8f261041b18ee80ad8afdd1621c909c4df9f6cc3
# good: [23f0dac848412dafd197566b62d831d5a68b5b6b] Merge tag 
'driver-core-5.7-rc7' of 
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core
git bisect good 23f0dac848412dafd197566b62d831d5a68b5b6b
# good: [33cd65e73abd693c00c4156cf23677c453b41b3b] kasan: disable branch 
tracing for core runtime
git bisect good 33cd65e73abd693c00c4156cf23677c453b41b3b
# bad: [c2bc26f7ca1ff1165bb6669a7a420ffd2ced] sparc32: use PUD rather than 
PGD to get PMD in srmmu_nocache_init()
git bisect bad c2bc26f7ca1ff1165bb6669a7a420ffd2ced
# good: [f7fa1876af81512444631d324adb77383f56c37a] MAINTAINERS: update email 
address for Naoya Horiguchi
git bisect good f7fa1876af81512444631d324adb77383f56c37a
# first bad commit: [c2bc26f7ca1ff1165bb6669a7a420ffd2ced] sparc32: use PUD 
rather than PGD to get PMD in srmmu_nocache_init()

---
Configuration device id QEMU version 1 machine id 36
Probing SBus slot 0 offset 0
Probing SBus slot 1 offset 0
Probing SBus slot 2 offset 0
Probing SBus slot 3 offset 0
Probing SBus slot 4 offset 0
Probing SBus slot 5 offset 0
Invalid FCode start byte
CPUs: 1 x FMI,MB86904
UUID: ----
Welcome to OpenBIOS v1.1 built on Oct 28 2019 17:08
  Type 'help' for detailed information
[sparc] Kernel already loaded
switching to new context:
PROMLIB: obio_ranges 1
PROMLIB: Sun Boot Prom Version 3 Revision 2
Linux version 5.7.0-rc6-00161-g423b8baf18a8 (gro...@server.roeck-us.net) (gcc 
version 6.5.0 (Buildroot 2018.11-rc2-00071-g4310260), GNU ld (GNU Binutils) 
2.31.1) #1 Sat May 23 11:57:22 PDT 2020
printk: bootconsole [earlyprom0] enabled
ARCH: SUN4M
TYPE: SPARCstation Classic
Ethernet address: 52:54:00:12:34:56
Unable to handle kernel paging request at virtual address d944
tsk->{mm,active_mm}->context = 
tsk->{mm,active_mm}->pgd = fc00
  \|/  \|/
  "@'/ ,. \`@"
  /_| \__/ |_\
 \__U_/
swapper(0): Oops [#1]
CPU: 0 PID: 0 Comm: swapper Not tainted 5.7.0-rc6-00161-g423b8baf18a8 #1
PSR: 04901fc3 PC: f06592a0 NPC: f06592a4 Y: Not tainted
PC: 
%G: 0008 f06c   cd4403f0  fc00 006c  f0622000 ec00
%O: 0006c200 03f0  0c00 f06c   1000  f0623d48 0c00
RPC: <0xc00>
%L: f067f000 f067f1d4  f067f000 f067f344  0fff 000f  1400 fc0003f0
%I: 

Re: [PATCH v1 07/25] lockdep: Add preemption disabled assertion API

2020-05-23 Thread Peter Zijlstra
On Sat, May 23, 2020 at 04:59:42PM +0200, Sebastian A. Siewior wrote:
> On 2020-05-22 19:55:03 [+0200], Peter Zijlstra wrote:

> > That is both more consistent with the things you claim it's modelled
> > after and also completely avoids that header dependency.
> 
> So we need additionally: 
> 
> - #include  in include/linux/flex_proportions.h
>   and I think un another file as well.
> 
> - write_seqcount_t_begin_nested() as a define
> 
> - write_seqcount_t_begin() as a define
> 
> Any "static inline" in the header file using
> lockdep_assert_preemption_disabled() will tro to complain about missing
> current-> define. But yes, it will work otherwise.

Because...? /me rummages around.. Ah you're proposing sticking this in
seqcount itself and then header hell.

Moo.. ok I'll go have another look on Monday.


Re: [PATCH v2 0/4] mm/gup, drm/i915: refactor gup_fast, convert to pin_user_pages()

2020-05-23 Thread John Hubbard

On 2020-05-23 02:41, Chris Wilson wrote:

Quoting John Hubbard (2020-05-22 06:19:27)

The purpose of posting this series is to launch a test in the
intel-gfx-ci tree. (The patches have already been merged into Andrew's
linux-mm tree.)

This applies to today's linux.git (note the base-commit tag at the
bottom).

Changes since V1:

* Fixed a bug in the refactoring patch: added FOLL_FAST_ONLY to the
   list of gup_flags *not* to WARN() on. This lead to a failure in the
   first intel-gfx-ci test run [1].

[1] 
https://lore.kernel.org/r/159008745422.32320.5724805750977048...@build.alporthouse.com


Ran this through our CI, warn and subsequent lockup were gone. That

DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1;
t=1590273216; bh=oK85oUq4LCrgTs8kxvJryKE7a7GUQfAveFtGpNOU2dQ=;
h=X-PGP-Universal:Subject:To:CC:References:From:X-Nvconfidentiality:
 Message-ID:Date:User-Agent:MIME-Version:In-Reply-To:
 X-Originating-IP:X-ClientProxiedBy:Content-Type:Content-Language:
 Content-Transfer-Encoding;
b=QoI4eJbYYVxcoARKgFJdRrxzB/GBPqy5yKIF46/pjR75LEiZvvAX947VBwywSMYhx
 It8aQpMm6kMaF/rxiv0IPBf3tNGxNziWBAAhDXCyNqmvAS5s1HfdQh5ZoYbyDynKbJ
 uF+u9JjBOYo5uTnn3IUaGPRgl/p9k6OhwRhbJ9nYreDwIF1/1pPeo97jwP2jW7AtDf
 xDO5iJhGmwLYHPzRLilgiDdLbNhIGAP1XJ/4t/DByshidOUalduU7HxVQ9IOnysnCw
 QcqSlpyPgx5LkJOvs63gO8n28hHJnoJ4FggNXC3D311lBWRuD7iekdP5WuvmrxUb8N
 rZKwTpl0vJl9w==


Yea! Thanks again for these test runs. I really don't like posting
patches that I can't run-time test, but this CI system mitigates
that pretty well.



lockup is worrying me now, but that doesn't seem to be an issue from
this series.



I do think it's worth following up on. And it seems like it would be
very easy to repro: just hack in a forced failure at the call site of
pin_user_pages_fast_only(), and follow the breadcrumbs.




The i915 changes were simple enough, I would have computed the pin flags
just once (since the readonly bit is static, that would be interesting
if that was allowed to change mid gup :)
Reviewed-by: Chris Wilson 
-Chris



Thanks for the review! And if lifting that check up higher in the call
stack is desired, I'm all in favor of that being done...in a separate
patch. :)

I'm trying to keep a very light touch when converting these call sites.

thanks,
--
John Hubbard
NVIDIA


Re: [PATCH v2 0/7] Share events between metrics

2020-05-23 Thread Jiri Olsa
On Fri, May 22, 2020 at 10:56:59AM -0700, Ian Rogers wrote:

SNIP

> >> >   #11 0x004b6911 in cmd_test (argc=1, argv=0x7fffd7f0) 
> >> > at tests/builtin-test.c:772
> >> >   #12 0x004e977b in run_builtin (p=0xa7eee8 , 
> >> > argc=3, argv=0x7fffd7f0) at perf.c:312
> >> >   #13 0x004e99e8 in handle_internal_command (argc=3, 
> >> > argv=0x7fffd7f0) at perf.c:364
> >> >   #14 0x004e9b2f in run_argv (argcp=0x7fffd64c, 
> >> > argv=0x7fffd640) at perf.c:408
> >> >   #15 0x004e9efb in main (argc=3, argv=0x7fffd7f0) at 
> >> > perf.c:538
> >> >
> >> > attached patch fixes it for me, but I'm not sure this
> >> > should be necessary
> >>
> >> ... applying the patch below makes the segfault go away. Ian, Ack? I can
> >> fold it into the patch introducing the problem.
> >
> >
> > I suspect this patch is a memory leak. The underlying issue is likely the 
> > outstanding hashmap_clear fix in libbpf. Let me check.
> >
> > Thanks,
> > Ian
> 
> Tested:
> $ git checkout -b testing acme/tmp.perf/core
> $ make ...
> $ perf test 7
> 7: Simple expression parser  : FAILED!
> $ git cherry-pick 6bca339175bf
> [acme-perf-expr-testing 4614bd252003] libbpf: Fix memory leak and
> possible double-free in hashmap__c

yep, it fixes the issue for me, but I see that under different commit number:

  229bf8bf4d91 libbpf: Fix memory leak and possible double-free in 
hashmap__clear

jirka

> lear
> Author: Andrii Nakryiko 
> Date: Tue Apr 28 18:21:04 2020 -0700
> 1 file changed, 7 insertions(+)
> $ make ...
> $ perf test 7
> 7: Simple expression parser  : Ok
> 
> I'd prefer we took the libbpf fix as initializing over the top of the
> hashmap will leak. This fix is in the tools/perf/util/hashmap.c.
> 
> Thanks,
> Ian
> 
> >> - Arnaldo
> >>
> >> > jirka
> >> >
> >> >
> >> > ---

SNIP



Re: [PATCH net-next v2 4/4] net: dp83869: Add RGMII internal delay configuration

2020-05-23 Thread Andrew Lunn
> > Any why is your PHY special, in that is does care about out of range
> > delays, when others using new the new core helper don't?
> 
> We are not rounding to nearest here.  Basically the helper works to find the
> best match
> 
> If the delay passed in is less than or equal to the smallest delay then
> return the smallest delay index
> 
> If the delay passed in is greater then the largest delay then return the max
> delay index

+   /* Find an approximate index by looking up the table */
+   if (delay > delay_values[i - 1] &&
+   delay < delay_values[i]) {
+   if (delay - delay_values[i - 1] < delay_values[i] - 
delay)
+   return i - 1;
+   else
+   return i;

This appears to round to the nearest value when it is not an exact
match.

The documentation is a hint to the DT developer what value to put in
DT. By saying it rounders, the developer does not need to go digging
through the source code to find an exact value, otherwise -EINVAL will
be returned. They can just use the value the HW engineer suggested,
and the PHY will pick whatever is nearest.

> Not sure what you mean about this PHY being special.  This helper is
> not PHY specific.

As you said, if out of range, the helper returns the top/bottom
value. Your PHY is special, the top/bottom value is not good enough,
you throw an error.

The point of helpers is to give uniform behaviour. We have one line
helpers, simply because they give uniform behaviour, rather than have
each driver do it subtlety different. But it also means drivers should
try to not add additional constraints over what the helper already
has, unless it is actually required by the hardware.

> After I think about this more I am thinking a helper may be over kill here
> and the delay to setting should be done within the PHY driver itself

The helper is useful, it will result in uniform handling of rounding
between DT values and what the PHY can actually do. But please also
move your range check and error message inside the helper.

 Andrew


arch/powerpc/kexec/ima.c:156:21: sparse: sparse: incorrect type in assignment (different base types)

2020-05-23 Thread kbuild test robot
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
master
head:   423b8baf18a8c03f2d6fa99aa447ed0da189bb95
commit: 793b08e2efff3ec020c5c5861d00ed394fcdd488 powerpc/kexec: Move kexec 
files into a dedicated subdir.
date:   6 months ago
config: powerpc-randconfig-s001-20200524 (attached as .config)
compiler: powerpc64-linux-gcc (GCC) 9.3.0
reproduce:
# apt-get install sparse
# sparse version: v0.6.1-193-gb8fad4bc-dirty
git checkout 793b08e2efff3ec020c5c5861d00ed394fcdd488
# save the attached .config to linux build tree
make W=1 C=1 ARCH=powerpc CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot 


sparse warnings: (new ones prefixed by >>)

>> arch/powerpc/kexec/ima.c:156:21: sparse: sparse: incorrect type in 
>> assignment (different base types) @@expected unsigned int [usertype] tmp 
>> @@got restrunsigned int [usertype] tmp @@
>> arch/powerpc/kexec/ima.c:156:21: sparse:expected unsigned int [usertype] 
>> tmp
>> arch/powerpc/kexec/ima.c:156:21: sparse:got restricted __be32 [usertype]
>> arch/powerpc/kexec/ima.c:161:21: sparse: sparse: incorrect type in 
>> assignment (different base types) @@expected unsigned long long 
>> [usertype] tmp @@got nsigned long long [usertype] tmp @@
>> arch/powerpc/kexec/ima.c:161:21: sparse:expected unsigned long long 
>> [usertype] tmp
>> arch/powerpc/kexec/ima.c:161:21: sparse:got restricted __be64 [usertype]

vim +156 arch/powerpc/kexec/ima.c

ab6b1d1fc4aae6 arch/powerpc/kernel/ima_kexec.c Thiago Jung Bauermann 2016-12-19 
 147  
ab6b1d1fc4aae6 arch/powerpc/kernel/ima_kexec.c Thiago Jung Bauermann 2016-12-19 
 148  static int write_number(void *p, u64 value, int cells)
ab6b1d1fc4aae6 arch/powerpc/kernel/ima_kexec.c Thiago Jung Bauermann 2016-12-19 
 149  {
ab6b1d1fc4aae6 arch/powerpc/kernel/ima_kexec.c Thiago Jung Bauermann 2016-12-19 
 150if (cells == 1) {
ab6b1d1fc4aae6 arch/powerpc/kernel/ima_kexec.c Thiago Jung Bauermann 2016-12-19 
 151u32 tmp;
ab6b1d1fc4aae6 arch/powerpc/kernel/ima_kexec.c Thiago Jung Bauermann 2016-12-19 
 152  
ab6b1d1fc4aae6 arch/powerpc/kernel/ima_kexec.c Thiago Jung Bauermann 2016-12-19 
 153if (value > U32_MAX)
ab6b1d1fc4aae6 arch/powerpc/kernel/ima_kexec.c Thiago Jung Bauermann 2016-12-19 
 154return -EINVAL;
ab6b1d1fc4aae6 arch/powerpc/kernel/ima_kexec.c Thiago Jung Bauermann 2016-12-19 
 155  
ab6b1d1fc4aae6 arch/powerpc/kernel/ima_kexec.c Thiago Jung Bauermann 2016-12-19 
@156tmp = cpu_to_be32(value);
ab6b1d1fc4aae6 arch/powerpc/kernel/ima_kexec.c Thiago Jung Bauermann 2016-12-19 
 157memcpy(p, , sizeof(tmp));
ab6b1d1fc4aae6 arch/powerpc/kernel/ima_kexec.c Thiago Jung Bauermann 2016-12-19 
 158} else if (cells == 2) {
ab6b1d1fc4aae6 arch/powerpc/kernel/ima_kexec.c Thiago Jung Bauermann 2016-12-19 
 159u64 tmp;
ab6b1d1fc4aae6 arch/powerpc/kernel/ima_kexec.c Thiago Jung Bauermann 2016-12-19 
 160  
ab6b1d1fc4aae6 arch/powerpc/kernel/ima_kexec.c Thiago Jung Bauermann 2016-12-19 
@161tmp = cpu_to_be64(value);
ab6b1d1fc4aae6 arch/powerpc/kernel/ima_kexec.c Thiago Jung Bauermann 2016-12-19 
 162memcpy(p, , sizeof(tmp));
ab6b1d1fc4aae6 arch/powerpc/kernel/ima_kexec.c Thiago Jung Bauermann 2016-12-19 
 163} else
ab6b1d1fc4aae6 arch/powerpc/kernel/ima_kexec.c Thiago Jung Bauermann 2016-12-19 
 164return -EINVAL;
ab6b1d1fc4aae6 arch/powerpc/kernel/ima_kexec.c Thiago Jung Bauermann 2016-12-19 
 165  
ab6b1d1fc4aae6 arch/powerpc/kernel/ima_kexec.c Thiago Jung Bauermann 2016-12-19 
 166return 0;
ab6b1d1fc4aae6 arch/powerpc/kernel/ima_kexec.c Thiago Jung Bauermann 2016-12-19 
 167  }
ab6b1d1fc4aae6 arch/powerpc/kernel/ima_kexec.c Thiago Jung Bauermann 2016-12-19 
 168  

:: The code at line 156 was first introduced by commit
:: ab6b1d1fc4aae6b8bd6fb1422405568094c9b40f powerpc: ima: send the kexec 
buffer to the next kernel

:: TO: Thiago Jung Bauermann 
:: CC: Linus Torvalds 

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org


.config.gz
Description: application/gzip


Re: [PATCH net-next v2 4/4] net: dp83869: Add RGMII internal delay configuration

2020-05-23 Thread Dan Murphy

Andrew

On 5/23/20 10:09 AM, Andrew Lunn wrote:

+   dp83869->tx_id_delay = DP83869_RGMII_CLK_DELAY_INV;
+   ret = of_property_read_u32(of_node, "tx-internal-delay-ps",
+  >tx_id_delay);
+   if (!ret && dp83869->tx_id_delay > dp83869_internal_delay[delay_size]) {
+   phydev_err(phydev,
+  "tx-internal-delay value of %u out of range\n",
+  dp83869->tx_id_delay);
+   return -EINVAL;
+   }

This is the kind of validation that I would be expecting from the PHY
library to do, in fact, since you use Device Tree standard property, I
would expect you only need to pass the maximum delay value and some
storage for your array of delays.

Actually the PHY library will return either the 0th index if the value is to
small or the max index if the value is to large

based on the array passed in so maybe this check is unnecessary.

Hi Dan

I'm not sure the helper is implementing the best behaviour. Rounded to
the nearest when within the supported range is O.K. But if the request
is outside the range, i would report an error.


Hope this email does not bounce.


Any why is your PHY special, in that is does care about out of range
delays, when others using new the new core helper don't?


We are not rounding to nearest here.  Basically the helper works to find 
the best match


If the delay passed in is less than or equal to the smallest delay then 
return the smallest delay index


If the delay passed in is greater then the largest delay then return the 
max delay index


Not sure what you mean about this PHY being special.  This helper is not 
PHY specific.


After I think about this more I am thinking a helper may be over kill 
here and the delay to setting should be done within the PHY driver itself


Dan


Andrew


Re: [PATCH v2] fpga: dfl: afu: convert get_user_pages() --> pin_user_pages()

2020-05-23 Thread John Hubbard

On 2020-05-23 13:57, Moritz Fischer wrote:

On Fri, May 22, 2020 at 06:52:34PM -0700, John Hubbard wrote:

On 2020-05-19 13:14, John Hubbard wrote:

This code was using get_user_pages_fast(), in a "Case 2" scenario
(DMA/RDMA), using the categorization from [1]. That means that it's
time to convert the get_user_pages_fast() + put_page() calls to
pin_user_pages_fast() + unpin_user_pages() calls.

There is some helpful background in [2]: basically, this is a small
part of fixing a long-standing disconnect between pinning pages, and
file systems' use of those pages.

[1] Documentation/core-api/pin_user_pages.rst

[2] "Explicit pinning of user-space pages":
  https://lwn.net/Articles/807108/

Cc: Xu Yilun 
Cc: Wu Hao 
Cc: Moritz Fischer 
Cc: linux-f...@vger.kernel.org
Signed-off-by: John Hubbard 



Hi Moritz and FPGA developers,

Is this OK? And if so, is it going into your git tree? Or should I
send it up through a different tree? (I'm new to the FPGA development
model).


I can take it, sorry for sluggish response.



That's great news, thanks Moritz! Sorry to be pushy, just didn't want it
to get lost. :)

thanks,
--
John Hubbard
NVIDIA


Re: [RFC][PATCH 0/4] x86/entry: disallow #DB more

2020-05-23 Thread Peter Zijlstra
On Sat, May 23, 2020 at 02:59:40PM +0200, Peter Zijlstra wrote:
> On Fri, May 22, 2020 at 03:13:57PM -0700, Andy Lutomirski wrote:

> > This is great, except that the unconditional DR7 write is going to
> > seriously hurt perf performance.  Fortunately, no one cares about
> > perf, right? :)
> 
> Good point, so the trivial optimization is below. I couldn't find
> instruction latency numbers for DRn load/stores anywhere. I'm hoping
> loads are cheap.

+   u64 empty = 0, read = 0, write = 0;
+   unsigned long dr7;
+
+   for (i=0; i<100; i++) {
+   u64 s;
+
+   s = rdtsc();
+   barrier_nospec();
+   barrier_nospec();
+   empty += rdtsc() - s;
+
+   s = rdtsc();
+   barrier_nospec();
+   dr7 = native_get_debugreg(7);
+   barrier_nospec();
+   read += rdtsc() - s;
+
+   s = rdtsc();
+   barrier_nospec();
+   native_set_debugreg(7, 0);
+   barrier_nospec();
+   write += rdtsc() - s;
+   }
+
+   printk("XXX: %ld %ld %ld\n", empty, read, write);


[1.628125] XXX: 2800 2404 19600

IOW, reading DR7 is basically free, and certainly cheaper than looking
at cpu_dr7 which would probably be an insta cache miss.

Which seems to suggest KVM can go pound sand. Maybe they can fix
themselves with some paravirt love.




[PATCH] staging: rtl8723bs: Use shared header constants

2020-05-23 Thread Pascal Terjan
This is one of the 9 drivers redefining rfc1042_header.

Signed-off-by: Pascal Terjan 
---
 drivers/staging/rtl8723bs/core/rtw_recv.c | 15 ++-
 drivers/staging/rtl8723bs/include/rtw_recv.h  |  2 --
 drivers/staging/rtl8723bs/os_dep/recv_linux.c |  5 +++--
 3 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/rtl8723bs/core/rtw_recv.c 
b/drivers/staging/rtl8723bs/core/rtw_recv.c
index 5245098b9ecf..dc58822924b4 100644
--- a/drivers/staging/rtl8723bs/core/rtw_recv.c
+++ b/drivers/staging/rtl8723bs/core/rtw_recv.c
@@ -10,14 +10,11 @@
 #include 
 #include 
 #include 
+#include 
 
 static u8 SNAP_ETH_TYPE_IPX[2] = {0x81, 0x37};
 static u8 SNAP_ETH_TYPE_APPLETALK_AARP[2] = {0x80, 0xf3};
 
-u8 rtw_rfc1042_header[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
-/* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
-u8 rtw_bridge_tunnel_header[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
-
 static void rtw_signal_stat_timer_hdl(struct timer_list *t);
 
 void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv)
@@ -1625,11 +1622,11 @@ sint wlanhdr_to_ethhdr(union recv_frame *precvframe)
psnap_type = ptr+pattrib->hdrlen + pattrib->iv_len+SNAP_SIZE;
/* convert hdr + possible LLC headers into Ethernet header */
/* eth_type = (psnap_type[0] << 8) | psnap_type[1]; */
-   if ((!memcmp(psnap, rtw_rfc1042_header, SNAP_SIZE) &&
-   (memcmp(psnap_type, SNAP_ETH_TYPE_IPX, 2)) &&
-   (memcmp(psnap_type, SNAP_ETH_TYPE_APPLETALK_AARP, 2))) ||
-   /* eth_type != ETH_P_AARP && eth_type != ETH_P_IPX) || */
-!memcmp(psnap, rtw_bridge_tunnel_header, SNAP_SIZE)) {
+   if ((!memcmp(psnap, rfc1042_header, SNAP_SIZE) &&
+memcmp(psnap_type, SNAP_ETH_TYPE_IPX, 2) &&
+memcmp(psnap_type, SNAP_ETH_TYPE_APPLETALK_AARP, 2)) ||
+   /* eth_type != ETH_P_AARP && eth_type != ETH_P_IPX) || */
+   !memcmp(psnap, bridge_tunnel_header, SNAP_SIZE)) {
/* remove RFC1042 or Bridge-Tunnel encapsulation and replace 
EtherType */
bsnaphdr = true;
} else
diff --git a/drivers/staging/rtl8723bs/include/rtw_recv.h 
b/drivers/staging/rtl8723bs/include/rtw_recv.h
index 98c3e92245b7..a851b818ef0e 100644
--- a/drivers/staging/rtl8723bs/include/rtw_recv.h
+++ b/drivers/staging/rtl8723bs/include/rtw_recv.h
@@ -38,8 +38,6 @@
 #define RX_MAX_QUEUE   2
 
 #define MAX_SUBFRAME_COUNT 64
-extern u8 rtw_rfc1042_header[];
-extern u8 rtw_bridge_tunnel_header[];
 
 /* for Rx reordering buffer control */
 struct recv_reorder_ctrl
diff --git a/drivers/staging/rtl8723bs/os_dep/recv_linux.c 
b/drivers/staging/rtl8723bs/os_dep/recv_linux.c
index 2a7b9922b1d4..eb4d1c3008fe 100644
--- a/drivers/staging/rtl8723bs/os_dep/recv_linux.c
+++ b/drivers/staging/rtl8723bs/os_dep/recv_linux.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 
 void rtw_os_free_recvframe(union recv_frame *precvframe)
 {
@@ -71,9 +72,9 @@ _pkt *rtw_os_alloc_msdu_pkt(union recv_frame *prframe, u16 
nSubframe_Length, u8
eth_type = RTW_GET_BE16(_skb->data[6]);
 
if (sub_skb->len >= 8 &&
-   ((!memcmp(sub_skb->data, rtw_rfc1042_header, SNAP_SIZE) &&
+   ((!memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) &&
  eth_type != ETH_P_AARP && eth_type != ETH_P_IPX) ||
-!memcmp(sub_skb->data, rtw_bridge_tunnel_header, SNAP_SIZE))) {
+!memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE))) {
/*
 * remove RFC1042 or Bridge-Tunnel encapsulation and replace
 * EtherType
-- 
2.27.0.rc0.183.gde8f92d652-goog



[PATCH] atmel: Use shared constant for rfc1042 header

2020-05-23 Thread Pascal Terjan
This is one of the 9 drivers redefining rfc1042_header.

Signed-off-by: Pascal Terjan 
---
 drivers/net/wireless/atmel/atmel.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/wireless/atmel/atmel.c 
b/drivers/net/wireless/atmel/atmel.c
index 74538085cfb7..d5875836068c 100644
--- a/drivers/net/wireless/atmel/atmel.c
+++ b/drivers/net/wireless/atmel/atmel.c
@@ -798,7 +798,6 @@ static void tx_update_descriptor(struct atmel_private 
*priv, int is_bcast,
 
 static netdev_tx_t start_tx(struct sk_buff *skb, struct net_device *dev)
 {
-   static const u8 SNAP_RFC1024[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 
};
struct atmel_private *priv = netdev_priv(dev);
struct ieee80211_hdr header;
unsigned long flags;
@@ -853,7 +852,7 @@ static netdev_tx_t start_tx(struct sk_buff *skb, struct 
net_device *dev)
}
 
if (priv->use_wpa)
-   memcpy(, SNAP_RFC1024, ETH_ALEN);
+   memcpy(, rfc1042_header, ETH_ALEN);
 
header.frame_control = cpu_to_le16(frame_ctl);
/* Copy the wireless header into the card */
-- 
2.27.0.rc0.183.gde8f92d652-goog



[PATCH] libertas: Use shared constant for rfc1042 header

2020-05-23 Thread Pascal Terjan
This is one of the 9 drivers redefining rfc1042_header.

Signed-off-by: Pascal Terjan 
---
 drivers/net/wireless/marvell/libertas/rx.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/net/wireless/marvell/libertas/rx.c 
b/drivers/net/wireless/marvell/libertas/rx.c
index 58a1fc433b73..f28aa09d1f9e 100644
--- a/drivers/net/wireless/marvell/libertas/rx.c
+++ b/drivers/net/wireless/marvell/libertas/rx.c
@@ -62,9 +62,6 @@ int lbs_process_rxed_packet(struct lbs_private *priv, struct 
sk_buff *skb)
struct rxpd *p_rx_pd;
int hdrchop;
struct ethhdr *p_ethhdr;
-   static const u8 rfc1042_eth_hdr[] = {
-   0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00
-   };
 
BUG_ON(!skb);
 
@@ -102,7 +99,7 @@ int lbs_process_rxed_packet(struct lbs_private *priv, struct 
sk_buff *skb)
sizeof(p_rx_pkt->eth803_hdr.src_addr));
 
if (memcmp(_rx_pkt->rfc1042_hdr,
-  rfc1042_eth_hdr, sizeof(rfc1042_eth_hdr)) == 0) {
+  rfc1042_header, sizeof(rfc1042_header)) == 0) {
/*
 *  Replace the 803 header and rfc1042 header (llc/snap) with an
 *EthernetII header, keep the src/dst and snap_type 
(ethertype)
-- 
2.27.0.rc0.183.gde8f92d652-goog



Re: linux-next: build failure after merge of the tip tree

2020-05-23 Thread Paul E. McKenney
On Sat, May 23, 2020 at 09:05:24PM +0200, Thomas Gleixner wrote:
> "Paul E. McKenney"  writes:
> > On Sat, May 23, 2020 at 11:54:26AM +0200, Thomas Gleixner wrote:
> >> core/rcu is the one which diverged and caused the merge conflict with
> >> PPC to happen twice. So Paul needs to remove the stale core/rcu bits and
> >> rebase on the current version (which is not going to change again).
> >
> > So there will be another noinstr-rcu-* tag, and I will rebase on top
> > of that, correct?  If so, fair enough!
> 
> Here you go: noinstr-rcu-220-05-23
> 
> I wanted this to be 2020 and not 220 but I noticed after pushing it
> out. I guess it still does the job :)

Now -that- is what I call an old-school tag name!!!  ;-)

I remerged, rebased, and pushed to -rcu branch "dev".

If it survives testing, I will reset -rcu branch "rcu/next" as well.

Thanx, Paul


[PATCH] staging: rtl8712: Fix IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK

2020-05-23 Thread Pascal Terjan
The value in shared headers was fixed 9 years ago in commit 8d661f1e462d
("ieee80211: correct IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK macro") and
while looking at using shared headers for other duplicated constants
I noticed this driver uses the old value.

The macros are also defined twice in this file so I am deleting the
second definition.

Signed-off-by: Pascal Terjan 
---
 drivers/staging/rtl8712/wifi.h | 9 +
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/drivers/staging/rtl8712/wifi.h b/drivers/staging/rtl8712/wifi.h
index be731f1a2209..91b65731fcaa 100644
--- a/drivers/staging/rtl8712/wifi.h
+++ b/drivers/staging/rtl8712/wifi.h
@@ -440,7 +440,7 @@ static inline unsigned char *get_hdr_bssid(unsigned char 
*pframe)
 /* block-ack parameters */
 #define IEEE80211_ADDBA_PARAM_POLICY_MASK 0x0002
 #define IEEE80211_ADDBA_PARAM_TID_MASK 0x003C
-#define IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK 0xFFA0
+#define IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK 0xFFC0
 #define IEEE80211_DELBA_PARAM_TID_MASK 0xF000
 #define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800
 
@@ -532,13 +532,6 @@ struct ieee80211_ht_addt_info {
 #define IEEE80211_HT_IE_NON_GF_STA_PRSNT   0x0004
 #define IEEE80211_HT_IE_NON_HT_STA_PRSNT   0x0010
 
-/* block-ack parameters */
-#define IEEE80211_ADDBA_PARAM_POLICY_MASK 0x0002
-#define IEEE80211_ADDBA_PARAM_TID_MASK 0x003C
-#define IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK 0xFFA0
-#define IEEE80211_DELBA_PARAM_TID_MASK 0xF000
-#define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800
-
 /*
  * A-PMDU buffer sizes
  * According to IEEE802.11n spec size varies from 8K to 64K (in powers of 2)
-- 
2.27.0.rc0.183.gde8f92d652-goog



  1   2   3   4   >