x86/sgx: uapi change proposal

2018-12-18 Thread Jarkko Sakkinen
I have pretty much figured out how to change the driver implementation
from VMA based to file based. Most of the code in the driver can be
reused with not that enormous changes. I think it is a clue that the
architecture is somewhat right because changing the driver this
radically does not seem to require any changes to the core.

Using anon inode is the right choice because it is more robust interface
to be able to create multiple enclaves.

The only remaining open that I have when it comes to implementing this
is the backing storage. From API perspective the most robust choice
would be to revert to use shmem file. It would be easy then to create a
complete construction flow without any dependencies to mm_struct.

I do recognize the issue with accounting but to which process the
backing storage should be accounted anyway in this new paradigm.

I've attached the new uapi header to this email that I'm going forward
with.

/Jarkko
/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
/**
 * Copyright(c) 2016-18 Intel Corporation.
 */
#ifndef _UAPI_ASM_X86_SGX_H
#define _UAPI_ASM_X86_SGX_H

#include 
#include 

#define SGX_MAGIC 0xA4

#define SGX_IOC_ENCLAVE_CREATE \
	_IOW(SGX_MAGIC, 0x00, struct sgx_enclave_create)
#define SGX_IOC_ENCLAVE_ADD_PAGE \
	_IOW(SGX_MAGIC, 0x01, struct sgx_enclave_add_page)
#define SGX_IOC_ENCLAVE_INIT \
	_IOW(SGX_MAGIC, 0x02, struct sgx_enclave_init)
#define SGX_IOC_ENCLAVE_SET_ATTRIBUTE \
	_IOW(SGX_MAGIC, 0x03, struct sgx_enclave_set_attribute)

/* IOCTL return values */
#define SGX_POWER_LOST_ENCLAVE		0x4000

/**
 * struct sgx_enclave_create - parameter structure for the
 * %SGX_IOC_ENCLAVE_CREATE ioctl
 * @src:	address for the SECS page data
 * @enclave_fd:	file handle to the enclave address space (out)
 */
struct sgx_enclave_create  {
	__u64	src;
	__u64	enclave_fd;
};

/**
 * struct sgx_enclave_add_page - parameter structure for the
 *   %SGX_IOC_ENCLAVE_ADD_PAGE ioctl
 * @eclave_fd:	file handle to the enclave address space
 * @src:	address for the page data
 * @secinfo:	address for the SECINFO data
 * @mrmask:	bitmask for the measured 256 byte chunks
 */
struct sgx_enclave_add_page {
	__u64	enclave_fd;
	__u64	src;
	__u64	secinfo;
	__u16	mrmask;
} __attribute__((__packed__));


/**
 * struct sgx_enclave_init - parameter structure for the
 *   %SGX_IOC_ENCLAVE_INIT ioctl
 * @eclave_fd:	file handle to the enclave address space
 * @sigstruct:	address for the SIGSTRUCT data
 */
struct sgx_enclave_init {
	__u64	enclave_fd;
	__u64	sigstruct;
};

/**
 * struct sgx_enclave_set_attribute - parameter structure for the
 *  %SGX_IOC_ENCLAVE_INIT ioctl
 * @addr:		address within the ELRANGE
 * @eclave_fd:		file handle to the enclave address space
 * @attribute_fd:	file handle of the attribute file in the securityfs
 */
struct sgx_enclave_set_attribute {
	__u64	enclave_fd;
	__u64	attribute_fd;
};

#endif /* _UAPI_ASM_X86_SGX_H */


[PATCH] drm/amd/display: Remove duplicate header

2018-12-18 Thread Brajeswar Ghosh
Remove custom_float.h which is included more than once

Signed-off-by: Brajeswar Ghosh 
---
 drivers/gpu/drm/amd/display/dc/dcn10/dcn10_hw_sequencer.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_hw_sequencer.c 
b/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_hw_sequencer.c
index 193184affefb..3e21c2d26998 100644
--- a/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_hw_sequencer.c
+++ b/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_hw_sequencer.c
@@ -40,7 +40,6 @@
 #include "ipp.h"
 #include "mpc.h"
 #include "reg_helper.h"
-#include "custom_float.h"
 #include "dcn10_hubp.h"
 #include "dcn10_hubbub.h"
 #include "dcn10_cm_common.h"
-- 
2.17.1



Mysterious delays on power-related events in userspace

2018-12-18 Thread L29Ah
Hi all,

When i connect various USB devices or get different ACPI(?) events like 
opening/closing the lid (as seen by acpid) on my Thinkpad X230 with 
Linux-4.19.5, i get random delays (usually ~10s, but may also be ~20s and 
~30s). USB-related messages show up in dmesg instantly as they should tho. This 
was occuring to me for a few years already. What can be wrong with my system?
eudev bug report: https://github.com/gentoo/eudev/issues/153

CC me please.

-- 
()  ascii ribbon campaign - against html mail
/\  http://arc.pasp.de/   - against proprietary attachments


[PATCH 1/1] wlcore: Fix memory leak in case wl12xx_fetch_firmware failure

2018-12-18 Thread Zumeng Chen
Release fw_status, raw_fw_status, and tx_res_if when wl12xx_fetch_firmware
failed instead of meaningless goto out to avoid the following memory leak
reports(Only the last one listed):

unreferenced object 0xc28a9a00 (size 512):
  comm "kworker/0:4", pid 31298, jiffies 2783204 (age 203.290s)
  hex dump (first 32 bytes):
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
  backtrace:
[<6624adab>] kmemleak_alloc+0x40/0x74
[<500ddb31>] kmem_cache_alloc_trace+0x1ac/0x270
[] wl12xx_chip_wakeup+0xc4/0x1fc [wlcore]
[<76c5db53>] wl1271_op_add_interface+0x4a4/0x8f4 [wlcore]
[] drv_add_interface+0xa4/0x1a0 [mac80211]
[<65bac325>] ieee80211_reconfig+0x9c0/0x1644 [mac80211]
[<2817c80e>] ieee80211_restart_work+0x90/0xc8 [mac80211]
[<7e1d425a>] process_one_work+0x284/0x42c
[<55f9432e>] worker_thread+0x2fc/0x48c
[] kthread+0x148/0x160
[<63144b13>] ret_from_fork+0x14/0x2c
[< (null)>] (null)
[<1f6e7715>] 0x

Signed-off-by: Zumeng Chen 
---
 drivers/net/wireless/ti/wlcore/main.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/ti/wlcore/main.c 
b/drivers/net/wireless/ti/wlcore/main.c
index 26b1873..2e12de8 100644
--- a/drivers/net/wireless/ti/wlcore/main.c
+++ b/drivers/net/wireless/ti/wlcore/main.c
@@ -1085,8 +1085,11 @@ static int wl12xx_chip_wakeup(struct wl1271 *wl, bool 
plt)
goto out;
 
ret = wl12xx_fetch_firmware(wl, plt);
-   if (ret < 0)
-   goto out;
+   if (ret < 0) {
+   kfree(wl->fw_status);
+   kfree(wl->raw_fw_status);
+   kfree(wl->tx_res_if);
+   }
 
 out:
return ret;
-- 
2.7.5



Re: [PATCH v5 2/2] media: usb: pwc: Don't use coherent DMA buffers for ISO transfer

2018-12-18 Thread Christoph Hellwig
On Tue, Dec 18, 2018 at 06:48:03PM +0900, Tomasz Figa wrote:
> > So as I said you can call dma_alloc_attrs with DMA_ATTR_NON_CONSISTENT
> > in a loop with a suitably small chunk size, then stuff the results into
> > a scatterlist and map that again for the device share with if you don't
> > want a single contigous region.  You just have to either deal with
> > non-contigous access from the kernel or use vmap and the right vmap
> > cache flushing helpers.
> 
> The point is that you didn't have to do this small chunk loop without
> DMA_ATTR_NON_CONSISTENT, so it's at least inconsistent now and not
> sure why it could be better than just a loop of alloc_page().

You have to do it if you want to map the addresses for a second device.

> > I would advice against new non-consistent users until this series
> > goes through, mostly because dma_cache_sync is such an amazing bad
> > API.  Otherwise things will just work at the allocation side, you'll
> > just need to be careful to transfer ownership between the cpu and
> > the device(s) carefully using the dma_sync_* APIs.
> 
> Just to clarify, the actual code isn't very likely to surface any time
> soon. so I assume it would be after this series lands.
> 
> We will however need an API that can transparently handle both cases
> of contiguous (without IOMMU) and page-by-page allocations (with
> IOMMU) behind the scenes, like the current dma_alloc_attrs() without
> DMA_ATTR_NON_CONSISTENT.

Is the use case to then share the memory between multiples devices
or just for a single device?  The latter case is generally easy, the
former is rather more painful.


Re: linux-next: build warnings after merge of the wireless-drivers-next tree

2018-12-18 Thread Kalle Valo
Stephen Rothwell  writes:

> On Fri, 30 Nov 2018 12:05:55 +1100 Stephen Rothwell  
> wrote:
>>
>> After merging the wireless-drivers-next tree, today's linux-next build
>> (x86_64 allmodconfig) produced these warnings:
>> 
>> drivers/net/wireless/intel/iwlwifi/iwl-drv.c: In function 
>> 'iwl_parse_tlv_firmware':
>> drivers/net/wireless/intel/iwlwifi/iwl-drv.c:1098:7: warning: this statement 
>> may fall through [-Wimplicit-fallthrough=]
>> if (iwlwifi_mod_params.enable_ini)
>>^
>> drivers/net/wireless/intel/iwlwifi/iwl-drv.c:1100:3: note: here
>>default:
>>^~~
>> drivers/net/wireless/intel/iwlwifi/iwl-dbg-tlv.c: In function 
>> 'iwl_parse_fw_dbg_tlv':
>> drivers/net/wireless/intel/iwlwifi/iwl-dbg-tlv.c:203:4: warning: this 
>> statement may fall through [-Wimplicit-fallthrough=]
>> iwl_fw_dbg_copy_tlv(trans, tlv, true);
>> ^
>> drivers/net/wireless/intel/iwlwifi/iwl-dbg-tlv.c:204:3: note: here
>>default:
>>^~~
>> 
>> Introduced by commit
>> 
>>   f14cda6f3b31 ("iwlwifi: trans: parse and store debug ini TLVs")
>> 
>> These are noted because I use -Wimplict-fallthrough
>> 
>> The warnings can be suppressed by adding a comment like
>>  /* fall through */
>> at the appropriate place to indicate that the fallthough is intended.
>
> I am still seeing these warnings (but in the net-next tree now) and I
> do not see a fix patch in the wireless-drivers-next tree.

Luca did submit a patch[1] for cfg80211 to fix those but I don't see any
patches for iwlwifi (even in the one pending pull request he sent), not
sure what happened. I know that Luca is already on holidays but adding
Emmanuel, maybe he can help here?

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

-- 
Kalle Valo


Re: RT-Kernel boot stalls because of change in fs/dcache.c

2018-12-18 Thread Schrempf Frieder
+ linux-rt-users

On 17.12.18 11:42, Frieder Schrempf wrote:
> Hi,
> 
> I have tried to boot a 4.14-Kernel with the RT-patches and 
> PREEMPT_RT_FULL on an i.MX6UL board. Unfortunately the boot stalls at 
> some point and never finishes.
> 
> I did some bisecting and found out, that reverting this change: [1], 
> makes the board boot correctly.
> 
> Can anyone help to come up with a proper fix for this?
> 
> Thanks,
> Frieder
> 
> [1]: 
> https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git/commit/?h=v4.14-rt=56684d21f7f8341f7a5ed1433714112f49294590
>  
> 

Re: [PATCH RFC v2 5/8] drm/bridge: dw-hdmi: support dynamically get input/out color info

2018-12-18 Thread Laurent Pinchart
Hello,

On Wednesday, 19 December 2018 09:26:08 EET Andrzej Hajda wrote:
> On 30.11.2018 14:42, Neil Armstrong wrote:
> > From: Zheng Yang 
> > 
> > To get input/output bus_format/enc_format dynamically, this patch
> > 
> > introduce following funstion in plat_data:
> > - get_input_bus_format
> > - get_output_bus_format
> > - get_enc_in_encoding
> > - get_enc_out_encoding
> 
> It seems fishy. On one side description says about dynamic resolution of
> formats and encodings.
> 
> On the other side these functions as only argument takes platform_data
> which should be rather static.
> 
> Where is this "dynamic" thing? The only usage of these callbacks I have
> found in next patches is also not dynamic, the functions just return
> some static value.
> 
> Moreover function takes void* argument, which is again something
> suspicious, why cannot you pass know structure?
> 
> And finally encoding usually should depend on display mode, it should
> not depend only static data.
> 
> 
> What kind of problems do you want to solve here?

I would add that this doesn't seem to be specific to dw-hdmi in any way. I'd 
prefer an API at the drm_bridge level to handle this.

> > Signed-off-by: Zheng Yang 
> > Signed-off-by: Neil Armstrong 
> > ---
> > 
> >  drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 28 +--
> >  include/drm/bridge/dw_hdmi.h  |  5 
> >  2 files changed, 26 insertions(+), 7 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
> > b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c index
> > 4a9a24e854db..bd564ffdf18b 100644
> > --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
> > +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
> > @@ -1810,6 +1810,7 @@ static void hdmi_disable_overflow_interrupts(struct
> > dw_hdmi *hdmi)> 
> >  static int dw_hdmi_setup(struct dw_hdmi *hdmi, struct drm_display_mode
> >  *mode) {
> >  
> > int ret;
> > 
> > +   void *data = hdmi->plat_data->phy_data;
> > 
> > hdmi_disable_overflow_interrupts(hdmi);
> > 
> > @@ -1821,10 +1822,13 @@ static int dw_hdmi_setup(struct dw_hdmi *hdmi,
> > struct drm_display_mode *mode)> 
> > dev_dbg(hdmi->dev, "CEA mode used vic=%d\n", hdmi->vic);
> > 
> > }
> > 
> > -   if ((hdmi->vic == 6) || (hdmi->vic == 7) ||
> > -   (hdmi->vic == 21) || (hdmi->vic == 22) ||
> > -   (hdmi->vic == 2) || (hdmi->vic == 3) ||
> > -   (hdmi->vic == 17) || (hdmi->vic == 18))
> > +   if (hdmi->plat_data->get_enc_out_encoding)
> > +   hdmi->hdmi_data.enc_out_encoding =
> > +   hdmi->plat_data->get_enc_out_encoding(data);
> > +   else if ((hdmi->vic == 6) || (hdmi->vic == 7) ||
> > +(hdmi->vic == 21) || (hdmi->vic == 22) ||
> > +(hdmi->vic == 2) || (hdmi->vic == 3) ||
> > +(hdmi->vic == 17) || (hdmi->vic == 18))
> > 
> > hdmi->hdmi_data.enc_out_encoding = V4L2_YCBCR_ENC_601;
> > 
> > else
> > 
> > hdmi->hdmi_data.enc_out_encoding = V4L2_YCBCR_ENC_709;
> > 
> > @@ -1833,21 +1837,31 @@ static int dw_hdmi_setup(struct dw_hdmi *hdmi,
> > struct drm_display_mode *mode)> 
> > hdmi->hdmi_data.video_mode.mpixelrepetitioninput = 0;
> > 
> > /* TOFIX: Get input format from plat data or fallback to RGB888 */
> > 
> > -   if (hdmi->plat_data->input_bus_format)
> > +   if (hdmi->plat_data->get_input_bus_format)
> > +   hdmi->hdmi_data.enc_in_bus_format =
> > +   hdmi->plat_data->get_input_bus_format(data);
> > +   else if (hdmi->plat_data->input_bus_format)
> > 
> > hdmi->hdmi_data.enc_in_bus_format =
> > 
> > hdmi->plat_data->input_bus_format;
> > 
> > else
> > 
> > hdmi->hdmi_data.enc_in_bus_format = MEDIA_BUS_FMT_RGB888_1X24;
> > 
> > /* TOFIX: Get input encoding from plat data or fallback to none */
> > 
> > -   if (hdmi->plat_data->input_bus_encoding)
> > +   if (hdmi->plat_data->get_enc_in_encoding)
> > +   hdmi->hdmi_data.enc_in_encoding =
> > +   hdmi->plat_data->get_enc_in_encoding(data);
> > +   else if (hdmi->plat_data->input_bus_encoding)
> > 
> > hdmi->hdmi_data.enc_in_encoding =
> > 
> > hdmi->plat_data->input_bus_encoding;
> > 
> > else
> > 
> > hdmi->hdmi_data.enc_in_encoding = V4L2_YCBCR_ENC_DEFAULT;
> > 
> > /* TOFIX: Default to RGB888 output format */
> > 
> > -   hdmi->hdmi_data.enc_out_bus_format = MEDIA_BUS_FMT_RGB888_1X24;
> > +   if (hdmi->plat_data->get_output_bus_format)
> > +   hdmi->hdmi_data.enc_out_bus_format =
> > +   hdmi->plat_data->get_output_bus_format(data);
> > +   else
> > +   hdmi->hdmi_data.enc_out_bus_format = MEDIA_BUS_FMT_RGB888_1X24;
> > 
> > hdmi->hdmi_data.pix_repet_factor = 0;
> > hdmi->hdmi_data.hdcp_enable = 0;
> > 
> > diff --git a/include/drm/bridge/dw_hdmi.h b/include/drm/bridge/dw_hdmi.h

linux-next: Tree for Dec 19

2018-12-18 Thread Stephen Rothwell
Hi all,

Changes since 20181218:

New tree: kgdb-dt

The rdma tree still had its build failure so I used a supplied patch.

The kvm tree gained a conflict against the tip tree and a build failure
for which I applied a merge fix patch.

Non-merge commits (relative to Linus' tree): 9805
 10005 files changed, 472520 insertions(+), 262947 deletions(-)



I have created today's linux-next tree at
git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
(patches at http://www.kernel.org/pub/linux/kernel/next/ ).  If you
are tracking the linux-next tree using git, you should not use "git pull"
to do so as that will try to merge the new linux-next release with the
old one.  You should use "git fetch" and checkout or reset to the new
master.

You can see which trees have been included by looking in the Next/Trees
file in the source.  There are also quilt-import.log and merge.log
files in the Next directory.  Between each merge, the tree was built
with a ppc64_defconfig for powerpc, an allmodconfig for x86_64, a
multi_v7_defconfig for arm and a native build of tools/perf. After
the final fixups (if any), I do an x86_64 modules_install followed by
builds for x86_64 allnoconfig, powerpc allnoconfig (32 and 64 bit),
ppc44x_defconfig, allyesconfig and pseries_le_defconfig and i386, sparc
and sparc64 defconfig. And finally, a simple boot test of the powerpc
pseries_le_defconfig kernel in qemu (with and without kvm enabled).

Below is a summary of the state of the merge.

I am currently merging 292 trees (counting Linus' and 69 trees of bug
fix patches pending for the current merge release).

Stats about the size of the tree over time can be seen at
http://neuling.org/linux-next-size.html .

Status of my local build tests will be at
http://kisskb.ellerman.id.au/linux-next .  If maintainers want to give
advice about cross compilers/configs that work, we are always open to add
more builds.

Thanks to Randy Dunlap for doing many randconfig builds.  And to Paul
Gortmaker for triage and bug fixes.

-- 
Cheers,
Stephen Rothwell

$ git checkout master
$ git reset --hard stable
Merging origin/master (ddfbab46539f Merge tag 'scsi-fixes' of 
git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi)
Merging fixes/master (d8c137546ef8 powerpc: tag implicit fall throughs)
Merging kbuild-current/fixes (ccda4af0f4b9 Linux 4.20-rc2)
Merging arc-current/for-curr (bc2cbf2cc506 ARC: perf: map generic branches to 
correct hardware condition)
Merging arm-current/fixes (c2a3831df6dc ARM: 8816/1: dma-mapping: fix potential 
uninitialized return)
Merging arm64-fixes/for-next/fixes (3238c359acee arm64: dma-mapping: Fix 
FORCE_CONTIGUOUS buffer clearing)
Merging m68k-current/for-linus (58c116fb7dc6 m68k/sun3: Remove is_medusa and 
m68k_pgtable_cachemode)
Merging powerpc-fixes/fixes (a225f1567405 powerpc/ptrace: replace 
ptrace_report_syscall() with a tracehook call)
Merging sparc/master (cf76c364a1e1 Merge tag 'scsi-fixes' of 
git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi)
Merging fscrypt-current/for-stable (ae64f9bd1d36 Linux 4.15-rc2)
Merging net/master (a915b982d8f5 VSOCK: Send reset control packet when socket 
is partially bound)
Merging bpf/master (bcb671c2fa0e bpf: promote bpf_perf_event.h to mandatory 
UAPI header)
Merging ipsec/master (4a135e538962 xfrm_user: fix freeing of xfrm states on 
acquire)
Merging netfilter/master (9e69efd45321 Merge branch 'vhost-fixes')
Merging ipvs/master (feb9f55c33e5 netfilter: nft_dynset: allow dynamic updates 
of non-anonymous set)
Merging wireless-drivers/master (eca1e56ceedd iwlwifi: mvm: don't send 
GEO_TX_POWER_LIMIT to old firmwares)
Merging mac80211/master (442147d0ea77 mac80211: free skb fraglist before 
freeing the skb)
Merging rdma-fixes/for-rc (37fbd834b4e4 IB/core: Fix oops in 
netdev_next_upper_dev_rcu())
Merging sound-current/for-linus (0bea4cc83835 ALSA: hda/realtek: Enable audio 
jacks of ASUS UX433FN/UX333FA with ALC294)
Merging sound-asoc-fixes/for-linus (1e7a78c1a3ca Merge branch 'asoc-4.20' into 
asoc-linus)
Merging regmap-fixes/for-linus (40e020c129cf Linux 4.20-rc6)
Merging regulator-fixes/for-linus (71b6b0e0d12f Merge branch 'regulator-4.20' 
into regulator-linus)
Merging spi-fixes/for-linus (111c49e0eef9 Merge branch 'spi-4.20' into 
spi-linus)
Merging pci-current/for-linus (1063a5148ac9 PCI/AER: Queue one GHES event, not 
several uninitialized ones)
Merging driver-core.current/driver-core-linus (2595646791c3 Linux 4.20-rc5)
Merging tty.current/tty-linus (3c9dc275dba1 Revert "serial: 8250: Fix clearing 
FIFOs in RS485 mode again")
Merging usb.current/usb-linus (2419f30a4a4f USB: xhci: fix 'broken_suspend' 
placement in struct xchi_hcd)
Merging usb-gadget-fixes/fixes (069caf5950df USB: omap_udc: fix rejection of 
out transfers when DMA is used)
Merging usb-serial-fixes/usb-linus (28a86092b175 USB: serial: option: add Telit 
LN940 series)
Merging usb-ch

[PATCH V5 3/3] misc/pvpanic : add pci dependency in Kconfig

2018-12-18 Thread Peng Hao
Add PCI dependency for pvpanic in Kconfig.

Signed-off-by: Peng Hao 
---
 drivers/misc/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index f417b06..5ff8ca4 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -515,7 +515,7 @@ config MISC_RTSX
 
 config PVPANIC
tristate "pvpanic device support"
-   depends on HAS_IOMEM && (ACPI || OF)
+   depends on HAS_IOMEM && (ACPI || OF || PCI)
help
  This driver provides support for the pvpanic device.  pvpanic is
  a paravirtualized device provided by QEMU; it lets a virtual machine
-- 
1.8.3.1



[PATCH V5 1/3] misc/pvpanic: return 0 for empty body register function

2018-12-18 Thread Peng Hao
Return 0 for empty body register function normally.

Signed-off-by: Peng Hao 
---
v4 --> v5 : handle all typo "drvier/driver" in funtion name. 

v3 --> v4 : use pcim* function instead of pci* function.
handle typo "drvier/driver" in funtion name. 

v2 --> v3 : handle a uninitialized variable in some path.

v2 --> v1 : arch=sh don't support pci, adjust  CONFIG_PCI macro. 

v1 : QEMU community requires additional PCI devices to simulate PVPANIC devices
so that some architectures can not occupy precious less than 4G of memory 
space.

 drivers/misc/pvpanic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/misc/pvpanic.c b/drivers/misc/pvpanic.c
index 3150dc2..f84ed30 100644
--- a/drivers/misc/pvpanic.c
+++ b/drivers/misc/pvpanic.c
@@ -125,7 +125,7 @@ static void pvpanic_unregister_acpi_driver(void)
 #else
 static int pvpanic_register_acpi_driver(void)
 {
-   return -ENODEV;
+   return 0;
 }
 
 static void pvpanic_unregister_acpi_driver(void) {}
-- 
1.8.3.1



[PATCH V5 2/3] misc/pvpanic : add pci interface for pvpanic

2018-12-18 Thread Peng Hao
Support pvpanic as a pci device in guest kernel.

Signed-off-by: Peng Hao 
---
 drivers/misc/pvpanic.c | 72 --
 1 file changed, 70 insertions(+), 2 deletions(-)

diff --git a/drivers/misc/pvpanic.c b/drivers/misc/pvpanic.c
index f84ed30..c30bf62 100644
--- a/drivers/misc/pvpanic.c
+++ b/drivers/misc/pvpanic.c
@@ -13,9 +13,12 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
+#define PCI_VENDOR_ID_REDHAT 0x1b36
+#define PCI_DEVICE_ID_REDHAT_PVPANIC 0x0101
 static void __iomem *base;
 
 #define PVPANIC_PANICKED(1 << 0)
@@ -172,12 +175,76 @@ static int pvpanic_mmio_remove(struct platform_device 
*pdev)
.remove = pvpanic_mmio_remove,
 };
 
+#ifdef CONFIG_PCI
+static const struct pci_device_id pvpanic_pci_id_tbl[]  = {
+   { PCI_DEVICE(PCI_VENDOR_ID_REDHAT, PCI_DEVICE_ID_REDHAT_PVPANIC),},
+   {}
+};
+
+static int pvpanic_pci_probe(struct pci_dev *pdev,
+const struct pci_device_id *ent)
+{
+   int ret;
+
+   ret = pcim_enable_device(pdev);
+   if (ret < 0)
+   return ret;
+
+   ret = pcim_iomap_regions(pdev, 1 << 0, pci_name(pdev));
+   if (ret)
+   return ret;
+
+   base = pcim_iomap_table(pdev)[0];
+
+   atomic_notifier_chain_register(_notifier_list,
+  _panic_nb);
+   return 0;
+}
+
+static void pvpanic_pci_remove(struct pci_dev *pdev)
+{
+   atomic_notifier_chain_unregister(_notifier_list,
+_panic_nb);
+}
+
+static struct pci_driver pvpanic_pci_driver = {
+   .name = "pvpanic-pci",
+   .id_table = pvpanic_pci_id_tbl,
+   .probe =pvpanic_pci_probe,
+   .remove =   pvpanic_pci_remove,
+};
+
+static int pvpanic_register_pci_driver(void)
+{
+   return pci_register_driver(_pci_driver);
+}
+
+static void pvpanic_unregister_pci_driver(void)
+{
+   pci_unregister_driver(_pci_driver);
+}
+#else
+static int pvpanic_register_pci_driver(void)
+{
+   return 0;
+}
+
+static void pvpanic_unregister_pci_driver(void) {}
+#endif
+
 static int __init pvpanic_mmio_init(void)
 {
+   int r1, r2;
+
if (acpi_disabled)
-   return platform_driver_register(_mmio_driver);
+   r1 = platform_driver_register(_mmio_driver);
+   else
+   r1 = pvpanic_register_acpi_driver();
+   r2 = pvpanic_register_pci_driver();
+   if (r1 && r2) /* all drivers register failed */
+   return 1;
else
-   return pvpanic_register_acpi_driver();
+   return 0;
 }
 
 static void __exit pvpanic_mmio_exit(void)
@@ -186,6 +253,7 @@ static void __exit pvpanic_mmio_exit(void)
platform_driver_unregister(_mmio_driver);
else
pvpanic_unregister_acpi_driver();
+   pvpanic_unregister_pci_driver();
 }
 
 module_init(pvpanic_mmio_init);
-- 
1.8.3.1



Re: [PATCH V2 1/9] jump_label: Add for_each_label_entry helper

2018-12-18 Thread Daniel Bristot de Oliveira
On 12/18/18 10:19 PM, Borislav Petkov wrote:
> On Tue, Dec 18, 2018 at 05:46:30PM +0100, Daniel Bristot de Oliveira wrote:
>> This patch adds the helper:
>>  for_each_label_entry(key, entry, stop)
>>
>> For the "for each jump label entry" for defined as:
>>  for (; (entry < stop) && (jump_entry_key(entry) == key); entry++)
>>
>> Simplifying the reading and usage.
> 
> Please avoid writing "This patch" in a commit message and also what it
> does - that should be obvious. Instead say something like:
> 
> "Add a helper macro to make jump entry iteration code more readable."
> 
> or so.

Right! I will change it!

> But then, IINM, this macro is being used only once. Isn't that a bit too
> much? I mean, you could just as well do:
> 
>   # iterate over each jump entry
>   for (; (entry < stop) && (jump_entry_key(entry) == key); entry++) {
> 
> and have it even more readable without introducing macro which is not
> going to be used elsewhere. Or is it going to...?

It is also used in the patch 9. But I can remove it, no problem.

Thoughts?

Thanks!

-- Daniel



Re: [PATCH v4 6/9] iommu/dma-iommu.c: Convert to use vm_insert_range

2018-12-18 Thread Souptick Joarder
On Tue, Dec 18, 2018 at 1:50 AM Souptick Joarder  wrote:
>
> Convert to use vm_insert_range() to map range of kernel
> memory to user vma.
>
> Signed-off-by: Souptick Joarder 
> Reviewed-by: Matthew Wilcox 

Cc'd: Robin Murphy
> ---
>  drivers/iommu/dma-iommu.c | 13 +++--
>  1 file changed, 3 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
> index d1b0475..de7ffd8 100644
> --- a/drivers/iommu/dma-iommu.c
> +++ b/drivers/iommu/dma-iommu.c
> @@ -622,17 +622,10 @@ struct page **iommu_dma_alloc(struct device *dev, 
> size_t size, gfp_t gfp,
>
>  int iommu_dma_mmap(struct page **pages, size_t size, struct vm_area_struct 
> *vma)
>  {
> -   unsigned long uaddr = vma->vm_start;
> -   unsigned int i, count = PAGE_ALIGN(size) >> PAGE_SHIFT;
> -   int ret = -ENXIO;
> +   unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT;
>
> -   for (i = vma->vm_pgoff; i < count && uaddr < vma->vm_end; i++) {
> -   ret = vm_insert_page(vma, uaddr, pages[i]);
> -   if (ret)
> -   break;
> -   uaddr += PAGE_SIZE;
> -   }
> -   return ret;
> +   return vm_insert_range(vma, vma->vm_start, pages + vma->vm_pgoff,
> +   count - vma->vm_pgoff);
>  }
>
>  static dma_addr_t __iommu_dma_map(struct device *dev, phys_addr_t phys,
> --
> 1.9.1
>


Re: [PATCH v4 2/2] trace nvme submit queue status

2018-12-18 Thread h...@lst.de
On Tue, Dec 18, 2018 at 05:19:00PM -0800, peng yu wrote:
> I think this change is nice. Will you submit this change or are you
> suggesting me to do it?

I've folded the changes in.


Re: [PATCH v2 14/17] staging: rtl8188eu: simplify null array initializations

2018-12-18 Thread Greg KH
On Tue, Dec 18, 2018 at 07:34:48PM +0100, Michael Straube wrote:
> Simplfy initialization of null arrays to improve readability
> and save some lines.
> 
> Signed-off-by: Michael Straube 
> ---
>  drivers/staging/rtl8188eu/core/rtw_mlme_ext.c | 4 ++--
>  drivers/staging/rtl8188eu/core/rtw_xmit.c | 6 ++
>  2 files changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c 
> b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
> index d3d211d8..2a42f80d1970 100644
> --- a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
> +++ b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
> @@ -17,7 +17,7 @@
>  #include 
>  #include 
>  
> -static u8 null_addr[ETH_ALEN] = {0, 0, 0, 0, 0, 0};
> +static u8 null_addr[ETH_ALEN] = {};
>  
>  /**
>  OUI definitions for the vendor specific IE
> @@ -5207,7 +5207,7 @@ u8 setkey_hdl(struct adapter *padapter, u8 *pbuf)
>   struct setkey_parm *pparm = (struct setkey_parm *)pbuf;
>   struct mlme_ext_priv *pmlmeext = >mlmeextpriv;
>   struct mlme_ext_info *pmlmeinfo = >mlmext_info;
> - u8 null_sta[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
> + u8 null_sta[ETH_ALEN] = {};

This just changed the type of the variable to a fixed size.  I'm
guessing it's ok, but it looks odd in a "cleanup patch"...

thanks,

greg k-h


[PATCH v4.14 1/1]: nvmem: imx-ocotp: account for addressing gaps to ensure consistent read/write on i.MX SoCs

2018-12-18 Thread Andrea Barisani


The nvmem-imx-ocotp driver does not currently handle addressing gaps between
OTP banks which can be present in i.MX System-on-Chip part numbers.

This leads to inconsistencies between the interpretation of the offset
argument in read and write operations, not only requiring specific
workarounds but also resulting in the impossibility of reading the entire OTP
bank.

Additionally this inconsistency violates the NVMEM subsystem principle of
exposing a userspace binary interface for read/write operations against a
pseudo-file.

This patch accounts for addressing gaps, depending on the specific i.MX model
being addressed.

Signed-off-by: Andrea Barisani 

---
 drivers/nvmem/imx-ocotp.c |   49 ++--
 1 file changed, 41 insertions(+), 8 deletions(-)

--- linux-4.14.89/drivers/nvmem/imx-ocotp.c.orig2018-12-18 
10:30:49.363322853 +0100
+++ linux-4.14.89/drivers/nvmem/imx-ocotp.c 2018-12-18 10:31:18.143778980 
+0100
@@ -114,6 +114,8 @@ static int imx_ocotp_read(void *context,
 {
struct ocotp_priv *priv = context;
unsigned int count;
+   unsigned int base_offset;
+   const char *compat;
u32 *buf = val;
int i, ret;
u32 index;
@@ -139,11 +141,42 @@ static int imx_ocotp_read(void *context,
goto read_end;
}
 
+   compat = of_get_property(priv->dev->of_node, "compatible", NULL);
+
for (i = index; i < (index + count); i++) {
-   *buf++ = readl(priv->base + IMX_OCOTP_OFFSET_B0W0 +
-  i * IMX_OCOTP_OFFSET_PER_WORD);
+   /*
+* On specific i.MX P/Ns there are addressing gaps between
+* contiguous OTP banks which must be accounted for when
+* reading OTP banks from mapped memory.
+*
+* This is necessary to make the imx_ocotp_read() offset
+* interpretation consistent with imx_ocotp_write(), which
+* does not require to account for gaps as it uses the offset
+* value to derive the bank index and pass it directly to the
+* OCOTP controller (rather than being used for mapped memory
+* addressing).
+*/
+   base_offset = IMX_OCOTP_OFFSET_B0W0 + i * 
IMX_OCOTP_OFFSET_PER_WORD;
+
+   if (strcmp(compat, "fsl,imx6sx-ocotp")) {
+   /* 44.5.43 [IMX6SXRM]
+* 256 bytes gap between Bank5 Word7 (21B_C6F0h, offset 
0x6f0) and
+* Bank10 Word1 (21B_CA10h, offset 0xa10)
+*/
+   if (base_offset > 0x6f0)
+   base_offset += 0x100;
+   } else if (strcmp(compat, "fsl,imx6ul-ocotp")) {
+   /* 35.5.59 [IMX6ULRM]
+* 256 bytes gap between Bank5 Word7 (21B_C6F0h, offset 
0x6f0) and
+* Bank6 Word0 (21B_C800h, offset 0x800)
+*/
+   if (base_offset > 0x6f0)
+   base_offset += 0x100;
+   }
+
+   *buf++ = readl(priv->base + base_offset);
 
-   /* 47.3.1.2
+   /* 47.3.1.2 [IMX6SDLRM]
 * For "read locked" registers 0xBADABADA will be returned and
 * HW_OCOTP_CTRL[ERROR] will be set. It must be cleared by
 * software before any new write, read or reload access can be
@@ -205,7 +238,7 @@ static int imx_ocotp_write(void *context
 
writel(timing, priv->base + IMX_OCOTP_ADDR_TIMING);
 
-   /* 47.3.1.3.2
+   /* 47.3.1.3.2 [IMX6SDLRM]
 * Check that HW_OCOTP_CTRL[BUSY] and HW_OCOTP_CTRL[ERROR] are clear.
 * Overlapped accesses are not supported by the controller. Any pending
 * write or reload must be completed before a write access can be
@@ -217,7 +250,7 @@ static int imx_ocotp_write(void *context
goto write_end;
}
 
-   /* 47.3.1.3.3
+   /* 47.3.1.3.3 [IMX6SDLRM]
 * Write the requested address to HW_OCOTP_CTRL[ADDR] and program the
 * unlock code into HW_OCOTP_CTRL[WR_UNLOCK]. This must be programmed
 * for each write access. The lock code is documented in the register
@@ -234,7 +267,7 @@ static int imx_ocotp_write(void *context
 
writel(ctrl, priv->base + IMX_OCOTP_ADDR_CTRL);
 
-   /* 47.3.1.3.4
+   /* 47.3.1.3.4 [IMX6SDLRM]
 * Write the data to the HW_OCOTP_DATA register. This will automatically
 * set HW_OCOTP_CTRL[BUSY] and clear HW_OCOTP_CTRL[WR_UNLOCK]. To
 * protect programming same OTP bit twice, before program OCOTP will
@@ -254,7 +287,7 @@ static int imx_ocotp_write(void *context
 */
writel(*buf, priv->base + IMX_OCOTP_ADDR_DATA);
 
-   /* 47.4.1.4.5
+   /* 47.4.1.4.5 [IMX6SDLRM]
 * Once complete, the controller will clear BUSY. A write 

Re: [PATCH RFC v2 5/8] drm/bridge: dw-hdmi: support dynamically get input/out color info

2018-12-18 Thread Andrzej Hajda
On 30.11.2018 14:42, Neil Armstrong wrote:
> From: Zheng Yang 
>
> To get input/output bus_format/enc_format dynamically, this patch
> introduce following funstion in plat_data:
>   - get_input_bus_format
>   - get_output_bus_format
>   - get_enc_in_encoding
>   - get_enc_out_encoding


It seems fishy. On one side description says about dynamic resolution of
formats and encodings.

On the other side these functions as only argument takes platform_data
which should be rather static.

Where is this "dynamic" thing? The only usage of these callbacks I have
found in next patches is also not dynamic, the functions just return
some static value.

Moreover function takes void* argument, which is again something
suspicious, why cannot you pass know structure?

And finally encoding usually should depend on display mode, it should
not depend only static data.


What kind of problems do you want to solve here?


Regards

Andrzej



>
> Signed-off-by: Zheng Yang 
> Signed-off-by: Neil Armstrong 
> ---
>  drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 28 +--
>  include/drm/bridge/dw_hdmi.h  |  5 
>  2 files changed, 26 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c 
> b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
> index 4a9a24e854db..bd564ffdf18b 100644
> --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
> +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
> @@ -1810,6 +1810,7 @@ static void hdmi_disable_overflow_interrupts(struct 
> dw_hdmi *hdmi)
>  static int dw_hdmi_setup(struct dw_hdmi *hdmi, struct drm_display_mode *mode)
>  {
>   int ret;
> + void *data = hdmi->plat_data->phy_data;
>  
>   hdmi_disable_overflow_interrupts(hdmi);
>  
> @@ -1821,10 +1822,13 @@ static int dw_hdmi_setup(struct dw_hdmi *hdmi, struct 
> drm_display_mode *mode)
>   dev_dbg(hdmi->dev, "CEA mode used vic=%d\n", hdmi->vic);
>   }
>  
> - if ((hdmi->vic == 6) || (hdmi->vic == 7) ||
> - (hdmi->vic == 21) || (hdmi->vic == 22) ||
> - (hdmi->vic == 2) || (hdmi->vic == 3) ||
> - (hdmi->vic == 17) || (hdmi->vic == 18))
> + if (hdmi->plat_data->get_enc_out_encoding)
> + hdmi->hdmi_data.enc_out_encoding =
> + hdmi->plat_data->get_enc_out_encoding(data);
> + else if ((hdmi->vic == 6) || (hdmi->vic == 7) ||
> +  (hdmi->vic == 21) || (hdmi->vic == 22) ||
> +  (hdmi->vic == 2) || (hdmi->vic == 3) ||
> +  (hdmi->vic == 17) || (hdmi->vic == 18))
>   hdmi->hdmi_data.enc_out_encoding = V4L2_YCBCR_ENC_601;
>   else
>   hdmi->hdmi_data.enc_out_encoding = V4L2_YCBCR_ENC_709;
> @@ -1833,21 +1837,31 @@ static int dw_hdmi_setup(struct dw_hdmi *hdmi, struct 
> drm_display_mode *mode)
>   hdmi->hdmi_data.video_mode.mpixelrepetitioninput = 0;
>  
>   /* TOFIX: Get input format from plat data or fallback to RGB888 */
> - if (hdmi->plat_data->input_bus_format)
> + if (hdmi->plat_data->get_input_bus_format)
> + hdmi->hdmi_data.enc_in_bus_format =
> + hdmi->plat_data->get_input_bus_format(data);
> + else if (hdmi->plat_data->input_bus_format)
>   hdmi->hdmi_data.enc_in_bus_format =
>   hdmi->plat_data->input_bus_format;
>   else
>   hdmi->hdmi_data.enc_in_bus_format = MEDIA_BUS_FMT_RGB888_1X24;
>  
>   /* TOFIX: Get input encoding from plat data or fallback to none */
> - if (hdmi->plat_data->input_bus_encoding)
> + if (hdmi->plat_data->get_enc_in_encoding)
> + hdmi->hdmi_data.enc_in_encoding =
> + hdmi->plat_data->get_enc_in_encoding(data);
> + else if (hdmi->plat_data->input_bus_encoding)
>   hdmi->hdmi_data.enc_in_encoding =
>   hdmi->plat_data->input_bus_encoding;
>   else
>   hdmi->hdmi_data.enc_in_encoding = V4L2_YCBCR_ENC_DEFAULT;
>  
>   /* TOFIX: Default to RGB888 output format */
> - hdmi->hdmi_data.enc_out_bus_format = MEDIA_BUS_FMT_RGB888_1X24;
> + if (hdmi->plat_data->get_output_bus_format)
> + hdmi->hdmi_data.enc_out_bus_format =
> + hdmi->plat_data->get_output_bus_format(data);
> + else
> + hdmi->hdmi_data.enc_out_bus_format = MEDIA_BUS_FMT_RGB888_1X24;
>  
>   hdmi->hdmi_data.pix_repet_factor = 0;
>   hdmi->hdmi_data.hdcp_enable = 0;
> diff --git a/include/drm/bridge/dw_hdmi.h b/include/drm/bridge/dw_hdmi.h
> index 7a02744ce0bc..2e797f782c51 100644
> --- a/include/drm/bridge/dw_hdmi.h
> +++ b/include/drm/bridge/dw_hdmi.h
> @@ -142,6 +142,11 @@ struct dw_hdmi_plat_data {
>   int (*configure_phy)(struct dw_hdmi *hdmi,
>const struct dw_hdmi_plat_data *pdata,
>unsigned long mpixelclock);
> +
> + unsigned long (*get_input_bus_format)(void *data);
> + unsigned long 

Re: [PATCH v2] dt-bindings: serial: sh-sci: Document r8a774c0 bindings

2018-12-18 Thread Greg Kroah-Hartman
On Tue, Dec 18, 2018 at 12:03:10PM +, Fabrizio Castro wrote:
> RZ/G2E (R8A774C0) SoC also has the R-Car Gen3 compatible SCIF and
> HSCIF ports, so document the SoC specific bindings.
> 
> Signed-off-by: Fabrizio Castro 
> Reviewed-by: Geert Uytterhoeven 
> Reviewed-by: Simon Horman 
> Reviewed-by: Rob Herring 
> ---
> v1->v2:
> * Fixed title according to Geert's comment
> 
> This patch depends on:
> https://patchwork.kernel.org/patch/10565543/

I don't have that patch in my tree, so can you please resend all of the
pending patches that you need applied so that I can?  Including this one
too.

thanks,

greg k-h


Re: [PATCH v4 3/9] drivers/firewire/core-iso.c: Convert to use vm_insert_range

2018-12-18 Thread Souptick Joarder
On Tue, Dec 18, 2018 at 4:15 PM Russell King - ARM Linux
 wrote:
>
> On Tue, Dec 18, 2018 at 01:52:46AM +0530, Souptick Joarder wrote:
> > Convert to use vm_insert_range to map range of kernel memory
> > to user vma.
> >
> > Signed-off-by: Souptick Joarder 
> > Reviewed-by: Matthew Wilcox 
> > ---
> >  drivers/firewire/core-iso.c | 15 ++-
> >  1 file changed, 2 insertions(+), 13 deletions(-)
> >
> > diff --git a/drivers/firewire/core-iso.c b/drivers/firewire/core-iso.c
> > index 35e784c..7bf28bb 100644
> > --- a/drivers/firewire/core-iso.c
> > +++ b/drivers/firewire/core-iso.c
> > @@ -107,19 +107,8 @@ int fw_iso_buffer_init(struct fw_iso_buffer *buffer, 
> > struct fw_card *card,
> >  int fw_iso_buffer_map_vma(struct fw_iso_buffer *buffer,
> > struct vm_area_struct *vma)
> >  {
> > - unsigned long uaddr;
> > - int i, err;
> > -
> > - uaddr = vma->vm_start;
> > - for (i = 0; i < buffer->page_count; i++) {
> > - err = vm_insert_page(vma, uaddr, buffer->pages[i]);
> > - if (err)
> > - return err;
> > -
> > - uaddr += PAGE_SIZE;
> > - }
> > -
> > - return 0;
> > + return vm_insert_range(vma, vma->vm_start, buffer->pages,
> > + buffer->page_count);
>
> This looks functionally equivalent.  Note that if we go with my
> proposal to your patch 4, that would cause an issue for this
> implementation.
>
> Maybe we need two functions, but that then causes problems with
> which function should be used (which makes it easy to get wrong.)

I think, apart from patch [4/9] and [6/9], all others places can be
directly replaced
with vm_insert_range(). [4/9] and [6/9] are the places where
*vma->vm_pgoff* need to be
considered and need to adjust *count* accordingly. In my opinion, bugs
around these
[4/9] & [6/9] can be fixed (raised during review) to accommodate it to
use vm_insert_range().
>
> I'm beginning to wonder if the risks of causing regressions and
> introducing bugs is actually worth the effort of trying to clean
> this up.
>
> --
> RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
> FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
> According to speedtest.net: 11.9Mbps down 500kbps up


Re: [PATCH] cifs: check kzalloc return

2018-12-18 Thread Nicholas Mc Guire
On Tue, Dec 18, 2018 at 09:33:58AM -0800, Joe Perches wrote:
> On Tue, 2018-12-18 at 17:27 +0100, Nicholas Mc Guire wrote:
> > kzalloc can return NULL so a check is needed. While there is a
> > check for ret_buf there is no check for the allocation of
> > ret_buf->crfid.fid - this check is thus added. Both call-sites
> > of tconInfoAlloc() check for NULL return of tconInfoAlloc()
> > so returning NULL on failure of kzalloc() here seems appropriate.
> > As the kzalloc() is the only thing here that can fail it is
> > moved to the beginning so as not to initialize other resources
> > on failure of kzalloc.
> > 
> > Signed-off-by: Nicholas Mc Guire 
> > Fixes: 3d4ef9a15343 ("smb3: fix redundant opens on root")
> > ---
> > 
> > Problem located with an experimental coccinelle script
> > 
> > While at it make checkpatch happy by using *ret_buf->crfid.fid
> > rather than struct cifs_fid.
> > 
> > Patch was compile tested with: x86_64_defconfig + CIFS=m
> > (with some unrelated smatch warnings and some pending cocci fixes)
> > 
> > Patch is against v4.20-rc7 (localversion-next is next-20181218)
> []
> > diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
> []
> > @@ -113,6 +113,13 @@ tconInfoAlloc(void)
> > struct cifs_tcon *ret_buf;
> > ret_buf = kzalloc(sizeof(struct cifs_tcon), GFP_KERNEL);
> > if (ret_buf) {
> > +   ret_buf->crfid.fid = kzalloc(sizeof(*ret_buf->crfid.fid),
> > +GFP_KERNEL);
> > +   if (!ret_buf->crfid.fid) {
> > +   kfree(ret_buf);
> > +   return NULL;
> > +   }
> > +
> > atomic_inc();
> > ret_buf->tidStatus = CifsNew;
> > ++ret_buf->tc_count;
> > @@ -120,8 +127,6 @@ tconInfoAlloc(void)
> > INIT_LIST_HEAD(_buf->tcon_list);
> > spin_lock_init(_buf->open_file_lock);
> > mutex_init(_buf->crfid.fid_mutex);
> > -   ret_buf->crfid.fid = kzalloc(sizeof(struct cifs_fid),
> > -GFP_KERNEL);
> > spin_lock_init(_buf->stat_lock);
> > atomic_set(_buf->num_local_opens, 0);
> > atomic_set(_buf->num_remote_opens, 0);
> 
> Perhaps use a more common style by returning early on the
> first possible failure too so the block can be unindented.
>

yup the restructured cleanup would be the better way to go

rather than making this two patches I guess it would be the
best to just skip the intermediate kzalloc only cleanup -
atleast I see little value in that intermediat step - so
could you take care of the kzalloc() in your refactoring 
please ?

thx!
hofrat
 
> Maybe as a separate cleanup patch.
> ---
>  fs/cifs/misc.c | 34 --
>  1 file changed, 20 insertions(+), 14 deletions(-)
> 
> diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
> index 113980dba4d8..bee203055b30 100644
> --- a/fs/cifs/misc.c
> +++ b/fs/cifs/misc.c
> @@ -111,21 +111,27 @@ struct cifs_tcon *
>  tconInfoAlloc(void)
>  {
>   struct cifs_tcon *ret_buf;
> - ret_buf = kzalloc(sizeof(struct cifs_tcon), GFP_KERNEL);
> - if (ret_buf) {
> - atomic_inc();
> - ret_buf->tidStatus = CifsNew;
> - ++ret_buf->tc_count;
> - INIT_LIST_HEAD(_buf->openFileList);
> - INIT_LIST_HEAD(_buf->tcon_list);
> - spin_lock_init(_buf->open_file_lock);
> - mutex_init(_buf->crfid.fid_mutex);
> - ret_buf->crfid.fid = kzalloc(sizeof(struct cifs_fid),
> -  GFP_KERNEL);
> - spin_lock_init(_buf->stat_lock);
> - atomic_set(_buf->num_local_opens, 0);
> - atomic_set(_buf->num_remote_opens, 0);
> +
> + ret_buf = kzalloc(sizeof(*ret_buf), GFP_KERNEL);
> + if (!ret_buf)
> + return NULL;
> + ret_buf->crfid.fid = kzalloc(sizeof(*ret_buf->crfid.fid), GFP_KERNEL);
> + if (!ret_buf->crfid.fid) {
> + kfree(ret_buf);
> + return NULL;
>   }
> +
> + atomic_inc();
> + ret_buf->tidStatus = CifsNew;
> + ++ret_buf->tc_count;
> + INIT_LIST_HEAD(_buf->openFileList);
> + INIT_LIST_HEAD(_buf->tcon_list);
> + spin_lock_init(_buf->open_file_lock);
> + mutex_init(_buf->crfid.fid_mutex);
> + spin_lock_init(_buf->stat_lock);
> + atomic_set(_buf->num_local_opens, 0);
> + atomic_set(_buf->num_remote_opens, 0);
> +
>   return ret_buf;
>  }
>  
> 


[v3, PATCH 0/2] add ethernet binding and modify ethernet driver for mt2712

2018-12-18 Thread Biao Huang
changes in v3:
resend this series base on the latest net-next tree.

changes in v2 as comments from Sean:
1. fix typo.
2. use capital letters for RMII/MII/RGMII in driver and bindings.

v1:
This new series is the result of discussion in:
http://lkml.org/lkml/2018/12/13/1007
http://lkml.org/lkml/2018/12/14/53

1. ethernet binding file move to this series.
2. remove fine tune property in device tree
3. remove fine tune flow in ethernet driver
4. set rgmii timing according to the value in device tree,
and don't care whether phy insert internal delay  or not.

Biao Huang (2):
  net-next: dt-binding: dwmac-mediatek: remove fine-tune property
  net-next: stmmac: dwmac-mediatek: remove fine-tune property

 .../devicetree/bindings/net/mediatek-dwmac.txt |   31 +++--
 .../net/ethernet/stmicro/stmmac/dwmac-mediatek.c   |   71 +++-
 2 files changed, 35 insertions(+), 67 deletions(-)

-- 
1.7.9.5



Re: [PATCH v15 2/2] Add oom victim's memcg to the oom context information

2018-12-18 Thread Tetsuo Handa
Andrew, will you fold below diff into "mm, oom: add oom victim's memcg to the 
oom context information" ?

>From add1e8daddbfc5186417dbc58e9e11e7614868f8 Mon Sep 17 00:00:00 2001
From: Tetsuo Handa 
Date: Wed, 19 Dec 2018 16:09:31 +0900
Subject: [PATCH] mm, oom: Use pr_cont() in mem_cgroup_print_oom_context().

One line summary of the OOM killer context is not one line due to
not using KERN_CONT.

[   23.346650] 
oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0
[   23.346691] ,global_oom,task_memcg=/,task=firewalld,pid=5096,uid=0

Signed-off-by: Tetsuo Handa 
---
 mm/memcontrol.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index b860dd4f7..4afd597 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1306,10 +1306,10 @@ void mem_cgroup_print_oom_context(struct mem_cgroup 
*memcg, struct task_struct *
rcu_read_lock();
 
if (memcg) {
-   pr_info(",oom_memcg=");
+   pr_cont(",oom_memcg=");
pr_cont_cgroup_path(memcg->css.cgroup);
} else
-   pr_info(",global_oom");
+   pr_cont(",global_oom");
if (p) {
pr_cont(",task_memcg=");
pr_cont_cgroup_path(task_cgroup(p, memory_cgrp_id));
-- 
1.8.3.1



[v3, PATCH 2/2] net-next: stmmac: dwmac-mediatek: remove fine-tune property

2018-12-18 Thread Biao Huang
1. remove fine-tune property and related setting to simplify
the timing adjustment flow.
2. set timing value according to the value from device tree,
and will not care whether PHY insert internal delay.

Signed-off-by: Biao Huang 
---
 .../net/ethernet/stmicro/stmmac/dwmac-mediatek.c   |   71 +++-
 1 file changed, 24 insertions(+), 47 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-mediatek.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac-mediatek.c
index e400cbd..bf25629 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-mediatek.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-mediatek.c
@@ -44,7 +44,6 @@ struct mac_delay_struct {
u32 rx_delay;
bool tx_inv;
bool rx_inv;
-   bool fine_tune;
 };
 
 struct mediatek_dwmac_plat_data {
@@ -105,16 +104,28 @@ static int mt2712_set_interface(struct 
mediatek_dwmac_plat_data *plat)
return 0;
 }
 
-static void mt2712_delay_ps2stage(struct mac_delay_struct *mac_delay)
+static void mt2712_delay_ps2stage(struct mediatek_dwmac_plat_data *plat)
 {
-   if (mac_delay->fine_tune) {
-   /* 170ps per stage for fine tune delay macro circuit*/
-   mac_delay->tx_delay /= 170;
-   mac_delay->rx_delay /= 170;
-   } else {
-   /* 550ps per stage for coarse tune delay macro circuit*/
+   struct mac_delay_struct *mac_delay = >mac_delay;
+
+   switch (plat->phy_mode) {
+   case PHY_INTERFACE_MODE_MII:
+   case PHY_INTERFACE_MODE_RMII:
+   /* 550ps per stage for MII/RMII */
mac_delay->tx_delay /= 550;
mac_delay->rx_delay /= 550;
+   break;
+   case PHY_INTERFACE_MODE_RGMII:
+   case PHY_INTERFACE_MODE_RGMII_TXID:
+   case PHY_INTERFACE_MODE_RGMII_RXID:
+   case PHY_INTERFACE_MODE_RGMII_ID:
+   /* 170ps per stage for RGMII */
+   mac_delay->tx_delay /= 170;
+   mac_delay->rx_delay /= 170;
+   break;
+   default:
+   dev_err(plat->dev, "phy interface not supported\n");
+   break;
}
 }
 
@@ -123,7 +134,7 @@ static int mt2712_set_delay(struct mediatek_dwmac_plat_data 
*plat)
struct mac_delay_struct *mac_delay = >mac_delay;
u32 delay_val = 0, fine_val = 0;
 
-   mt2712_delay_ps2stage(mac_delay);
+   mt2712_delay_ps2stage(plat);
 
switch (plat->phy_mode) {
case PHY_INTERFACE_MODE_MII:
@@ -167,13 +178,10 @@ static int mt2712_set_delay(struct 
mediatek_dwmac_plat_data *plat)
fine_val = ETH_RMII_DLY_TX_INV;
break;
case PHY_INTERFACE_MODE_RGMII:
-   /* the PHY is not responsible for inserting any internal
-* delay by itself in PHY_INTERFACE_MODE_RGMII case,
-* so Ethernet MAC will insert delays for both transmit
-* and receive path here.
-*/
-   if (mac_delay->fine_tune)
-   fine_val = ETH_FINE_DLY_GTXC | ETH_FINE_DLY_RXC;
+   case PHY_INTERFACE_MODE_RGMII_TXID:
+   case PHY_INTERFACE_MODE_RGMII_RXID:
+   case PHY_INTERFACE_MODE_RGMII_ID:
+   fine_val = ETH_FINE_DLY_GTXC | ETH_FINE_DLY_RXC;
 
delay_val |= FIELD_PREP(ETH_DLY_GTXC_ENABLE, 
!!mac_delay->tx_delay);
delay_val |= FIELD_PREP(ETH_DLY_GTXC_STAGES, 
mac_delay->tx_delay);
@@ -183,36 +191,6 @@ static int mt2712_set_delay(struct 
mediatek_dwmac_plat_data *plat)
delay_val |= FIELD_PREP(ETH_DLY_RXC_STAGES, 
mac_delay->rx_delay);
delay_val |= FIELD_PREP(ETH_DLY_RXC_INV, mac_delay->rx_inv);
break;
-   case PHY_INTERFACE_MODE_RGMII_TXID:
-   /* the PHY should insert an internal delay for the transmit
-* path in PHY_INTERFACE_MODE_RGMII_TXID case,
-* so Ethernet MAC will insert the delay for receive path here.
-*/
-   if (mac_delay->fine_tune)
-   fine_val = ETH_FINE_DLY_RXC;
-
-   delay_val |= FIELD_PREP(ETH_DLY_RXC_ENABLE, 
!!mac_delay->rx_delay);
-   delay_val |= FIELD_PREP(ETH_DLY_RXC_STAGES, 
mac_delay->rx_delay);
-   delay_val |= FIELD_PREP(ETH_DLY_RXC_INV, mac_delay->rx_inv);
-   break;
-   case PHY_INTERFACE_MODE_RGMII_RXID:
-   /* the PHY should insert an internal delay for the receive
-* path in PHY_INTERFACE_MODE_RGMII_RXID case,
-* so Ethernet MAC will insert the delay for transmit path here.
-*/
-   if (mac_delay->fine_tune)
-   fine_val = ETH_FINE_DLY_GTXC;
-
-   delay_val |= FIELD_PREP(ETH_DLY_GTXC_ENABLE, 
!!mac_delay->tx_delay);
-   delay_val |= FIELD_PREP(ETH_DLY_GTXC_STAGES, 
mac_delay->tx_delay);
-   delay_val |= FIELD_PREP(ETH_DLY_GTXC_INV, mac_delay->tx_inv);
- 

[v3, PATCH 1/2] net-next: dt-binding: dwmac-mediatek: remove fine-tune property

2018-12-18 Thread Biao Huang
remove fine-tune property in device tree, modify
the corresponding description in dt-binding.

Signed-off-by: Biao Huang 
---
 .../devicetree/bindings/net/mediatek-dwmac.txt |   31 +++-
 1 file changed, 11 insertions(+), 20 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/mediatek-dwmac.txt 
b/Documentation/devicetree/bindings/net/mediatek-dwmac.txt
index 4de479b..8a08621 100644
--- a/Documentation/devicetree/bindings/net/mediatek-dwmac.txt
+++ b/Documentation/devicetree/bindings/net/mediatek-dwmac.txt
@@ -22,33 +22,25 @@ Required properties:
 
 Optional properties:
 - mediatek,tx-delay-ps: TX clock delay macro value. Default is 0.
-   It should be defined for rgmii/rgmii-rxid/mii interface.
+   It should be defined for RGMII/MII interface.
 - mediatek,rx-delay-ps: RX clock delay macro value. Default is 0.
-   It should be defined for rgmii/rgmii-txid/mii/rmii interface.
-Both delay properties need to be a multiple of 170 for fine-tune rgmii,
-range 0~31*170.
-Both delay properties need to be a multiple of 550 for coarse-tune rgmii,
-range 0~31*550.
-Both delay properties need to be a multiple of 550 for mii/rmii,
-range 0~31*550.
+   It should be defined for RGMII/MII/RMII interface.
+Both delay properties need to be a multiple of 170 for RGMII interface,
+or will round down. Range 0~31*170.
+Both delay properties need to be a multiple of 550 for MII/RMII interface,
+or will round down. Range 0~31*550.
 
-- mediatek,fine-tune: boolean property, if present indicates that fine delay
-   is selected for rgmii interface.
-   If present, tx-delay-ps/rx-delay-ps is 170+/-50ps per stage.
-   Else tx-delay-ps/rx-delay-ps of coarse delay macro is 0.55+/-0.2ns per 
stage.
-   This property do not apply to non-rgmii PHYs.
-   Only coarse-tune delay is supported for mii/rmii PHYs.
-- mediatek,rmii-rxc: boolean property, if present indicates that the rmii
+- mediatek,rmii-rxc: boolean property, if present indicates that the RMII
reference clock, which is from external PHYs, is connected to RXC pin
on MT2712 SoC.
Otherwise, is connected to TXC pin.
 - mediatek,txc-inverse: boolean property, if present indicates that
-   1. tx clock will be inversed in mii/rgmii case,
+   1. tx clock will be inversed in MII/RGMII case,
2. tx clock inside MAC will be inversed relative to reference clock
-  which is from external PHYs in rmii case, and it rarely happen.
+  which is from external PHYs in RMII case, and it rarely happen.
 - mediatek,rxc-inverse: boolean property, if present indicates that
-   1. rx clock will be inversed in mii/rgmii case.
-   2. reference clock will be inversed when arrived at MAC in rmii case.
+   1. rx clock will be inversed in MII/RGMII case.
+   2. reference clock will be inversed when arrived at MAC in RMII case.
 - assigned-clocks: mac_main and ptp_ref clocks
 - assigned-clock-parents: parent clocks of the assigned clocks
 
@@ -76,7 +68,6 @@ Example:
mediatek,pericfg = <>;
mediatek,tx-delay-ps = <1530>;
mediatek,rx-delay-ps = <1530>;
-   mediatek,fine-tune;
mediatek,rmii-rxc;
mediatek,txc-inverse;
mediatek,rxc-inverse;
-- 
1.7.9.5



Re: [PATCH v2 01/12] fs-verity: add a documentation file

2018-12-18 Thread Christoph Hellwig
On Tue, Dec 18, 2018 at 11:16:08PM -0800, Linus Torvalds wrote:
> On Tue, Dec 18, 2018, 23:11 Christoph Hellwig  
> >
> > I think the fd would have to be on the same fs for this interface to
> > make sense. But it could be an O_TMPFILE one.  And given that ext4
> > already supports a variant of swapext this interface should also work
> > with the existing ext4 on disk format.
> >
> 
> Why is the merkle tree not just an xattr of the file?

Because it is too large for our awkward xattrs interface..


Re: [PATCH v2 01/12] fs-verity: add a documentation file

2018-12-18 Thread Christoph Hellwig
On Tue, Dec 18, 2018 at 07:16:03PM -0500, Theodore Y. Ts'o wrote:
> Sure, but what would be the benefit of doing different things on the
> back end?  I think this is a really more of a philophical objection
> than anything else.  With both fsverity and fscrypt, well over 95% of
> the implementation is shared between ext4 and f2fs.  And from a
> cryptographic design, that's something I consider a feature, not a
> bug.  Cryptographic code is subtle in very different ways compared to
> file system code.  So it's a good thing to having it done once and
> audited by crypto specialists, as opposed to having each file system
> doing it differently / independently.

Where the data is located on disk should not matter for the crypto
details.  If it does you have severe implementation issues.

> Right, the current interface makes it somewhat more awkward to do
> these other things --- but the question is *why* would you want to in
> the first place?  Why add the extra complexity?  I'm a big believer of
> the KISS principle, and if there was a reason why a file system would
> want to store the Merkle tree somewhere else, we could talk about it,
> but I see only downside, and no upside.

Filesystems already use blocks beyond EOF for preallocation, either
speculative by the file system itself, or explicitly by the user with
fallocate.  I bet you will run into bugs with your creative abuse
sooner or later.  Indepnd of that the interface simply is gross, which
is enough of a reason not to merge it.


RE: [PATCH V2] dt-bindings: timer: gpt: update binding doc

2018-12-18 Thread Anson Huang
Hi, Rob

Best Regards!
Anson Huang

> -Original Message-
> From: Rob Herring [mailto:r...@kernel.org]
> Sent: 2018年12月19日 1:12
> To: Anson Huang 
> Cc: daniel.lezc...@linaro.org; t...@linutronix.de; mark.rutl...@arm.com;
> linux-kernel@vger.kernel.org; devicet...@vger.kernel.org; dl-linux-imx
> 
> Subject: Re: [PATCH V2] dt-bindings: timer: gpt: update binding doc
> 
> On Wed, Dec 12, 2018 at 07:20:44AM +, Anson Huang wrote:
> > The i.MX GPT timer driver binding doc is out of date, update it
> > according to current GPT timer driver.
> >
> > Signed-off-by: Anson Huang 
> > ---
> >  .../devicetree/bindings/timer/fsl,imxgpt.txt   | 28
> +-
> >  1 file changed, 22 insertions(+), 6 deletions(-)
> >
> > diff --git a/Documentation/devicetree/bindings/timer/fsl,imxgpt.txt
> > b/Documentation/devicetree/bindings/timer/fsl,imxgpt.txt
> > index 9809b11..2ed84ad 100644
> > --- a/Documentation/devicetree/bindings/timer/fsl,imxgpt.txt
> > +++ b/Documentation/devicetree/bindings/timer/fsl,imxgpt.txt
> > @@ -2,17 +2,33 @@ Freescale i.MX General Purpose Timer (GPT)
> >
> >  Required properties:
> >
> > -- compatible : should be "fsl,-gpt"
> > -- reg : Specifies base physical address and size of the registers.
> > -- interrupts : A list of 4 interrupts; one per timer channel.
> > -- clocks : The clocks provided by the SoC to drive the timer.
> > +- compatible : must be one of following:
> > +  - "fsl,imx1-gpt",
> > +  - "fsl,imx21-gpt",
> > +  - "fsl,imx27-gpt",
> > +  - "fsl,imx31-gpt",
> > +  - "fsl,imx25-gpt",
> > +  - "fsl,imx50-gpt",
> > +  - "fsl,imx51-gpt",
> > +  - "fsl,imx53-gpt",
> > +  - "fsl,imx6q-gpt",
> > +  - "fsl,imx6dl-gpt",
> > +  - "fsl,imx6sl-gpt",
> > +  - "fsl,imx6sx-gpt".
> 
> You need to list fall-backs here. IOW, what are the valid combinations?

I listed the combinations in V3 patch;

> 
> > +- reg : specifies base physical address and size of the registers.
> > +- interrupts : should be the clock event device interrupt.
> 
> 'clock event' is a Linux thing and shouldn't be part of the binding.
> 
> What happened to the 4 interrupts?

Yes, using "gpt interrupt" is better than "clock event", and looks like the 
i.MX GPT
driver does NOT support 4 interrupts at all, ONLY 1 general GPT interrupt is 
needed,
so I updated it;

> 
> > +- clocks : the clocks provided by the SoC to drive the timer, must contain
> > +   an entry for each entry in clock-names.
> > +- clock-names : must include "ipg" entry first, then "per" entry, "osc_per"
> > +can be a substitute of "per" entry on some SoCs.
> 
> per or osc_per should be deprecated so only one is used going forward.

osc_per is just a special case for i.MX6Q, so I remove it, just mention the ipg 
and per clock.
Please help review V3, thanks.

Anson.

> 
> >
> >  Example:
> >
> >  gpt1: timer@10003000 {
> > -   compatible = "fsl,imx27-gpt", "fsl,imx1-gpt";
> > +   compatible = "fsl,imx27-gpt", "fsl,imx21-gpt";
> > reg = <0x10003000 0x1000>;
> > interrupts = <26>;
> > -   clocks = < 46>, < 61>;
> > +   clocks = < IMX27_CLK_GPT1_IPG_GATE>,
> > +< IMX27_CLK_PER1_GATE>;
> > clock-names = "ipg", "per";
> >  };
> > --
> > 2.7.4
> >


Re: [PATCH v2 01/12] fs-verity: add a documentation file

2018-12-18 Thread Christoph Hellwig
On Mon, Dec 17, 2018 at 12:00:39PM -0800, Darrick J. Wong wrote:
> FWIW, if I were (hypothetically) working on an xfs implementation, I
> likely would have settled on passing a reference to a merkle tree
> through a (fd, length) pair, because that allows us plenty of options
> on the back end:
> 
> b) we could remap the tree into a new inode fork for merkle trees, or
> a) remap it as posteof blocks like ext4/f2fs does, or
> c) remap the blocks into the attribute fork as an (unusually large)
> extended attribute value.
>
> If the merkle_fd isn't on the same filesystem as the fd we could at
> least use generic_copy_file_range (i.e. page cache copying) to land the
> merkle tree wherever we want.

I think the fd would have to be on the same fs for this interface to
make sense. But it could be an O_TMPFILE one.  And given that ext4
already supports a variant of swapext this interface should also work
with the existing ext4 on disk format.


Re: [PATCH] fs: fix possible Spectre V1 indexing in __close_fd()

2018-12-18 Thread Greg KH
On Mon, Oct 15, 2018 at 06:54:31AM -0700, Omer Tripp wrote:
> Hi Greg and all,
> 
> Here is my analysis of the complete gadget, and looking forward to your
> corrections/feedback if there are any inaccuracies:
> 
> 
>1.
> 
>__close_fd() is reachable via the close() syscall with a user-controlled
>fd.
>2.
> 
>If said bounds check is mispredicted, then a user-controlled address
>fdt->fd[fd] is obtained then dereferenced, and the value of a
>user-controlled address is loaded into the local variable file.
>3.
> 
>file is then passed as an argument to filp_close, where the cache
> lines secret
>+ offsetof(f_op) and secret + offsetof(f_mode) are hot and vulnerable to
>a timing channel attack.
> 
> 
> The mitigation proposed by Greg Hackmann blocks this gadget.

What ever happened to this patch?  Did it get reposted?  If not, can
someone please do so with this text in the changelog?

thanks,

greg k-h


[PATCH v4] powerpc: implement CONFIG_DEBUG_VIRTUAL

2018-12-18 Thread Christophe Leroy
This patch implements CONFIG_DEBUG_VIRTUAL to warn about
incorrect use of virt_to_phys() and page_to_phys()

Below is the result of test_debug_virtual:

[1.438746] WARNING: CPU: 0 PID: 1 at ./arch/powerpc/include/asm/io.h:808 
test_debug_virtual_init+0x3c/0xd4
[1.448156] CPU: 0 PID: 1 Comm: swapper Not tainted 
4.20.0-rc5-00560-g6bfb52e23a00-dirty #532
[1.457259] NIP:  c066c550 LR: c0650ccc CTR: c066c514
[1.462257] REGS: c900bdb0 TRAP: 0700   Not tainted  
(4.20.0-rc5-00560-g6bfb52e23a00-dirty)
[1.471184] MSR:  00029032   CR: 48000422  XER: 2000
[1.477811]
[1.477811] GPR00: c0650ccc c900be60 c60d  006000c0 c900 
9032 c7fa0020
[1.477811] GPR08: 2400 0001 0900  c07b5d04  
c00037d8 
[1.477811] GPR16:     c076 c074 
0092 c0685bb0
[1.477811] GPR24: c065042c c068a734 c0685b8c 0006  c076 
c075c3c0 
[1.512711] NIP [c066c550] test_debug_virtual_init+0x3c/0xd4
[1.518315] LR [c0650ccc] do_one_initcall+0x8c/0x1cc
[1.523163] Call Trace:
[1.525595] [c900be60] [c0567340] 0xc0567340 (unreliable)
[1.530954] [c900be90] [c0650ccc] do_one_initcall+0x8c/0x1cc
[1.536551] [c900bef0] [c0651000] kernel_init_freeable+0x1f4/0x2cc
[1.542658] [c900bf30] [c00037ec] kernel_init+0x14/0x110
[1.547913] [c900bf40] [c000e1d0] ret_from_kernel_thread+0x14/0x1c
[1.553971] Instruction dump:
[1.556909] 3ca50100 bfa10024 54a5000e 3fa0c076 7c0802a6 3d454000 813dc204 
554893be
[1.564566] 7d294010 7d294910 90010034 39290001 <0f09> 7c3e0b78 955e0008 
3fe0c062
[1.572425] ---[ end trace 6f6984225b280ad6 ]---
[1.577467] PA: 0x0900 for VA: 0xc900
[1.581799] PA: 0x061e8f50 for VA: 0xc61e8f50

Signed-off-by: Christophe Leroy 
---
 v4: revised verification in __ioremap_caller(): we keep the verification
 based on virt_to_phys() but do it on (highmem - 1) instead of highmem
 because highmem is not a valid virtual address.

 v3: Added missing linux/mm.h
 I realised that a driver may use DMA on stack after checking with 
virt_addr_valid(), so the new
 verification might induce false positives. I remove it for now, will add 
it again later in a more
 controled way.

 v2: Using asm/pgtable.h to avoid build failure on ppc64e.
 Added a verification that the object is not in stack to catch problems 
before activing VMAP_STACK.

 arch/powerpc/Kconfig  |  1 +
 arch/powerpc/include/asm/io.h | 13 -
 arch/powerpc/mm/pgtable_32.c  |  2 +-
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index e312e92e3381..94b46624068d 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -128,6 +128,7 @@ config PPC
#
# Please keep this list sorted alphabetically.
#
+   select ARCH_HAS_DEBUG_VIRTUAL
select ARCH_HAS_DEVMEM_IS_ALLOWED
select ARCH_HAS_DMA_SET_COHERENT_MASK
select ARCH_HAS_ELF_RANDOMIZE
diff --git a/arch/powerpc/include/asm/io.h b/arch/powerpc/include/asm/io.h
index e746becd9d6f..7f19fbd3ba55 100644
--- a/arch/powerpc/include/asm/io.h
+++ b/arch/powerpc/include/asm/io.h
@@ -29,12 +29,14 @@ extern struct pci_dev *isa_bridge_pcidev;
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 
 #ifdef CONFIG_PPC64
 #include 
@@ -804,6 +806,8 @@ extern void __iounmap_at(void *ea, unsigned long size);
  */
 static inline unsigned long virt_to_phys(volatile void * address)
 {
+   WARN_ON(IS_ENABLED(CONFIG_DEBUG_VIRTUAL) && !virt_addr_valid(address));
+
return __pa((unsigned long)address);
 }
 
@@ -827,7 +831,14 @@ static inline void * phys_to_virt(unsigned long address)
 /*
  * Change "struct page" to physical address.
  */
-#define page_to_phys(page) ((phys_addr_t)page_to_pfn(page) << PAGE_SHIFT)
+static inline phys_addr_t page_to_phys(struct page *page)
+{
+   unsigned long pfn = page_to_pfn(page);
+
+   WARN_ON(IS_ENABLED(CONFIG_DEBUG_VIRTUAL) && !pfn_valid(pfn));
+
+   return PFN_PHYS(pfn);
+}
 
 /*
  * 32 bits still uses virt_to_bus() for it's implementation of DMA
diff --git a/arch/powerpc/mm/pgtable_32.c b/arch/powerpc/mm/pgtable_32.c
index 4fc77a99c9bf..d67215248d82 100644
--- a/arch/powerpc/mm/pgtable_32.c
+++ b/arch/powerpc/mm/pgtable_32.c
@@ -143,7 +143,7 @@ __ioremap_caller(phys_addr_t addr, unsigned long size, 
pgprot_t prot, void *call
 * Don't allow anybody to remap normal RAM that we're using.
 * mem_init() sets high_memory so only do the check after that.
 */
-   if (slab_is_available() && (p < virt_to_phys(high_memory)) &&
+   if (slab_is_available() && p <= virt_to_phys(high_memory - 1) &&
page_is_ram(__phys_to_pfn(p))) {
printk("__ioremap(): phys addr 0x%llx is RAM lr %ps\n",
   (unsigned long long)p, 

[PATCH V3] dt-bindings: timer: gpt: update binding doc

2018-12-18 Thread Anson Huang
The i.MX GPT timer driver binding doc is out of date,
update it according to current GPT timer driver.

Signed-off-by: Anson Huang 
---
 .../devicetree/bindings/timer/fsl,imxgpt.txt   | 35 ++
 1 file changed, 29 insertions(+), 6 deletions(-)

diff --git a/Documentation/devicetree/bindings/timer/fsl,imxgpt.txt 
b/Documentation/devicetree/bindings/timer/fsl,imxgpt.txt
index 9809b11..a7f23a6 100644
--- a/Documentation/devicetree/bindings/timer/fsl,imxgpt.txt
+++ b/Documentation/devicetree/bindings/timer/fsl,imxgpt.txt
@@ -2,17 +2,40 @@ Freescale i.MX General Purpose Timer (GPT)
 
 Required properties:
 
-- compatible : should be "fsl,-gpt"
-- reg : Specifies base physical address and size of the registers.
-- interrupts : A list of 4 interrupts; one per timer channel.
-- clocks : The clocks provided by the SoC to drive the timer.
+- compatible : should be one of following:
+
+  should be "fsl,imx1-gpt" for i.MX1;
+
+  should be one of following for i.MX21/i.MX27:
+  - "fsl,imx21-gpt",
+  - "fsl,imx27-gpt",
+
+  should be one of following for i.MX31/i.MX25/i.MX50/i.MX51/i.MX53/i.MX6Q:
+  - "fsl,imx31-gpt",
+  - "fsl,imx25-gpt",
+  - "fsl,imx50-gpt",
+  - "fsl,imx51-gpt",
+  - "fsl,imx53-gpt",
+  - "fsl,imx6q-gpt",
+
+  should be one of following for i.MX6DL/i.MX6SL/i.MX6SX:
+  - "fsl,imx6dl-gpt",
+  - "fsl,imx6sl-gpt",
+  - "fsl,imx6sx-gpt".
+
+- reg : specifies base physical address and size of the registers.
+- interrupts : should be the gpt interrupt.
+- clocks : the clocks provided by the SoC to drive the timer, must contain
+   an entry for each entry in clock-names.
+- clock-names : must include "ipg" entry first, then "per" entry.
 
 Example:
 
 gpt1: timer@10003000 {
-   compatible = "fsl,imx27-gpt", "fsl,imx1-gpt";
+   compatible = "fsl,imx27-gpt", "fsl,imx21-gpt";
reg = <0x10003000 0x1000>;
interrupts = <26>;
-   clocks = < 46>, < 61>;
+   clocks = < IMX27_CLK_GPT1_IPG_GATE>,
+< IMX27_CLK_PER1_GATE>;
clock-names = "ipg", "per";
 };
-- 
2.7.4



Re: [PATCH v2 01/12] fs-verity: add a documentation file

2018-12-18 Thread Christoph Hellwig
On Mon, Dec 17, 2018 at 10:32:06AM -0800, Eric Biggers wrote:
> I don't see how that helps.  The Merkle tree can still be too large to fit in
> memory.  In the worst case, it might not even fit in the address space.  And I
> don't see how get_user_pages() helps either over just copy_from_user(); what 
> are
> you proposing to do with the pages after getting them, exactly?

Write them out to a file system specific area on the media.  Note
that get_user_pages is indeed not going to work if you run out of
address space, but that seems like an odd use case.  Out of of memory
is not an issue as we generally iterate over a small number of pages
for each individual get_user_pages call.


Re: [PATCH 2/3] ARM: dts: sun8i: add FriendlyARM NanoPi Duo2

2018-12-18 Thread Maxime Ripard
Hi,

On Tue, Dec 18, 2018 at 09:24:56PM +, Karl Palsson wrote:
> This is an Allwinner H3 based board, with 512MB ram, a USB OTG port,
> microsd slot, an onboard AP6212A wifi/bluetooth module, and a CSI
> connector.
> 
> Full details and schematic available from vendor:
> http://wiki.friendlyarm.com/wiki/index.php/NanoPi_Duo2
> 
> Signed-off-by: Karl Palsson 
> ---
>  arch/arm/boot/dts/Makefile |   1 +
>  arch/arm/boot/dts/sun8i-h3-nanopi-duo2.dts | 148 
> +
>  2 files changed, 149 insertions(+)
>  create mode 100644 arch/arm/boot/dts/sun8i-h3-nanopi-duo2.dts
> 
> diff --git a/arch/arm/boot/dts/Makefile b/arch/arm/boot/dts/Makefile
> index 78551c4375d5..7f296bfea94a 100644
> --- a/arch/arm/boot/dts/Makefile
> +++ b/arch/arm/boot/dts/Makefile
> @@ -1063,6 +1063,7 @@ dtb-$(CONFIG_MACH_SUN8I) += \
>   sun8i-h3-beelink-x2.dtb \
>   sun8i-h3-libretech-all-h3-cc.dtb \
>   sun8i-h3-mapleboard-mp130.dtb \
> + sun8i-h3-nanopi-duo2.dtb \
>   sun8i-h3-nanopi-m1.dtb  \
>   sun8i-h3-nanopi-m1-plus.dtb \
>   sun8i-h3-nanopi-neo.dtb \
> diff --git a/arch/arm/boot/dts/sun8i-h3-nanopi-duo2.dts 
> b/arch/arm/boot/dts/sun8i-h3-nanopi-duo2.dts
> new file mode 100644
> index ..07d2f1bebd56
> --- /dev/null
> +++ b/arch/arm/boot/dts/sun8i-h3-nanopi-duo2.dts
> @@ -0,0 +1,148 @@
> +// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
> +/*
> + * Copyright (C) 2018 Karl Palsson 
> + */
> +
> +/dts-v1/;
> +#include "sun8i-h3.dtsi"
> +#include "sunxi-common-regulators.dtsi"
> +
> +#include 
> +#include 
> +
> +/ {
> + model = "FriendlyARM NanoPi Duo2";
> + compatible = "friendlyarm,nanopi-duo2", "allwinner,sun8i-h3";
> +
> + aliases {
> + serial0 = 
> + };
> +
> + chosen {
> + stdout-path = "serial0:115200n8";
> + };
> +
> + leds {
> + compatible = "gpio-leds";
> +
> + status {
> + label = "nanopi:green:status";
> + gpios = < 0 10 GPIO_ACTIVE_HIGH>;
> + linux,default-trigger = "heartbeat";
> + };
> +
> + pwr {
> + label = "nanopi:red:pwr";
> + gpios = <_pio 0 10 GPIO_ACTIVE_HIGH>;
> + default-state = "on";
> + };
> + };
> +
> + r_gpio_keys {
> + compatible = "gpio-keys";
> + pinctrl-names = "default";
> + pinctrl-0 = <_r_npi>;
> +
> + k1 {
> + label = "k1";
> + linux,code = ;
> + gpios = <_pio 0 3 GPIO_ACTIVE_LOW>;
> + };
> + };
> +
> + reg_vdd_cpux: vdd-cpux-regulator {
> + compatible = "regulator-gpio";
> + regulator-name = "vdd-cpux";
> + regulator-boot-on;
> + regulator-always-on;
> + regulator-min-microvolt = <110>;
> + regulator-max-microvolt = <130>;
> + regulator-ramp-delay = <50>; /* 4ms */
> +
> + gpios = <_pio 0 6 GPIO_ACTIVE_HIGH>; /* PL6 */
> + enable-active-high;
> + gpios-states = <0x1>;
> + states = <110 0x0
> +   130 0x1>;
> + };
> +
> + wifi_pwrseq: wifi_pwrseq {
> + compatible = "mmc-pwrseq-simple";
> + reset-gpios = <_pio 0 7 GPIO_ACTIVE_LOW>; /* PL7 */
> + };
> +
> +};
> +
> + {
> + cpu-supply = <_vdd_cpux>;
> +};
> +
> +_otg {
> + status = "okay";
> + dr_mode = "otg";
> +};
> +
> + {
> + status = "okay";
> +};
> +
> + {
> + status = "okay";
> +};
> +
> +_usb0_vbus {
> + gpio = <_pio 0 2 GPIO_ACTIVE_HIGH>; /* PL2 */
> + status = "okay";
> +};
> +
> +_pio {
> + sw_r_npi: key_pins {
> + pins = "PL3";
> + function = "gpio_in";
> + };
> +};

This node isn't needed you can just remove it

> + {
> + usb0_id_det-gpios = < 6 12 GPIO_ACTIVE_HIGH>; /* PG12 */
> + usb0_vbus-supply = <_usb0_vbus>;
> + status = "okay";
> +};
> +
> + {
> + bus-width = <4>;
> + cd-gpios = < 5 6 GPIO_ACTIVE_LOW>;
> + status = "okay";
> + vmmc-supply = <_vcc3v3>;
> +};
> +
> + {
> + vmmc-supply = <_vcc3v3>;
> + vqmmc-supply = <_vcc3v3>;
> + mmc-pwrseq = <_pwrseq>;
> + bus-width = <4>;
> + non-removable;
> + status = "okay";
> +
> + sdio_wifi: sdio_wifi@1 {
> + reg = <1>;
> + compatible = "brcm,bcm4329-fmac";
> + interrupt-parent = <>;
> + interrupts = <6 10 IRQ_TYPE_LEVEL_LOW>; /* PG10 / EINT10 */
> + interrupt-names = "host-wake";
> + };
> +};
> +
> + {
> + pinctrl-names = "default";
> + pinctrl-0 = <_pins_a>;
> + status = "okay";
> +};
> +
> + {
> + pinctrl-names = "default";
> + pinctrl-0 = <_pins>, <_rts_cts_pins>;
> + uart-has-rtscts;
> + status = "okay";
> +
> + /* bluetooth goes here */

The 

[PATCH v4.19 1/1]: nvmem: imx-ocotp: account for addressing gaps to ensure consistent read/write on i.MX SoCs

2018-12-18 Thread Andrea Barisani


The nvmem-imx-ocotp driver does not currently handle addressing gaps between
OTP banks which can be present in i.MX System-on-Chip part numbers.

This leads to inconsistencies between the interpretation of the offset
argument in read and write operations, not only requiring specific
workarounds but also resulting in the impossibility of reading the entire OTP
bank.

Additionally this inconsistency violates the NVMEM subsystem principle of
exposing a userspace binary interface for read/write operations against a
pseudo-file.

This patch accounts for addressing gaps, depending on the specific i.MX model
being addressed.

Signed-off-by: Andrea Barisani 

---
 drivers/nvmem/imx-ocotp.c |   49 ++--
 1 file changed, 41 insertions(+), 8 deletions(-)

diff -up linux-4.19.9/drivers/nvmem/imx-ocotp.c.orig 
linux-4.19.9/drivers/nvmem/imx-ocotp.c
--- linux-4.19.9/drivers/nvmem/imx-ocotp.c.orig 2018-12-18 10:33:26.665742455 
+0100
+++ linux-4.19.9/drivers/nvmem/imx-ocotp.c  2018-12-18 10:33:32.569830061 
+0100
@@ -125,6 +125,8 @@ static int imx_ocotp_read(void *context,
 {
struct ocotp_priv *priv = context;
unsigned int count;
+   unsigned int base_offset;
+   const char *compat;
u32 *buf = val;
int i, ret;
u32 index;
@@ -150,11 +152,42 @@ static int imx_ocotp_read(void *context,
goto read_end;
}
 
+   compat = of_get_property(priv->dev->of_node, "compatible", NULL);
+
for (i = index; i < (index + count); i++) {
-   *buf++ = readl(priv->base + IMX_OCOTP_OFFSET_B0W0 +
-  i * IMX_OCOTP_OFFSET_PER_WORD);
+   /*
+* On specific i.MX P/Ns there are addressing gaps between
+* contiguous OTP banks which must be accounted for when
+* reading OTP banks from mapped memory.
+*
+* This is necessary to make the imx_ocotp_read() offset
+* interpretation consistent with imx_ocotp_write(), which
+* does not require to account for gaps as it uses the offset
+* value to derive the bank index and pass it directly to the
+* OCOTP controller (rather than being used for mapped memory
+* addressing).
+*/
+   base_offset = IMX_OCOTP_OFFSET_B0W0 + i * 
IMX_OCOTP_OFFSET_PER_WORD;
+
+   if (strcmp(compat, "fsl,imx6sx-ocotp")) {
+   /* 44.5.43 [IMX6SXRM]
+* 256 bytes gap between Bank5 Word7 (21B_C6F0h, offset 
0x6f0) and
+* Bank10 Word1 (21B_CA10h, offset 0xa10)
+*/
+   if (base_offset > 0x6f0)
+   base_offset += 0x100;
+   } else if (strcmp(compat, "fsl,imx6ul-ocotp")) {
+   /* 35.5.59 [IMX6ULRM]
+* 256 bytes gap between Bank5 Word7 (21B_C6F0h, offset 
0x6f0) and
+* Bank6 Word0 (21B_C800h, offset 0x800)
+*/
+   if (base_offset > 0x6f0)
+   base_offset += 0x100;
+   }
+
+   *buf++ = readl(priv->base + base_offset);
 
-   /* 47.3.1.2
+   /* 47.3.1.2 [IMX6SDLRM]
 * For "read locked" registers 0xBADABADA will be returned and
 * HW_OCOTP_CTRL[ERROR] will be set. It must be cleared by
 * software before any new write, read or reload access can be
@@ -177,7 +210,7 @@ static void imx_ocotp_set_imx6_timing(st
unsigned long strobe_read, relax, strobe_prog;
u32 timing = 0;
 
-   /* 47.3.1.3.1
+   /* 47.3.1.3.1 [IMX6SDLRM]
 * Program HW_OCOTP_TIMING[STROBE_PROG] and HW_OCOTP_TIMING[RELAX]
 * fields with timing values to match the current frequency of the
 * ipg_clk. OTP writes will work at maximum bus frequencies as long
@@ -245,7 +278,7 @@ static int imx_ocotp_write(void *context
/* Setup the write timing values */
priv->params->set_timing(priv);
 
-   /* 47.3.1.3.2
+   /* 47.3.1.3.2 [IMX6SDLRM]
 * Check that HW_OCOTP_CTRL[BUSY] and HW_OCOTP_CTRL[ERROR] are clear.
 * Overlapped accesses are not supported by the controller. Any pending
 * write or reload must be completed before a write access can be
@@ -257,7 +290,7 @@ static int imx_ocotp_write(void *context
goto write_end;
}
 
-   /* 47.3.1.3.3
+   /* 47.3.1.3.3 [IMX6SDLRM]
 * Write the requested address to HW_OCOTP_CTRL[ADDR] and program the
 * unlock code into HW_OCOTP_CTRL[WR_UNLOCK]. This must be programmed
 * for each write access. The lock code is documented in the register
@@ -289,7 +322,7 @@ static int imx_ocotp_write(void *context
 
writel(ctrl, priv->base + IMX_OCOTP_ADDR_CTRL);
 
-   

Re: [PATCH v2 2/7] dt-bindings: remoteproc: qcom: Add clock bindings for Q6V5

2018-12-18 Thread Sibi Sankar

Hi Rob,
Thanks for the review!

On 2018-12-18 22:57, Rob Herring wrote:

On Mon, Dec 17, 2018 at 03:37:19PM +0530, Sibi Sankar wrote:

Add missing clock bindings for Q6V5 MSS on SDM845 SoCs.

Signed-off-by: Sibi Sankar 
---
 .../devicetree/bindings/remoteproc/qcom,q6v5.txt   | 10 
+++---

 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git 
a/Documentation/devicetree/bindings/remoteproc/qcom,q6v5.txt 
b/Documentation/devicetree/bindings/remoteproc/qcom,q6v5.txt

index 9ff5b0309417..780adc043b37 100644
--- a/Documentation/devicetree/bindings/remoteproc/qcom,q6v5.txt
+++ b/Documentation/devicetree/bindings/remoteproc/qcom,q6v5.txt
@@ -39,13 +39,17 @@ on the Qualcomm Hexagon core.
 - clocks:
Usage: required
Value type: 
-   Definition: reference to the iface, bus and mem clocks to be held on
-   behalf of the booting of the Hexagon core
+	Definition: reference to the list of 4 clocks for the modem 
sub-system

+   reference to the list of 8 clocks for the modem sub-system
+   on SDM845 SoCs

 - clock-names:
Usage: required
Value type: 
-   Definition: must be "iface", "bus", "mem"
+	Definition: must be "iface", "bus", "mem", "xo" for the modem 
sub-system

+   must be "iface", "bus", "mem", "gpll0_mss", "snoc_axi",
+   "mnoc_axi", "prng", "xo" for the modem sub-system on SDM845
+   SoCs


This seems to me a list of all clocks you need enabled, not what clocks
actually go to the modem. Specifically, shouldn't the *noc_axi clocks 
be

managed by the interconnect driver?


clocks = ...,
   < GCC_MSS_SNOC_AXI_CLK>,
   < GCC_MSS_MFAB_AXIS_CLK>,
 ...;
clock-names = ..., "snoc_axi", "mnoc_axi",...;

snoc_axi and mnoc_axi maps to above GCC clks and
both of them fall under the MSS functional group



Rob


--
-- Sibi Sankar --
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project.


Re: [PATCH v3] powerpc: implement CONFIG_DEBUG_VIRTUAL

2018-12-18 Thread Christophe Leroy




On 12/19/2018 06:57 AM, Christophe Leroy wrote:



Le 19/12/2018 à 01:26, Michael Ellerman a écrit :

Michael Ellerman  writes:

Christophe Leroy  writes:


This patch implements CONFIG_DEBUG_VIRTUAL to warn about
incorrect use of virt_to_phys() and page_to_phys()


This commit is breaking my p5020ds booting a 32-bit kernel with:

   smp: Bringing up secondary CPUs ...
   __ioremap(): phys addr 0x7fef5000 is RAM lr ioremap_coherent
   Unable to handle kernel paging request for data at address 0x
   Faulting instruction address: 0xc002e950
   Oops: Kernel access of bad area, sig: 11 [#1]
   BE SMP NR_CPUS=24 CoreNet Generic
   Modules linked in:
   CPU: 0 PID: 1 Comm: swapper/0 Not tainted 
4.20.0-rc2-gcc-7.0.1-00138-g9a0380d299e9 #148

   NIP:  c002e950 LR: c002eb20 CTR: 0001
   REGS: e804bd20 TRAP: 0300   Not tainted  
(4.20.0-rc2-gcc-7.0.1-00138-g9a0380d299e9)

   MSR:  00021002   CR: 28004222  XER: 
   DEAR:  ESR: 
   GPR00: c002eb20 e804bdd0 e805  00021002  
0050 00021002
   GPR08: 2d3f 0001  0004 24000842  
c00026d0 
   GPR16:       
 0001
   GPR24: 00029002 7fef5140 3000   0040 
0001 

   NIP [c002e950] smp_85xx_kick_cpu+0x120/0x410
   LR [c002eb20] smp_85xx_kick_cpu+0x2f0/0x410
   Call Trace:
   [e804bdd0] [c002eb20] smp_85xx_kick_cpu+0x2f0/0x410 (unreliable)
   [e804be20] [c0012e38] __cpu_up+0xc8/0x230
   [e804be50] [c0040b34] bringup_cpu+0x34/0x110
   [e804be70] [c00418a8] cpu_up+0x128/0x250
   [e804beb0] [c0b84b14] smp_init+0xc4/0x10c
   [e804bee0] [c0b75c1c] kernel_init_freeable+0xc8/0x250
   [e804bf20] [c00026e8] kernel_init+0x18/0x120
   [e804bf40] [c0011298] ret_from_kernel_thread+0x14/0x1c
   Instruction dump:
   7fb3e850 57bdd1be 2e1d 41d20250 57bd3032 393dffc0 7e6a9b78 
5529d1be
   39290001 7d2903a6 6000 6000 <7c0050ac> 394a0040 4200fff8 
7c0004ac

   ---[ end trace edcab2a1dfd5b38c ]---


Which is obviously this hunk:

diff --git a/arch/powerpc/mm/pgtable_32.c 
b/arch/powerpc/mm/pgtable_32.c

index 4fc77a99c9bf..68d204a45cd0 100644
--- a/arch/powerpc/mm/pgtable_32.c
+++ b/arch/powerpc/mm/pgtable_32.c
@@ -143,7 +143,7 @@ __ioremap_caller(phys_addr_t addr, unsigned long 
size, pgprot_t prot, void *call

   * Don't allow anybody to remap normal RAM that we're using.
   * mem_init() sets high_memory so only do the check after that.
   */
-    if (slab_is_available() && (p < virt_to_phys(high_memory)) &&
+    if (slab_is_available() && virt_addr_valid(p) &&
  page_is_ram(__phys_to_pfn(p))) {
  printk("__ioremap(): phys addr 0x%llx is RAM lr %ps\n",
 (unsigned long long)p, __builtin_return_address(0));



I'll try and come up with a fix tomorrow.


Actually I think that change is just wrong. virt_addr_valid() takes a
virtual address, but p is a physical address.

So I'll drop this hunk for now, which makes the patch a no-op when
DEBUG_VIRTUAL is n which is probably the way it should be.


The hunk is obviously wrong for sure. Anyway there's a problem, most 
likely high_memory is not a valid virtual address, so without this hunk 
I get the following warning at every ioremap():


[    0.00] WARNING: CPU: 0 PID: 0 at 
./arch/powerpc/include/asm/io.h:809 __ioremap_caller+0x9c/0x180
[    0.00] CPU: 0 PID: 0 Comm: swapper Not tainted 
4.20.0-rc6-s3k-dev-00677-g9c98dcab6203-dirty #615

[    0.00] NIP:  c000fcd0 LR: c000fc64 CTR: 
[    0.00] REGS: c073de50 TRAP: 0700   Not tainted 
(4.20.0-rc6-s3k-dev-00677-g9c98dcab6203-dirty)

[    0.00] MSR:  00021032   CR: 28944422  XER: f940
[    0.00]
[    0.00] GPR00: c000fe04 c073df00 c06e1450 0001 4023 
c073df38 c0018f50 0001
[    0.00] GPR08: 2000 0800 2000  88944224 
0060  07ff9580
[    0.00] GPR16:  07ffb94c    
  
[    0.00] GPR24:  c076 019f ff00 ff00 
c000fe04 4000 c0018f50

[    0.00] NIP [c000fcd0] __ioremap_caller+0x9c/0x180
[    0.00] LR [c000fc64] __ioremap_caller+0x30/0x180
[    0.00] Call Trace:
[    0.00] [c073df00] [c02fc23c] of_address_to_resource+0x114/0x154 
(unreliable)

[    0.00] [c073df30] [c000fe04] ioremap_wt+0x20/0x30
[    0.00] [c073df40] [c0018f50] mpc8xx_pic_init+0x70/0xf8
[    0.00] [c073df80] [c0655b84] mpc8xx_pics_init+0x10/0x6c
[    0.00] [c073df90] [c0675080] cmpc885_pics_init+0x14/0x118
[    0.00] [c073dfa0] [c0652eb0] init_IRQ+0x24/0x38
[    0.00] [c073dfb0] [c0650b10] start_kernel+0x2a8/0x3d4
[    0.00] [c073dff0] [c0002258] start_here+0x44/0x98
[    0.00] Instruction dump:
[    0.00] 419e00b8 7f83e378 480013fd 7c7d1b79 41820030 576304be 
7c63ea14 80010034
[    0.00] bb410018 7c0803a6 38210030 4e800020 <0fe0> 7f9c4840 
409cffc4 48a8
[    

Re: [PATCH] sysfs: Disable lockdep for driver bind/unbind files

2018-12-18 Thread Greg Kroah-Hartman
On Tue, Dec 18, 2018 at 09:14:43PM +0100, Daniel Vetter wrote:
> This is the much more correct fix for my earlier attempt at:
> 
> https://lkml.org/lkml/2018/12/10/118
> 
> Short recap:
> 
> - There's not actually a locking issue, it's just lockdep being a bit
>   too eager to complain about a possible deadlock.
> 
> - Contrary to what I claimed the real problem is recursion on
>   kn->count. Greg pointed me at sysfs_break_active_protection(), used
>   by the scsi subsystem to allow a sysfs file to unbind itself. That
>   would be a real deadlock, which isn't what's happening here. Also,
>   breaking the active protection means we'd need to manually handle
>   all the lifetime fun.
> 
> - With Rafael we discussed the task_work approach, which kinda works,
>   but has two downsides: It's a functional change for a lockdep
>   annotation issue, and it won't work for the bind file (which needs
>   to get the errno from the driver load function back to userspace).
> 
> - Greg also asked why this never showed up: To hit this you need to
>   unregister a 2nd driver from the unload code of your first driver. I
>   guess only gpus do that. The bug has always been there, but only
>   with a recent patch series did we add more locks so that lockdep
>   built a chain from unbinding the snd-hda driver to the
>   acpi_video_unregister call.
> 
> Full lockdep splat:
> 
> [12301.898799] 
> [12301.898805] WARNING: possible recursive locking detected
> [12301.898811] 4.20.0-rc7+ #84 Not tainted
> [12301.898815] 
> [12301.898821] bash/5297 is trying to acquire lock:
> [12301.898826] f61c6093 (kn->count#39){}, at: 
> kernfs_remove_by_name_ns+0x3b/0x80
> [12301.898841] but task is already holding lock:
> [12301.898847] 5f634021 (kn->count#39){}, at: 
> kernfs_fop_write+0xdc/0x190
> [12301.898856] other info that might help us debug this:
> [12301.898862]  Possible unsafe locking scenario:
> [12301.898867]CPU0
> [12301.898870]
> [12301.898874]   lock(kn->count#39);
> [12301.898879]   lock(kn->count#39);
> [12301.898883] *** DEADLOCK ***
> [12301.898891]  May be due to missing lock nesting notation
> [12301.898899] 5 locks held by bash/5297:
> [12301.898903]  #0: cd800e54 (sb_writers#4){.+.+}, at: 
> vfs_write+0x17f/0x1b0
> [12301.898915]  #1: 0465e7c2 (>mutex){+.+.}, at: 
> kernfs_fop_write+0xd3/0x190
> [12301.898925]  #2: 5f634021 (kn->count#39){}, at: 
> kernfs_fop_write+0xdc/0x190
> [12301.898936]  #3: 414ef7ac (>mutex){}, at: 
> device_release_driver_internal+0x34/0x240
> [12301.898950]  #4: 3218fbdf (register_count_mutex){+.+.}, at: 
> acpi_video_unregister+0xe/0x40
> [12301.898960] stack backtrace:
> [12301.898968] CPU: 1 PID: 5297 Comm: bash Not tainted 4.20.0-rc7+ #84
> [12301.898974] Hardware name: Hewlett-Packard HP EliteBook 8460p/161C, BIOS 
> 68SCF Ver. F.01 03/11/2011
> [12301.898982] Call Trace:
> [12301.898989]  dump_stack+0x67/0x9b
> [12301.898997]  __lock_acquire+0x6ad/0x1410
> [12301.899003]  ? kernfs_remove_by_name_ns+0x3b/0x80
> [12301.899010]  ? find_held_lock+0x2d/0x90
> [12301.899017]  ? mutex_spin_on_owner+0xe4/0x150
> [12301.899023]  ? find_held_lock+0x2d/0x90
> [12301.899030]  ? lock_acquire+0x90/0x180
> [12301.899036]  lock_acquire+0x90/0x180
> [12301.899042]  ? kernfs_remove_by_name_ns+0x3b/0x80
> [12301.899049]  __kernfs_remove+0x296/0x310
> [12301.899055]  ? kernfs_remove_by_name_ns+0x3b/0x80
> [12301.899060]  ? kernfs_name_hash+0xd/0x80
> [12301.899066]  ? kernfs_find_ns+0x6c/0x100
> [12301.899073]  kernfs_remove_by_name_ns+0x3b/0x80
> [12301.899080]  bus_remove_driver+0x92/0xa0
> [12301.899085]  acpi_video_unregister+0x24/0x40
> [12301.899127]  i915_driver_unload+0x42/0x130 [i915]
> [12301.899160]  i915_pci_remove+0x19/0x30 [i915]
> [12301.899169]  pci_device_remove+0x36/0xb0
> [12301.899176]  device_release_driver_internal+0x185/0x240
> [12301.899183]  unbind_store+0xaf/0x180
> [12301.899189]  kernfs_fop_write+0x104/0x190
> [12301.899195]  __vfs_write+0x31/0x180
> [12301.899203]  ? rcu_read_lock_sched_held+0x6f/0x80
> [12301.899209]  ? rcu_sync_lockdep_assert+0x29/0x50
> [12301.899216]  ? __sb_start_write+0x13c/0x1a0
> [12301.899221]  ? vfs_write+0x17f/0x1b0
> [12301.899227]  vfs_write+0xb9/0x1b0
> [12301.899233]  ksys_write+0x50/0xc0
> [12301.899239]  do_syscall_64+0x4b/0x180
> [12301.899247]  entry_SYSCALL_64_after_hwframe+0x49/0xbe
> [12301.899253] RIP: 0033:0x7f452ac7f7a4
> [12301.899259] Code: 00 f7 d8 64 89 02 48 c7 c0 ff ff ff ff eb b7 0f 1f 80 00 
> 00 00 00 8b 05 aa f0 2c 00 48 63 ff 85 c0 75 13 b8 01 00 00 00 0f 05 <48> 3d 
> 00 f0 ff ff 77 54 f3 c3 66 90 55 53 48 89 d5 48 89 f3 48 83
> [12301.899273] RSP: 002b:7ffceafa6918 EFLAGS: 0246 ORIG_RAX: 
> 0001
> [12301.899282] RAX: ffda RBX: 000d RCX: 
> 7f452ac7f7a4
> [12301.899288] RDX: 000d RSI: 

Re: [PATCH v3] powerpc: implement CONFIG_DEBUG_VIRTUAL

2018-12-18 Thread Christophe Leroy




Le 19/12/2018 à 01:26, Michael Ellerman a écrit :

Michael Ellerman  writes:

Christophe Leroy  writes:


This patch implements CONFIG_DEBUG_VIRTUAL to warn about
incorrect use of virt_to_phys() and page_to_phys()


This commit is breaking my p5020ds booting a 32-bit kernel with:

   smp: Bringing up secondary CPUs ...
   __ioremap(): phys addr 0x7fef5000 is RAM lr ioremap_coherent
   Unable to handle kernel paging request for data at address 0x
   Faulting instruction address: 0xc002e950
   Oops: Kernel access of bad area, sig: 11 [#1]
   BE SMP NR_CPUS=24 CoreNet Generic
   Modules linked in:
   CPU: 0 PID: 1 Comm: swapper/0 Not tainted 
4.20.0-rc2-gcc-7.0.1-00138-g9a0380d299e9 #148
   NIP:  c002e950 LR: c002eb20 CTR: 0001
   REGS: e804bd20 TRAP: 0300   Not tainted  
(4.20.0-rc2-gcc-7.0.1-00138-g9a0380d299e9)
   MSR:  00021002   CR: 28004222  XER: 
   DEAR:  ESR: 
   GPR00: c002eb20 e804bdd0 e805  00021002  0050 
00021002
   GPR08: 2d3f 0001  0004 24000842  c00026d0 

   GPR16:        
0001
   GPR24: 00029002 7fef5140 3000   0040 0001 

   NIP [c002e950] smp_85xx_kick_cpu+0x120/0x410
   LR [c002eb20] smp_85xx_kick_cpu+0x2f0/0x410
   Call Trace:
   [e804bdd0] [c002eb20] smp_85xx_kick_cpu+0x2f0/0x410 (unreliable)
   [e804be20] [c0012e38] __cpu_up+0xc8/0x230
   [e804be50] [c0040b34] bringup_cpu+0x34/0x110
   [e804be70] [c00418a8] cpu_up+0x128/0x250
   [e804beb0] [c0b84b14] smp_init+0xc4/0x10c
   [e804bee0] [c0b75c1c] kernel_init_freeable+0xc8/0x250
   [e804bf20] [c00026e8] kernel_init+0x18/0x120
   [e804bf40] [c0011298] ret_from_kernel_thread+0x14/0x1c
   Instruction dump:
   7fb3e850 57bdd1be 2e1d 41d20250 57bd3032 393dffc0 7e6a9b78 5529d1be
   39290001 7d2903a6 6000 6000 <7c0050ac> 394a0040 4200fff8 7c0004ac
   ---[ end trace edcab2a1dfd5b38c ]---


Which is obviously this hunk:


diff --git a/arch/powerpc/mm/pgtable_32.c b/arch/powerpc/mm/pgtable_32.c
index 4fc77a99c9bf..68d204a45cd0 100644
--- a/arch/powerpc/mm/pgtable_32.c
+++ b/arch/powerpc/mm/pgtable_32.c
@@ -143,7 +143,7 @@ __ioremap_caller(phys_addr_t addr, unsigned long size, 
pgprot_t prot, void *call
 * Don't allow anybody to remap normal RAM that we're using.
 * mem_init() sets high_memory so only do the check after that.
 */
-   if (slab_is_available() && (p < virt_to_phys(high_memory)) &&
+   if (slab_is_available() && virt_addr_valid(p) &&
page_is_ram(__phys_to_pfn(p))) {
printk("__ioremap(): phys addr 0x%llx is RAM lr %ps\n",
   (unsigned long long)p, __builtin_return_address(0));



I'll try and come up with a fix tomorrow.


Actually I think that change is just wrong. virt_addr_valid() takes a
virtual address, but p is a physical address.

So I'll drop this hunk for now, which makes the patch a no-op when
DEBUG_VIRTUAL is n which is probably the way it should be.


The hunk is obviously wrong for sure. Anyway there's a problem, most 
likely high_memory is not a valid virtual address, so without this hunk 
I get the following warning at every ioremap():


[0.00] WARNING: CPU: 0 PID: 0 at 
./arch/powerpc/include/asm/io.h:809 __ioremap_caller+0x9c/0x180
[0.00] CPU: 0 PID: 0 Comm: swapper Not tainted 
4.20.0-rc6-s3k-dev-00677-g9c98dcab6203-dirty #615

[0.00] NIP:  c000fcd0 LR: c000fc64 CTR: 
[0.00] REGS: c073de50 TRAP: 0700   Not tainted 
(4.20.0-rc6-s3k-dev-00677-g9c98dcab6203-dirty)

[0.00] MSR:  00021032   CR: 28944422  XER: f940
[0.00]
[0.00] GPR00: c000fe04 c073df00 c06e1450 0001 4023 
c073df38 c0018f50 0001
[0.00] GPR08: 2000 0800 2000  88944224 
0060  07ff9580
[0.00] GPR16:  07ffb94c    
  
[0.00] GPR24:  c076 019f ff00 ff00 
c000fe04 4000 c0018f50

[0.00] NIP [c000fcd0] __ioremap_caller+0x9c/0x180
[0.00] LR [c000fc64] __ioremap_caller+0x30/0x180
[0.00] Call Trace:
[0.00] [c073df00] [c02fc23c] of_address_to_resource+0x114/0x154 
(unreliable)

[0.00] [c073df30] [c000fe04] ioremap_wt+0x20/0x30
[0.00] [c073df40] [c0018f50] mpc8xx_pic_init+0x70/0xf8
[0.00] [c073df80] [c0655b84] mpc8xx_pics_init+0x10/0x6c
[0.00] [c073df90] [c0675080] cmpc885_pics_init+0x14/0x118
[0.00] [c073dfa0] [c0652eb0] init_IRQ+0x24/0x38
[0.00] [c073dfb0] [c0650b10] start_kernel+0x2a8/0x3d4
[0.00] [c073dff0] [c0002258] start_here+0x44/0x98
[0.00] Instruction dump:
[0.00] 419e00b8 7f83e378 480013fd 7c7d1b79 41820030 576304be 
7c63ea14 80010034
[0.00] bb410018 7c0803a6 38210030 4e800020 <0fe0> 7f9c4840 
409cffc4 48a8
[0.00] random: 

Re: [PATCH V4 1/3] misc/pvpanic: return 0 for empty body registerfunction

2018-12-18 Thread Greg KH
On Wed, Dec 19, 2018 at 08:11:37AM +0800, peng.h...@zte.com.cn wrote:
> >On Tue, Dec 18, 2018 at 05:46:41PM +0800, Peng Hao wrote:
> >> Return 0 for empty body register function normally.
> >>
> >> Signed-off-by: Peng Hao 
> >> ---
> >> QEMU community requires additional PCI devices to simulate PVPANIC devices
> >> so that some architectures can not occupy precious less than 4G of memory
> >> space.
> >
> >What is this for below the --- line?
> >
> >And again, you did not specify what changed from the previous versions.
> >I can not take these unless you provide it.
> 
> The previous version of the code is basically unchanged, and the new patches 
> just 
> adds a PCI interface. Previous versions only support ACPI and FDT interfaces.
> The QEMU community requires a PCI interface so that some architectures do not 
> occupy
>  precious low 4G memory address.

No, you are changing things between each version, hopefully based on the
review comments.  And the testing that is being provided for you showing
you where your code breaks the build.

That goes in the "what changed" lines, as is documented in the kernel
documentation.  Please follow that when resubmitting if you wish for
your changes to be able to be accepted.

thanks,

greg k-h


Re: [PATCH v3] regmap: regmap-irq/gpio-max77620: add level-irq support

2018-12-18 Thread Matti Vaittinen
On Tue, Dec 18, 2018 at 11:36:22PM +0800, kbuild test robot wrote:
> Hi Matti,
> 
> Thank you for the patch! Yet something to improve:
> 
> [auto build test ERROR on regmap/for-next]
> [also build test ERROR on next-20181218]
> [cannot apply to v4.20-rc7]
> [if your patch is applied to the wrong git tree, please drop us a note to 
> help improve the system]
> 
> url:
> https://github.com/0day-ci/linux/commits/Matti-Vaittinen/regmap-regmap-irq-gpio-max77620-add-level-irq-support/20181218-225844
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git 
> for-next
> config: x86_64-randconfig-x006-201850 (attached as .config)
> compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
> reproduce:
> # save the attached .config to linux build tree
> make ARCH=x86_64 
> 
> All errors (new ones prefixed by >>):
> 
>drivers/base/regmap/regmap-irq.c: In function 'regmap_add_irq_chip':
> >> drivers/base/regmap/regmap-irq.c:644:24: error: 'const struct regmap_irq' 
> >> has no member named 'type_reg_offset'; did you mean 'reg_offset'?
>reg = chip->irqs[i].type_reg_offset / map->reg_stride;
>^~~
>reg_offset
> >> drivers/base/regmap/regmap-irq.c:645:41: error: 'const struct regmap_irq' 
> >> has no member named 'type_rising_mask'
>d->type_buf_def[reg] |= chip->irqs[i].type_rising_mask |
> ^
> >> drivers/base/regmap/regmap-irq.c:646:19: error: 'const struct regmap_irq' 
> >> has no member named 'type_falling_mask'
>  chip->irqs[i].type_falling_mask;
---

> > Version 3 of this patch is intended to be functionally identical to v2.
> > This patch is rebased on top of a tree which contains changes:
> > "regmap: irq: handle HW using separate rising/falling edge interrupts"
> > from Bartosz Golaszewski and the change
> > "regmap: regmap-irq: Remove default irq type setting from core"
> > (proposed here):
> > https://lore.kernel.org/lkml/20181218105813.GA6957@localhost.localdomain/
> > 
> > There should not be direct dependency to "regmap: regmap-irq: Remove
> > default irq type setting from core" though. Patch was also tested to
> > apply cleany on regmap-tree.

I forgot that the block of code the commit "regmap: regmap-irq: Remove
default irq type setting from core" removes do use the old type specifiers
whcih this patch changes. So even though this patch applies cleanly on tree
which does not include "regmap: regmap-irq: Remove default irq type setting
from core" - it does not mean there is no dependency. This was my brain fart.
There is dependency. "regmap: regmap-irq: Remove default irq type setting
from core" should be applied prior this patch.

Should I combine these two patches as a series (and resend them) or what is
the correct way to note the dependency?

Br,
Matti Vaittinen



[PATCH net-next] xfrm6_tunnel: Fix spi check in __xfrm6_tunnel_alloc_spi

2018-12-18 Thread YueHaibing
gcc warn this:

net/ipv6/xfrm6_tunnel.c:143 __xfrm6_tunnel_alloc_spi() warn:
 always true condition '(spi <= 4294967295) => (0-u32max <= u32max)'

'spi' is u32, which always not greater than XFRM6_TUNNEL_SPI_MAX
because of wrap around. So the second forloop will never reach.

Signed-off-by: YueHaibing 
---
 net/ipv6/xfrm6_tunnel.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/ipv6/xfrm6_tunnel.c b/net/ipv6/xfrm6_tunnel.c
index 4a46df8..f5b4feb 100644
--- a/net/ipv6/xfrm6_tunnel.c
+++ b/net/ipv6/xfrm6_tunnel.c
@@ -144,6 +144,9 @@ static u32 __xfrm6_tunnel_alloc_spi(struct net *net, 
xfrm_address_t *saddr)
index = __xfrm6_tunnel_spi_check(net, spi);
if (index >= 0)
goto alloc_spi;
+
+   if (spi == XFRM6_TUNNEL_SPI_MAX)
+   break;
}
for (spi = XFRM6_TUNNEL_SPI_MIN; spi < xfrm6_tn->spi; spi++) {
index = __xfrm6_tunnel_spi_check(net, spi);
-- 
2.7.0




Re: [15/15] dma-mapping: bypass indirect calls for dma-direct

2018-12-18 Thread Christoph Hellwig
On Tue, Dec 18, 2018 at 08:42:46PM +, Robin Murphy wrote:
>> [   16.046084] rk_iommu ff8f3f00.iommu: DMA map error for DT
>
> Yup, with this patch as-is, anything which isn't behind an IOMMU will be 
> erroneously banned from DMA entirely - see here:
>
> https://lore.kernel.org/lkml/20181214142435.ga18...@lst.de/

FYI, I'm still waiting for a review on that..


Re: [PATCH v2 5/5] powerpc/perf: Trace imc PMU functions

2018-12-18 Thread Madhavan Srinivasan



On 14/12/18 2:41 PM, Anju T Sudhakar wrote:

Add PMU functions to support trace-imc.


Reviewed-by: Madhavan Srinivasan 



Signed-off-by: Anju T Sudhakar 
---
  arch/powerpc/perf/imc-pmu.c | 175 
  1 file changed, 175 insertions(+)

diff --git a/arch/powerpc/perf/imc-pmu.c b/arch/powerpc/perf/imc-pmu.c
index 1f09265c8fb0..32ff0e449fca 100644
--- a/arch/powerpc/perf/imc-pmu.c
+++ b/arch/powerpc/perf/imc-pmu.c
@@ -1120,6 +1120,173 @@ static int trace_imc_cpu_init(void)
  ppc_trace_imc_cpu_offline);
  }

+static u64 get_trace_imc_event_base_addr(void)
+{
+   return (u64)per_cpu(trace_imc_mem, smp_processor_id());
+}
+
+/*
+ * Function to parse trace-imc data obtained
+ * and to prepare the perf sample.
+ */
+static int trace_imc_prepare_sample(struct trace_imc_data *mem,
+   struct perf_sample_data *data,
+   u64 *prev_tb,
+   struct perf_event_header *header,
+   struct perf_event *event)
+{
+   /* Sanity checks for a valid record */
+   if (be64_to_cpu(READ_ONCE(mem->tb1)) > *prev_tb)
+   *prev_tb = be64_to_cpu(READ_ONCE(mem->tb1));
+   else
+   return -EINVAL;
+
+   if ((be64_to_cpu(READ_ONCE(mem->tb1)) & IMC_TRACE_RECORD_TB1_MASK) !=
+be64_to_cpu(READ_ONCE(mem->tb2)))
+   return -EINVAL;
+
+   /* Prepare perf sample */
+   data->ip =  be64_to_cpu(READ_ONCE(mem->ip));
+   data->period = event->hw.last_period;
+
+   header->type = PERF_RECORD_SAMPLE;
+   header->size = sizeof(*header) + event->header_size;
+   header->misc = 0;
+
+   if (is_kernel_addr(data->ip))
+   header->misc |= PERF_RECORD_MISC_KERNEL;
+   else
+   header->misc |= PERF_RECORD_MISC_USER;
+
+   perf_event_header__init_id(header, data, event);
+
+   return 0;
+}
+
+static void dump_trace_imc_data(struct perf_event *event)
+{
+   struct trace_imc_data *mem;
+   int i, ret;
+   u64 prev_tb = 0;
+
+   mem = (struct trace_imc_data *)get_trace_imc_event_base_addr();
+   for (i = 0; i < (trace_imc_mem_size / sizeof(struct trace_imc_data));
+   i++, mem++) {
+   struct perf_sample_data data;
+   struct perf_event_header header;
+
+   ret = trace_imc_prepare_sample(mem, , _tb, , 
event);
+   if (ret) /* Exit, if not a valid record */
+   break;
+   else {
+   /* If this is a valid record, create the sample */
+   struct perf_output_handle handle;
+
+   if (perf_output_begin(, event, header.size))
+   return;
+
+   perf_output_sample(, , , event);
+   perf_output_end();
+   }
+   }
+}
+
+static int trace_imc_event_add(struct perf_event *event, int flags)
+{
+   /* Enable the sched_task to start the engine */
+   perf_sched_cb_inc(event->ctx->pmu);
+   return 0;
+}
+
+static void trace_imc_event_read(struct perf_event *event)
+{
+   dump_trace_imc_data(event);
+}
+
+static void trace_imc_event_stop(struct perf_event *event, int flags)
+{
+   trace_imc_event_read(event);
+}
+
+static void trace_imc_event_start(struct perf_event *event, int flags)
+{
+   return;
+}
+
+static void trace_imc_event_del(struct perf_event *event, int flags)
+{
+   perf_sched_cb_dec(event->ctx->pmu);
+}
+
+void trace_imc_pmu_sched_task(struct perf_event_context *ctx,
+   bool sched_in)
+{
+   int core_id = smp_processor_id() / threads_per_core;
+   struct imc_pmu_ref *ref;
+   u64 local_mem, ldbar_value;
+
+   /* Set trace-imc bit in ldbar and load ldbar with per-thread memory 
address */
+   local_mem = get_trace_imc_event_base_addr();
+   ldbar_value = ((u64)local_mem & THREAD_IMC_LDBAR_MASK) | 
TRACE_IMC_ENABLE;
+
+   ref = _imc_refc[core_id];
+   if (!ref)
+   return;
+
+   if (sched_in) {
+   mtspr(SPRN_LDBAR, ldbar_value);
+   mutex_lock(>lock);
+   if (ref->refc == 0) {
+   if (opal_imc_counters_start(OPAL_IMC_COUNTERS_TRACE,
+   
get_hard_smp_processor_id(smp_processor_id( {
+   mutex_unlock(>lock);
+   pr_err("trace-imc: Unable to start the counters for 
core %d\n", core_id);
+   mtspr(SPRN_LDBAR, 0);
+   return;
+   }
+   }
+   ++ref->refc;
+   mutex_unlock(>lock);
+   } else {
+   mtspr(SPRN_LDBAR, 0);
+   mutex_lock(>lock);
+   ref->refc--;
+   if (ref->refc == 0) {
+ 

Re: [PATCH v2 4/5] powerpc/perf: Trace imc events detection and cpuhotplug

2018-12-18 Thread Madhavan Srinivasan



On 14/12/18 2:41 PM, Anju T Sudhakar wrote:

Patch detects trace-imc events, does memory initilizations for each online
cpu, and registers cpuhotplug call-backs.


Reviewed-by: Madhavan Srinivasan 


Signed-off-by: Anju T Sudhakar 
---
  arch/powerpc/perf/imc-pmu.c   | 91 +++
  arch/powerpc/platforms/powernv/opal-imc.c |  3 +
  include/linux/cpuhotplug.h|  1 +
  3 files changed, 95 insertions(+)

diff --git a/arch/powerpc/perf/imc-pmu.c b/arch/powerpc/perf/imc-pmu.c
index 5ca80545a849..1f09265c8fb0 100644
--- a/arch/powerpc/perf/imc-pmu.c
+++ b/arch/powerpc/perf/imc-pmu.c
@@ -43,6 +43,10 @@ static DEFINE_PER_CPU(u64 *, thread_imc_mem);
  static struct imc_pmu *thread_imc_pmu;
  static int thread_imc_mem_size;

+/* Trace IMC data structures */
+static DEFINE_PER_CPU(u64 *, trace_imc_mem);
+static int trace_imc_mem_size;
+
  static struct imc_pmu *imc_event_to_pmu(struct perf_event *event)
  {
return container_of(event->pmu, struct imc_pmu, pmu);
@@ -1068,6 +1072,54 @@ static void thread_imc_event_del(struct perf_event 
*event, int flags)
imc_event_update(event);
  }

+/*
+ * Allocate a page of memory for each cpu, and load LDBAR with 0.
+ */
+static int trace_imc_mem_alloc(int cpu_id, int size)
+{
+   u64 *local_mem = per_cpu(trace_imc_mem, cpu_id);
+   int phys_id = cpu_to_node(cpu_id), rc = 0;
+
+   if (!local_mem) {
+   local_mem = page_address(alloc_pages_node(phys_id,
+   GFP_KERNEL | __GFP_ZERO | 
__GFP_THISNODE |
+   __GFP_NOWARN, get_order(size)));
+   if (!local_mem)
+   return -ENOMEM;
+   per_cpu(trace_imc_mem, cpu_id) = local_mem;
+
+   /* Initialise the counters for trace mode */
+   rc = opal_imc_counters_init(OPAL_IMC_COUNTERS_TRACE, __pa((void 
*)local_mem),
+   get_hard_smp_processor_id(cpu_id));
+   if (rc) {
+   pr_info("IMC:opal init failed for trace imc\n");
+   return rc;
+   }
+   }
+
+   mtspr(SPRN_LDBAR, 0);
+   return 0;
+}
+
+static int ppc_trace_imc_cpu_online(unsigned int cpu)
+{
+   return trace_imc_mem_alloc(cpu, trace_imc_mem_size);
+}
+
+static int ppc_trace_imc_cpu_offline(unsigned int cpu)
+{
+   mtspr(SPRN_LDBAR, 0);
+   return 0;
+}
+
+static int trace_imc_cpu_init(void)
+{
+   return cpuhp_setup_state(CPUHP_AP_PERF_POWERPC_TRACE_IMC_ONLINE,
+ "perf/powerpc/imc_trace:online",
+ ppc_trace_imc_cpu_online,
+ ppc_trace_imc_cpu_offline);
+}
+
  /* update_pmu_ops : Populate the appropriate operations for "pmu" */
  static int update_pmu_ops(struct imc_pmu *pmu)
  {
@@ -1189,6 +1241,17 @@ static void cleanup_all_thread_imc_memory(void)
}
  }

+static void cleanup_all_trace_imc_memory(void)
+{
+   int i, order = get_order(trace_imc_mem_size);
+
+   for_each_online_cpu(i) {
+   if (per_cpu(trace_imc_mem, i))
+   free_pages((u64)per_cpu(trace_imc_mem, i), order);
+
+   }
+}
+
  /* Function to free the attr_groups which are dynamically allocated */
  static void imc_common_mem_free(struct imc_pmu *pmu_ptr)
  {
@@ -1230,6 +1293,11 @@ static void imc_common_cpuhp_mem_free(struct imc_pmu 
*pmu_ptr)
cpuhp_remove_state(CPUHP_AP_PERF_POWERPC_THREAD_IMC_ONLINE);
cleanup_all_thread_imc_memory();
}
+
+   if (pmu_ptr->domain == IMC_DOMAIN_TRACE) {
+   cpuhp_remove_state(CPUHP_AP_PERF_POWERPC_TRACE_IMC_ONLINE);
+   cleanup_all_trace_imc_memory();
+   }
  }

  /*
@@ -1312,6 +1380,21 @@ static int imc_mem_init(struct imc_pmu *pmu_ptr, struct 
device_node *parent,

thread_imc_pmu = pmu_ptr;
break;
+   case IMC_DOMAIN_TRACE:
+   /* Update the pmu name */
+   pmu_ptr->pmu.name = kasprintf(GFP_KERNEL, "%s%s", s, "_imc");
+   if (!pmu_ptr->pmu.name)
+   return -ENOMEM;
+
+   trace_imc_mem_size = pmu_ptr->counter_mem_size;
+   for_each_online_cpu(cpu) {
+   res = trace_imc_mem_alloc(cpu, trace_imc_mem_size);
+   if (res) {
+   cleanup_all_trace_imc_memory();
+   goto err;
+   }
+   }
+   break;
default:
return -EINVAL;
}
@@ -1384,6 +1467,14 @@ int init_imc_pmu(struct device_node *parent, struct 
imc_pmu *pmu_ptr, int pmu_id
goto err_free_mem;
}

+   break;
+   case IMC_DOMAIN_TRACE:
+   ret = trace_imc_cpu_init();
+   if (ret) {
+   cleanup_all_trace_imc_memory();
+  

Re: [PATCH v2 2/5] powerpc/perf: Rearrange setting of ldbar for thread-imc

2018-12-18 Thread Madhavan Srinivasan



On 14/12/18 2:41 PM, Anju T Sudhakar wrote:

LDBAR holds the memory address allocated for each cpu. For thread-imc
the mode bit (i.e bit 1) of LDBAR is set to accumulation.
Currently, ldbar is loaded with per cpu memory address and mode set to
accumulation at boot time.

To enable trace-imc, the mode bit of ldbar should be set to 'trace'. So to
accommodate trace-mode of IMC, reposition setting of ldbar for thread-imc
to thread_imc_event_add(). Also reset ldbar at thread_imc_event_del().


Changes looks fine to me.

Reviewed-by: Madhavan Srinivasan 


Signed-off-by: Anju T Sudhakar 
---
  arch/powerpc/perf/imc-pmu.c | 28 +---
  1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/arch/powerpc/perf/imc-pmu.c b/arch/powerpc/perf/imc-pmu.c
index f292a3f284f1..3bef46f8417d 100644
--- a/arch/powerpc/perf/imc-pmu.c
+++ b/arch/powerpc/perf/imc-pmu.c
@@ -806,8 +806,11 @@ static int core_imc_event_init(struct perf_event *event)
  }

  /*
- * Allocates a page of memory for each of the online cpus, and write the
- * physical base address of that page to the LDBAR for that cpu.
+ * Allocates a page of memory for each of the online cpus, and load
+ * LDBAR with 0.
+ * The physical base address of the page allocated for a cpu will be
+ * written to the LDBAR for that cpu, when the thread-imc event
+ * is added.
   *
   * LDBAR Register Layout:
   *
@@ -825,7 +828,7 @@ static int core_imc_event_init(struct perf_event *event)
   */
  static int thread_imc_mem_alloc(int cpu_id, int size)
  {
-   u64 ldbar_value, *local_mem = per_cpu(thread_imc_mem, cpu_id);
+   u64 *local_mem = per_cpu(thread_imc_mem, cpu_id);
int nid = cpu_to_node(cpu_id);

if (!local_mem) {
@@ -842,9 +845,7 @@ static int thread_imc_mem_alloc(int cpu_id, int size)
per_cpu(thread_imc_mem, cpu_id) = local_mem;
}

-   ldbar_value = ((u64)local_mem & THREAD_IMC_LDBAR_MASK) | 
THREAD_IMC_ENABLE;
-
-   mtspr(SPRN_LDBAR, ldbar_value);
+   mtspr(SPRN_LDBAR, 0);
return 0;
  }

@@ -995,6 +996,7 @@ static int thread_imc_event_add(struct perf_event *event, 
int flags)
  {
int core_id;
struct imc_pmu_ref *ref;
+   u64 ldbar_value, *local_mem = per_cpu(thread_imc_mem, 
smp_processor_id());

if (flags & PERF_EF_START)
imc_event_start(event, flags);
@@ -1003,6 +1005,9 @@ static int thread_imc_event_add(struct perf_event *event, 
int flags)
return -EINVAL;

core_id = smp_processor_id() / threads_per_core;
+   ldbar_value = ((u64)local_mem & THREAD_IMC_LDBAR_MASK) | 
THREAD_IMC_ENABLE;
+   mtspr(SPRN_LDBAR, ldbar_value);
+
/*
 * imc pmus are enabled only when it is used.
 * See if this is triggered for the first time.
@@ -1034,11 +1039,7 @@ static void thread_imc_event_del(struct perf_event 
*event, int flags)
int core_id;
struct imc_pmu_ref *ref;

-   /*
-* Take a snapshot and calculate the delta and update
-* the event counter values.
-*/
-   imc_event_update(event);
+   mtspr(SPRN_LDBAR, 0);

core_id = smp_processor_id() / threads_per_core;
ref = _imc_refc[core_id];
@@ -1057,6 +1058,11 @@ static void thread_imc_event_del(struct perf_event 
*event, int flags)
ref->refc = 0;
}
mutex_unlock(>lock);
+   /*
+* Take a snapshot and calculate the delta and update
+* the event counter values.
+*/
+   imc_event_update(event);
  }

  /* update_pmu_ops : Populate the appropriate operations for "pmu" */




Re: [PATCH v4 perf, bpf-next 5/7] perf util: handle PERF_RECORD_BPF_EVENT

2018-12-18 Thread Song Liu
Please ignore this one. The other 5/7 is the right patch. 

Thanks,
Song

> On Dec 18, 2018, at 10:02 PM, Song Liu  wrote:
> 
> This patch handles PERF_RECORD_BPF_EVENT in perf record/report.
> Specifically, map and symbol are created for PERF_BPF_EVENT_PROG_LOAD,
> and removed for PERF_BPF_EVENT_PROG_UNLOAD.
> 
> This patch also set perf_event_attr.bpf_event properly. The flag is
> ON by default.
> 
> Signed-off-by: Song Liu 
> ---
> tools/perf/util/event.c   | 20 ++
> tools/perf/util/event.h   | 18 +
> tools/perf/util/evsel.c   |  9 +++
> tools/perf/util/evsel.h   |  1 +
> tools/perf/util/machine.c | 56 +++
> tools/perf/util/machine.h |  5 +++-
> tools/perf/util/session.c |  4 +++
> tools/perf/util/tool.h|  4 ++-
> 8 files changed, 115 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
> index e9c108a6b1c3..4b47194eaa4b 100644
> --- a/tools/perf/util/event.c
> +++ b/tools/perf/util/event.c
> @@ -24,6 +24,7 @@
> #include "symbol/kallsyms.h"
> #include "asm/bug.h"
> #include "stat.h"
> +#include "session.h"
> 
> static const char *perf_event__names[] = {
>   [0] = "TOTAL",
> @@ -43,6 +44,7 @@ static const char *perf_event__names[] = {
>   [PERF_RECORD_SWITCH]= "SWITCH",
>   [PERF_RECORD_SWITCH_CPU_WIDE]   = "SWITCH_CPU_WIDE",
>   [PERF_RECORD_NAMESPACES]= "NAMESPACES",
> + [PERF_RECORD_KSYMBOL]   = "KSYMBOL",
>   [PERF_RECORD_HEADER_ATTR]   = "ATTR",
>   [PERF_RECORD_HEADER_EVENT_TYPE] = "EVENT_TYPE",
>   [PERF_RECORD_HEADER_TRACING_DATA]   = "TRACING_DATA",
> @@ -1335,6 +1337,14 @@ int perf_event__process_switch(struct perf_tool *tool 
> __maybe_unused,
>   return machine__process_switch_event(machine, event);
> }
> 
> +int perf_event__process_ksymbol(struct perf_tool *tool __maybe_unused,
> + union perf_event *event,
> + struct perf_sample *sample __maybe_unused,
> + struct machine *machine)
> +{
> + return machine__process_ksymbol(machine, event, sample);
> +}
> +
> size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp)
> {
>   return fprintf(fp, " %d/%d: [%#" PRIx64 "(%#" PRIx64 ") @ %#" PRIx64 
> "]: %c %s\n",
> @@ -1467,6 +1477,13 @@ static size_t perf_event__fprintf_lost(union 
> perf_event *event, FILE *fp)
>   return fprintf(fp, " lost %" PRIu64 "\n", event->lost.lost);
> }
> 
> +size_t perf_event__fprintf_ksymbol(union perf_event *event, FILE *fp)
> +{
> + return fprintf(fp, " ksymbol event with addr %lx len %lu name %s\n",
> +event->ksymbol_event.addr, event->ksymbol_event.len,
> +event->ksymbol_event.name);
> +}
> +
> size_t perf_event__fprintf(union perf_event *event, FILE *fp)
> {
>   size_t ret = fprintf(fp, "PERF_RECORD_%s",
> @@ -1502,6 +1519,9 @@ size_t perf_event__fprintf(union perf_event *event, 
> FILE *fp)
>   case PERF_RECORD_LOST:
>   ret += perf_event__fprintf_lost(event, fp);
>   break;
> + case PERF_RECORD_KSYMBOL:
> + ret += perf_event__fprintf_ksymbol(event, fp);
> + break;
>   default:
>   ret += fprintf(fp, "\n");
>   }
> diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
> index bfa60bcafbde..100b59f1fdec 100644
> --- a/tools/perf/util/event.h
> +++ b/tools/perf/util/event.h
> @@ -5,6 +5,7 @@
> #include 
> #include 
> #include 
> +#include 
> 
> #include "../perf.h"
> #include "build-id.h"
> @@ -84,6 +85,17 @@ struct throttle_event {
>   u64 stream_id;
> };
> 
> +#ifndef KSYM_NAME_LEN
> +#define KSYM_NAME_LEN 256
> +#endif
> +
> +struct ksymbol_event {
> + struct perf_event_header header;
> + u64 addr;
> + u64 len;
> + char name[KSYM_NAME_LEN];
> +};
> +
> #define PERF_SAMPLE_MASK  \
>   (PERF_SAMPLE_IP | PERF_SAMPLE_TID | \
>PERF_SAMPLE_TIME | PERF_SAMPLE_ADDR |  \
> @@ -651,6 +663,7 @@ union perf_event {
>   struct stat_round_event stat_round;
>   struct time_conv_event  time_conv;
>   struct feature_eventfeat;
> + struct ksymbol_eventksymbol_event;
> };
> 
> void perf_event__print_totals(void);
> @@ -750,6 +763,10 @@ int perf_event__process_exit(struct perf_tool *tool,
>union perf_event *event,
>struct perf_sample *sample,
>struct machine *machine);
> +int perf_event__process_ksymbol(struct perf_tool *tool,
> + union perf_event *event,
> + struct perf_sample *sample,
> + struct machine *machine);
> int perf_tool__process_synth_event(struct perf_tool *tool,
>   

Re: [PATCH v2 1/5] powerpc/include: Add data structures and macros for IMC trace mode

2018-12-18 Thread Madhavan Srinivasan



On 14/12/18 2:41 PM, Anju T Sudhakar wrote:

Add the macros needed for IMC (In-Memory Collection Counters) trace-mode
and data structure to hold the trace-imc record data.
Also, add the new type "OPAL_IMC_COUNTERS_TRACE" in 'opal-api.h', since
there is a new switch case added in the opal-calls for IMC.


Reviewed-by: Madhavan Srinivasan 


Signed-off-by: Anju T Sudhakar 
---
  arch/powerpc/include/asm/imc-pmu.h  | 39 +
  arch/powerpc/include/asm/opal-api.h |  1 +
  2 files changed, 40 insertions(+)

diff --git a/arch/powerpc/include/asm/imc-pmu.h 
b/arch/powerpc/include/asm/imc-pmu.h
index 69f516ecb2fd..7c2ef0e42661 100644
--- a/arch/powerpc/include/asm/imc-pmu.h
+++ b/arch/powerpc/include/asm/imc-pmu.h
@@ -33,6 +33,7 @@
   */
  #define THREAD_IMC_LDBAR_MASK   0x0003e000ULL
  #define THREAD_IMC_ENABLE   0x8000ULL
+#define TRACE_IMC_ENABLE   0x4000ULL

  /*
   * For debugfs interface for imc-mode and imc-command
@@ -59,6 +60,34 @@ struct imc_events {
char *scale;
  };

+/*
+ * Trace IMC hardware updates a 64bytes record on
+ * Core Performance Monitoring Counter (CPMC)
+ * overflow. Here is the layout for the trace imc record
+ *
+ * DW 0 : Timebase
+ * DW 1 : Program Counter
+ * DW 2 : PIDR information
+ * DW 3 : CPMC1
+ * DW 4 : CPMC2
+ * DW 5 : CPMC3
+ * Dw 6 : CPMC4
+ * DW 7 : Timebase
+ * .
+ *
+ * The following is the data structure to hold trace imc data.
+ */
+struct trace_imc_data {
+   u64 tb1;
+   u64 ip;
+   u64 val;
+   u64 cpmc1;
+   u64 cpmc2;
+   u64 cpmc3;
+   u64 cpmc4;
+   u64 tb2;
+};
+
  /* Event attribute array index */
  #define IMC_FORMAT_ATTR   0
  #define IMC_EVENT_ATTR1
@@ -68,6 +97,13 @@ struct imc_events {
  /* PMU Format attribute macros */
  #define IMC_EVENT_OFFSET_MASK 0xULL

+/*
+ * Macro to mask bits 0:21 of first double word(which is the timebase) to
+ * compare with 8th double word (timebase) of trace imc record data.
+ */
+#define IMC_TRACE_RECORD_TB1_MASK  0x3ffULL
+
+
  /*
   * Device tree parser code detects IMC pmu support and
   * registers new IMC pmus. This structure will hold the
@@ -113,6 +149,7 @@ struct imc_pmu_ref {

  enum {
IMC_TYPE_THREAD = 0x1,
+   IMC_TYPE_TRACE  = 0x2,
IMC_TYPE_CORE   = 0x4,
IMC_TYPE_CHIP   = 0x10,
  };
@@ -123,6 +160,8 @@ enum {
  #define IMC_DOMAIN_NEST   1
  #define IMC_DOMAIN_CORE   2
  #define IMC_DOMAIN_THREAD 3
+/* For trace-imc the domain is still thread but it operates in trace-mode */
+#define IMC_DOMAIN_TRACE   4

  extern int init_imc_pmu(struct device_node *parent,
struct imc_pmu *pmu_ptr, int pmu_id);
diff --git a/arch/powerpc/include/asm/opal-api.h 
b/arch/powerpc/include/asm/opal-api.h
index 870fb7b239ea..a4130b21b159 100644
--- a/arch/powerpc/include/asm/opal-api.h
+++ b/arch/powerpc/include/asm/opal-api.h
@@ -1118,6 +1118,7 @@ enum {
  enum {
OPAL_IMC_COUNTERS_NEST = 1,
OPAL_IMC_COUNTERS_CORE = 2,
+   OPAL_IMC_COUNTERS_TRACE = 3,
  };






Re: [PATCH] vxge: ensure data0 is initialized in when fetching firmware version information

2018-12-18 Thread David Miller
From: Colin King 
Date: Tue, 18 Dec 2018 15:19:47 +

> From: Colin Ian King 
> 
> Currently variable data0 is not being initialized so a garbage value is
> being passed to vxge_hw_vpath_fw_api and this value is being written to
> the rts_access_steer_data0 register.  There are other occurrances where
> data0 is being initialized to zero (e.g. in function
> vxge_hw_upgrade_read_version) so I think it makes sense to ensure data0
> is initialized likewise to 0.
> 
> Detected by CoverityScan, CID#140696 ("Uninitialized scalar variable")
> 
> Fixes: 8424e00dfd52 ("vxge: serialize access to steering control register")
> Signed-off-by: Colin Ian King 

Applied.


[PATCH v4 perf, bpf-next 7/7] perf tools: synthesize PERF_RECORD_* for loaded BPF programs

2018-12-18 Thread Song Liu
This patch synthesize PERF_RECORD_KSYMBOL and PERF_RECORD_BPF_EVENT for
BPF programs loaded before perf-record. This is achieved by gathering
information about all BPF programs via sys_bpf.

Signed-off-by: Song Liu 
---
 tools/perf/builtin-record.c |   6 ++
 tools/perf/util/bpf-event.c | 204 
 tools/perf/util/bpf-event.h |   5 +
 3 files changed, 215 insertions(+)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 8983ab2e60dd..d239e8bf2f0f 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -41,6 +41,7 @@
 #include "util/perf-hooks.h"
 #include "util/time-utils.h"
 #include "util/units.h"
+#include "util/bpf-event.h"
 #include "asm/bug.h"
 
 #include 
@@ -855,6 +856,11 @@ static int record__synthesize(struct record *rec, bool 
tail)
return err;
}
 
+   err = perf_event__synthesize_bpf_events(tool, process_synthesized_event,
+   machine, opts);
+   if (err < 0)
+   pr_warning("Couldn't synthesize bpf events.\n");
+
err = __machine__synthesize_threads(machine, tool, >target, 
rec->evlist->threads,
process_synthesized_event, 
opts->sample_address,
opts->proc_map_timeout, 1);
diff --git a/tools/perf/util/bpf-event.c b/tools/perf/util/bpf-event.c
index f24f75506f51..98208b577533 100644
--- a/tools/perf/util/bpf-event.c
+++ b/tools/perf/util/bpf-event.c
@@ -1,10 +1,24 @@
 // SPDX-License-Identifier: GPL-2.0
 #include 
 #include 
+#include 
+#include 
 #include "bpf-event.h"
 #include "debug.h"
 #include "symbol.h"
 
+#define ptr_to_u64(ptr)((__u64)(unsigned long)(ptr))
+
+static int snprintf_hex(char *buf, size_t size, unsigned char *data, size_t 
len)
+{
+   int ret = 0;
+   size_t i;
+
+   for (i = 0; i < len; i++)
+   ret += snprintf(buf + ret, size - ret, "%02x", data[i]);
+   return ret;
+}
+
 int machine__process_bpf_event(struct machine *machine __maybe_unused,
   union perf_event *event,
   struct perf_sample *sample __maybe_unused)
@@ -13,3 +27,193 @@ int machine__process_bpf_event(struct machine *machine 
__maybe_unused,
perf_event__fprintf_bpf_event(event, stderr);
return 0;
 }
+
+/*
+ * Synthesize PERF_RECORD_KSYMBOL and PERF_RECORD_BPF_EVENT for one bpf
+ * program. One PERF_RECORD_BPF_EVENT is generated for the program. And
+ * one PERF_RECORD_KSYMBOL is generated for each sub program.
+ */
+static int perf_event__synthesize_one_bpf_prog(struct perf_tool *tool,
+  perf_event__handler_t process,
+  struct machine *machine,
+  int fd,
+  union perf_event *event,
+  struct record_opts *opts)
+{
+   struct ksymbol_event *ksymbol_event = >ksymbol_event;
+   struct bpf_event *bpf_event = >bpf_event;
+   u32 sub_prog_cnt, i, func_info_rec_size;
+   u8 (*prog_tags)[BPF_TAG_SIZE] = NULL;
+   struct bpf_prog_info info = {};
+   u32 info_len = sizeof(info);
+   void *func_infos = NULL;
+   u64 *prog_addrs = NULL;
+   struct btf *btf = NULL;
+   u32 *prog_lens = NULL;
+   bool has_btf = false;
+   int err = 0;
+
+   /* Call bpf_obj_get_info_by_fd() to get sizes of arrays */
+   err = bpf_obj_get_info_by_fd(fd, , _len);
+
+   if (err || info_len < 192 /* need field prog_tags */)
+   return -1;
+
+   /* number of ksyms, func_lengths, and tags should match */
+   sub_prog_cnt = info.nr_jited_ksyms;
+   if (sub_prog_cnt != info.nr_prog_tags ||
+   sub_prog_cnt != info.nr_jited_func_lens)
+   return -1;
+
+   /* check BTF func info support */
+   if (info.btf_id && info.nr_func_info && info.func_info_rec_size) {
+   /* btf func info number should be same as sub_prog_cnt */
+   if (sub_prog_cnt != info.nr_func_info)
+   return -1;
+   if (btf__get_from_id(info.btf_id, ))
+   return -1;
+   func_info_rec_size = info.func_info_rec_size;
+   func_infos = malloc(sub_prog_cnt * func_info_rec_size);
+   if (!func_infos)
+   return -1;
+   has_btf = true;
+   }
+
+   /*
+* We need address, length, and tag for each sub program.
+* Allocate memory and call bpf_obj_get_info_by_fd() again
+*/
+   prog_addrs = (u64 *)malloc(sizeof(u64) * sub_prog_cnt);
+   prog_lens = (u32 *)malloc(sizeof(u64) * sub_prog_cnt);
+   prog_tags = malloc(sizeof(u8) * BPF_TAG_SIZE * sub_prog_cnt);
+
+   err = !prog_addrs || !prog_lens || !prog_tags;
+   

[PATCH v4 perf, bpf-next 6/7] perf util: handle PERF_RECORD_BPF_EVENT

2018-12-18 Thread Song Liu
This patch adds basic handling of PERF_RECORD_BPF_EVENT.
Tracking of PERF_RECORD_BPF_EVENT is OFF by default. Option --bpf-event
is added to turn it on.

Signed-off-by: Song Liu 
---
 tools/perf/builtin-record.c |  1 +
 tools/perf/perf.h   |  1 +
 tools/perf/util/Build   |  2 ++
 tools/perf/util/bpf-event.c | 15 +++
 tools/perf/util/bpf-event.h | 11 +++
 tools/perf/util/event.c | 20 
 tools/perf/util/event.h | 16 
 tools/perf/util/evsel.c | 10 ++
 tools/perf/util/evsel.h |  1 +
 tools/perf/util/machine.c   |  3 +++
 tools/perf/util/session.c   |  4 
 tools/perf/util/tool.h  |  3 ++-
 12 files changed, 86 insertions(+), 1 deletion(-)
 create mode 100644 tools/perf/util/bpf-event.c
 create mode 100644 tools/perf/util/bpf-event.h

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 488779bc4c8d..8983ab2e60dd 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1604,6 +1604,7 @@ static struct option __record_options[] = {
OPT_BOOLEAN(0, "tail-synthesize", _synthesize,
"synthesize non-sample events at the end of output"),
OPT_BOOLEAN(0, "overwrite", , "use overwrite 
mode"),
+   OPT_BOOLEAN(0, "bpf-event", _event, "record bpf 
events"),
OPT_BOOLEAN(0, "strict-freq", _freq,
"Fail if the specified frequency can't be used"),
OPT_CALLBACK('F', "freq", , "freq or 'max'",
diff --git a/tools/perf/perf.h b/tools/perf/perf.h
index 0ed4a34c74c4..a45a85ab38d4 100644
--- a/tools/perf/perf.h
+++ b/tools/perf/perf.h
@@ -66,6 +66,7 @@ struct record_opts {
bool ignore_missing_thread;
bool strict_freq;
bool sample_id;
+   bool bpf_event;
unsigned int freq;
unsigned int mmap_pages;
unsigned int auxtrace_mmap_pages;
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index b7bf201fe8a8..99455f30c264 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -151,6 +151,8 @@ endif
 
 libperf-y += perf-hooks.o
 
+libperf-$(CONFIG_LIBBPF) += bpf-event.o
+
 libperf-$(CONFIG_CXX) += c++/
 
 CFLAGS_config.o   += -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
diff --git a/tools/perf/util/bpf-event.c b/tools/perf/util/bpf-event.c
new file mode 100644
index ..f24f75506f51
--- /dev/null
+++ b/tools/perf/util/bpf-event.c
@@ -0,0 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0
+#include 
+#include 
+#include "bpf-event.h"
+#include "debug.h"
+#include "symbol.h"
+
+int machine__process_bpf_event(struct machine *machine __maybe_unused,
+  union perf_event *event,
+  struct perf_sample *sample __maybe_unused)
+{
+   if (dump_trace)
+   perf_event__fprintf_bpf_event(event, stderr);
+   return 0;
+}
diff --git a/tools/perf/util/bpf-event.h b/tools/perf/util/bpf-event.h
new file mode 100644
index ..d5ca355dd298
--- /dev/null
+++ b/tools/perf/util/bpf-event.h
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __PERF_BPF_EVENT_H
+#define __PERF_BPF_EVENT_H
+
+#include "machine.h"
+
+int machine__process_bpf_event(struct machine *machine,
+  union perf_event *event,
+  struct perf_sample *sample);
+
+#endif
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 4b47194eaa4b..0e2eb3a3eab4 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -25,6 +25,7 @@
 #include "asm/bug.h"
 #include "stat.h"
 #include "session.h"
+#include "bpf-event.h"
 
 static const char *perf_event__names[] = {
[0] = "TOTAL",
@@ -45,6 +46,7 @@ static const char *perf_event__names[] = {
[PERF_RECORD_SWITCH_CPU_WIDE]   = "SWITCH_CPU_WIDE",
[PERF_RECORD_NAMESPACES]= "NAMESPACES",
[PERF_RECORD_KSYMBOL]   = "KSYMBOL",
+   [PERF_RECORD_BPF_EVENT] = "BPF_EVENT",
[PERF_RECORD_HEADER_ATTR]   = "ATTR",
[PERF_RECORD_HEADER_EVENT_TYPE] = "EVENT_TYPE",
[PERF_RECORD_HEADER_TRACING_DATA]   = "TRACING_DATA",
@@ -1345,6 +1347,14 @@ int perf_event__process_ksymbol(struct perf_tool *tool 
__maybe_unused,
return machine__process_ksymbol(machine, event, sample);
 }
 
+int perf_event__process_bpf_event(struct perf_tool *tool __maybe_unused,
+ union perf_event *event,
+ struct perf_sample *sample __maybe_unused,
+ struct machine *machine)
+{
+   return machine__process_bpf_event(machine, event, sample);
+}
+
 size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp)
 {
return fprintf(fp, " %d/%d: [%#" PRIx64 "(%#" PRIx64 ") @ %#" PRIx64 
"]: %c %s\n",
@@ -1484,6 +1494,13 @@ size_t 

Re: [PATCH v3] net/smc: fix TCP fallback socket release

2018-12-18 Thread David Miller
From: Myungho Jung 
Date: Tue, 18 Dec 2018 09:02:25 -0800

> clcsock can be released while kernel_accept() references it in TCP
> listen worker. Also, clcsock needs to wake up before released if TCP
> fallback is used and the clcsock is blocked by accept. Add a lock to
> safely release clcsock and call kernel_sock_shutdown() to wake up
> clcsock from accept in smc_release().
> 
> Reported-by: syzbot+0bf2e01269f1274b4...@syzkaller.appspotmail.com
> Reported-by: syzbot+e3132895630f95730...@syzkaller.appspotmail.com
> Signed-off-by: Myungho Jung 

Applied, thanks.


[PATCH v4 perf, bpf-next 5/7] perf util: handle PERF_RECORD_KSYMBOL

2018-12-18 Thread Song Liu
This patch handles PERF_RECORD_KSYMBOL in perf record/report.
Specifically, map and symbol are created for ksymbol register, and
removed for ksymbol unregister.

This patch also set perf_event_attr.ksymbol properly. The flag is
ON by default.

Signed-off-by: Song Liu 
---
 tools/perf/util/event.c   | 20 ++
 tools/perf/util/event.h   | 18 +
 tools/perf/util/evsel.c   |  9 +++
 tools/perf/util/evsel.h   |  1 +
 tools/perf/util/machine.c | 57 +++
 tools/perf/util/machine.h |  5 +++-
 tools/perf/util/session.c |  4 +++
 tools/perf/util/tool.h|  4 ++-
 8 files changed, 116 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index e9c108a6b1c3..4b47194eaa4b 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -24,6 +24,7 @@
 #include "symbol/kallsyms.h"
 #include "asm/bug.h"
 #include "stat.h"
+#include "session.h"
 
 static const char *perf_event__names[] = {
[0] = "TOTAL",
@@ -43,6 +44,7 @@ static const char *perf_event__names[] = {
[PERF_RECORD_SWITCH]= "SWITCH",
[PERF_RECORD_SWITCH_CPU_WIDE]   = "SWITCH_CPU_WIDE",
[PERF_RECORD_NAMESPACES]= "NAMESPACES",
+   [PERF_RECORD_KSYMBOL]   = "KSYMBOL",
[PERF_RECORD_HEADER_ATTR]   = "ATTR",
[PERF_RECORD_HEADER_EVENT_TYPE] = "EVENT_TYPE",
[PERF_RECORD_HEADER_TRACING_DATA]   = "TRACING_DATA",
@@ -1335,6 +1337,14 @@ int perf_event__process_switch(struct perf_tool *tool 
__maybe_unused,
return machine__process_switch_event(machine, event);
 }
 
+int perf_event__process_ksymbol(struct perf_tool *tool __maybe_unused,
+   union perf_event *event,
+   struct perf_sample *sample __maybe_unused,
+   struct machine *machine)
+{
+   return machine__process_ksymbol(machine, event, sample);
+}
+
 size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp)
 {
return fprintf(fp, " %d/%d: [%#" PRIx64 "(%#" PRIx64 ") @ %#" PRIx64 
"]: %c %s\n",
@@ -1467,6 +1477,13 @@ static size_t perf_event__fprintf_lost(union perf_event 
*event, FILE *fp)
return fprintf(fp, " lost %" PRIu64 "\n", event->lost.lost);
 }
 
+size_t perf_event__fprintf_ksymbol(union perf_event *event, FILE *fp)
+{
+   return fprintf(fp, " ksymbol event with addr %lx len %lu name %s\n",
+  event->ksymbol_event.addr, event->ksymbol_event.len,
+  event->ksymbol_event.name);
+}
+
 size_t perf_event__fprintf(union perf_event *event, FILE *fp)
 {
size_t ret = fprintf(fp, "PERF_RECORD_%s",
@@ -1502,6 +1519,9 @@ size_t perf_event__fprintf(union perf_event *event, FILE 
*fp)
case PERF_RECORD_LOST:
ret += perf_event__fprintf_lost(event, fp);
break;
+   case PERF_RECORD_KSYMBOL:
+   ret += perf_event__fprintf_ksymbol(event, fp);
+   break;
default:
ret += fprintf(fp, "\n");
}
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index bfa60bcafbde..100b59f1fdec 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -5,6 +5,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "../perf.h"
 #include "build-id.h"
@@ -84,6 +85,17 @@ struct throttle_event {
u64 stream_id;
 };
 
+#ifndef KSYM_NAME_LEN
+#define KSYM_NAME_LEN 256
+#endif
+
+struct ksymbol_event {
+   struct perf_event_header header;
+   u64 addr;
+   u64 len;
+   char name[KSYM_NAME_LEN];
+};
+
 #define PERF_SAMPLE_MASK   \
(PERF_SAMPLE_IP | PERF_SAMPLE_TID | \
 PERF_SAMPLE_TIME | PERF_SAMPLE_ADDR |  \
@@ -651,6 +663,7 @@ union perf_event {
struct stat_round_event stat_round;
struct time_conv_event  time_conv;
struct feature_eventfeat;
+   struct ksymbol_eventksymbol_event;
 };
 
 void perf_event__print_totals(void);
@@ -750,6 +763,10 @@ int perf_event__process_exit(struct perf_tool *tool,
 union perf_event *event,
 struct perf_sample *sample,
 struct machine *machine);
+int perf_event__process_ksymbol(struct perf_tool *tool,
+   union perf_event *event,
+   struct perf_sample *sample,
+   struct machine *machine);
 int perf_tool__process_synth_event(struct perf_tool *tool,
   union perf_event *event,
   struct machine *machine,
@@ -814,6 +831,7 @@ size_t perf_event__fprintf_switch(union perf_event *event, 
FILE *fp);
 size_t perf_event__fprintf_thread_map(union perf_event *event, FILE *fp);
 

[PATCH v4 perf, bpf-next 5/7] perf util: handle PERF_RECORD_BPF_EVENT

2018-12-18 Thread Song Liu
This patch handles PERF_RECORD_BPF_EVENT in perf record/report.
Specifically, map and symbol are created for PERF_BPF_EVENT_PROG_LOAD,
and removed for PERF_BPF_EVENT_PROG_UNLOAD.

This patch also set perf_event_attr.bpf_event properly. The flag is
ON by default.

Signed-off-by: Song Liu 
---
 tools/perf/util/event.c   | 20 ++
 tools/perf/util/event.h   | 18 +
 tools/perf/util/evsel.c   |  9 +++
 tools/perf/util/evsel.h   |  1 +
 tools/perf/util/machine.c | 56 +++
 tools/perf/util/machine.h |  5 +++-
 tools/perf/util/session.c |  4 +++
 tools/perf/util/tool.h|  4 ++-
 8 files changed, 115 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index e9c108a6b1c3..4b47194eaa4b 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -24,6 +24,7 @@
 #include "symbol/kallsyms.h"
 #include "asm/bug.h"
 #include "stat.h"
+#include "session.h"
 
 static const char *perf_event__names[] = {
[0] = "TOTAL",
@@ -43,6 +44,7 @@ static const char *perf_event__names[] = {
[PERF_RECORD_SWITCH]= "SWITCH",
[PERF_RECORD_SWITCH_CPU_WIDE]   = "SWITCH_CPU_WIDE",
[PERF_RECORD_NAMESPACES]= "NAMESPACES",
+   [PERF_RECORD_KSYMBOL]   = "KSYMBOL",
[PERF_RECORD_HEADER_ATTR]   = "ATTR",
[PERF_RECORD_HEADER_EVENT_TYPE] = "EVENT_TYPE",
[PERF_RECORD_HEADER_TRACING_DATA]   = "TRACING_DATA",
@@ -1335,6 +1337,14 @@ int perf_event__process_switch(struct perf_tool *tool 
__maybe_unused,
return machine__process_switch_event(machine, event);
 }
 
+int perf_event__process_ksymbol(struct perf_tool *tool __maybe_unused,
+   union perf_event *event,
+   struct perf_sample *sample __maybe_unused,
+   struct machine *machine)
+{
+   return machine__process_ksymbol(machine, event, sample);
+}
+
 size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp)
 {
return fprintf(fp, " %d/%d: [%#" PRIx64 "(%#" PRIx64 ") @ %#" PRIx64 
"]: %c %s\n",
@@ -1467,6 +1477,13 @@ static size_t perf_event__fprintf_lost(union perf_event 
*event, FILE *fp)
return fprintf(fp, " lost %" PRIu64 "\n", event->lost.lost);
 }
 
+size_t perf_event__fprintf_ksymbol(union perf_event *event, FILE *fp)
+{
+   return fprintf(fp, " ksymbol event with addr %lx len %lu name %s\n",
+  event->ksymbol_event.addr, event->ksymbol_event.len,
+  event->ksymbol_event.name);
+}
+
 size_t perf_event__fprintf(union perf_event *event, FILE *fp)
 {
size_t ret = fprintf(fp, "PERF_RECORD_%s",
@@ -1502,6 +1519,9 @@ size_t perf_event__fprintf(union perf_event *event, FILE 
*fp)
case PERF_RECORD_LOST:
ret += perf_event__fprintf_lost(event, fp);
break;
+   case PERF_RECORD_KSYMBOL:
+   ret += perf_event__fprintf_ksymbol(event, fp);
+   break;
default:
ret += fprintf(fp, "\n");
}
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index bfa60bcafbde..100b59f1fdec 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -5,6 +5,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "../perf.h"
 #include "build-id.h"
@@ -84,6 +85,17 @@ struct throttle_event {
u64 stream_id;
 };
 
+#ifndef KSYM_NAME_LEN
+#define KSYM_NAME_LEN 256
+#endif
+
+struct ksymbol_event {
+   struct perf_event_header header;
+   u64 addr;
+   u64 len;
+   char name[KSYM_NAME_LEN];
+};
+
 #define PERF_SAMPLE_MASK   \
(PERF_SAMPLE_IP | PERF_SAMPLE_TID | \
 PERF_SAMPLE_TIME | PERF_SAMPLE_ADDR |  \
@@ -651,6 +663,7 @@ union perf_event {
struct stat_round_event stat_round;
struct time_conv_event  time_conv;
struct feature_eventfeat;
+   struct ksymbol_eventksymbol_event;
 };
 
 void perf_event__print_totals(void);
@@ -750,6 +763,10 @@ int perf_event__process_exit(struct perf_tool *tool,
 union perf_event *event,
 struct perf_sample *sample,
 struct machine *machine);
+int perf_event__process_ksymbol(struct perf_tool *tool,
+   union perf_event *event,
+   struct perf_sample *sample,
+   struct machine *machine);
 int perf_tool__process_synth_event(struct perf_tool *tool,
   union perf_event *event,
   struct machine *machine,
@@ -814,6 +831,7 @@ size_t perf_event__fprintf_switch(union perf_event *event, 
FILE *fp);
 size_t perf_event__fprintf_thread_map(union perf_event 

[PATCH v4 perf, bpf-next 3/7] perf, bpf: introduce PERF_RECORD_BPF_EVENT

2018-12-18 Thread Song Liu
For better performance analysis of BPF programs, this patch introduces
PERF_RECORD_BPF_EVENT, a new perf_event_type that exposes BPF program
load/unload information to user space.

Each BPF program may contain up to BPF_MAX_SUBPROGS (256) sub programs.
The following example shows kernel symbols for a BPF program with 7
sub programs:

a0257cf9 t bpf_prog_b07ccb89267cf242_F
a02592e1 t bpf_prog_2dcecc18072623fc_F
a025b0e9 t bpf_prog_bb7a405ebaec5d5c_F
a025dd2c t bpf_prog_a7540d4a39ec1fc7_F
a025fcca t bpf_prog_05762d4ade0e3737_F
a026108f t bpf_prog_db4bd11e35df90d4_F
a0263f00 t bpf_prog_89d64e4abf0f0126_F
a0257cf9 t bpf_prog_ae31629322c4b018__dummy_tracepoi

When a bpf program is loaded, PERF_RECORD_KSYMBOL is generated for
each of these sub programs. Therefore, PERF_RECORD_BPF_EVENT is not
needed for simple profiling.

For annotation, user space need to listen to PERF_RECORD_BPF_EVENT
and gather more information about these (sub) programs via sys_bpf.

Signed-off-by: Song Liu 
---
 include/linux/filter.h  |   7 ++
 include/linux/perf_event.h  |   3 +
 include/uapi/linux/perf_event.h |  29 +++-
 kernel/bpf/core.c   |   2 +-
 kernel/bpf/syscall.c|   2 +
 kernel/events/core.c| 120 
 6 files changed, 161 insertions(+), 2 deletions(-)

diff --git a/include/linux/filter.h b/include/linux/filter.h
index 537e9e7c6e6f..45d23560f90b 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -955,6 +955,7 @@ bpf_address_lookup(unsigned long addr, unsigned long *size,
 
 void bpf_prog_kallsyms_add(struct bpf_prog *fp);
 void bpf_prog_kallsyms_del(struct bpf_prog *fp);
+void bpf_get_prog_name(const struct bpf_prog *prog, char *sym);
 
 #else /* CONFIG_BPF_JIT */
 
@@ -1010,6 +1011,12 @@ static inline void bpf_prog_kallsyms_add(struct bpf_prog 
*fp)
 static inline void bpf_prog_kallsyms_del(struct bpf_prog *fp)
 {
 }
+
+static inline void bpf_get_prog_name(const struct bpf_prog *prog, char *sym)
+{
+   sym[0] = '\0';
+}
+
 #endif /* CONFIG_BPF_JIT */
 
 void bpf_prog_kallsyms_del_subprogs(struct bpf_prog *fp);
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 4fd28b16c526..8e752a244ed7 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -1118,6 +1118,9 @@ extern void perf_event_mmap(struct vm_area_struct *vma);
 typedef int (perf_ksymbol_get_name_f)(char *name, int name_len, void *data);
 extern void perf_event_ksymbol(int type, u64 addr, u64 len, bool unregister,
   perf_ksymbol_get_name_f get_name, void *data);
+extern void perf_event_bpf_event(struct bpf_prog *prog,
+enum perf_bpf_event_type type,
+u16 flags);
 
 extern struct perf_guest_info_callbacks *perf_guest_cbs;
 extern int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks 
*callbacks);
diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index 6c9e327e87ed..68db04058408 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -373,7 +373,8 @@ struct perf_event_attr {
write_backward :  1, /* Write ring buffer from 
end to beginning */
namespaces :  1, /* include namespaces data 
*/
ksymbol:  1, /* include ksymbol events 
*/
-   __reserved_1   : 34;
+   bpf_event  :  1, /* include bpf events */
+   __reserved_1   : 33;
 
union {
__u32   wakeup_events;/* wakeup every n events */
@@ -986,9 +987,35 @@ enum perf_event_type {
 */
PERF_RECORD_KSYMBOL = 17,
 
+   /*
+* Record bpf events:
+*  enum perf_bpf_event_type {
+*  PERF_BPF_EVENT_UNKNOWN  = 0,
+*  PERF_BPF_EVENT_PROG_LOAD= 1,
+*  PERF_BPF_EVENT_PROG_UNLOAD  = 2,
+*  };
+*
+* struct {
+*  struct perf_event_headerheader;
+*  u16 type;
+*  u16 flags;
+*  u32 id;
+*  u8  tag[BPF_TAG_SIZE];
+*  struct sample_idsample_id;
+* };
+*/
+   PERF_RECORD_BPF_EVENT   = 18,
+
PERF_RECORD_MAX,/* non-ABI */
 };
 
+enum perf_bpf_event_type {
+   PERF_BPF_EVENT_UNKNOWN  = 0,
+   PERF_BPF_EVENT_PROG_LOAD= 1,
+   PERF_BPF_EVENT_PROG_UNLOAD  = 2,
+   PERF_BPF_EVENT_MAX, /* non-ABI */
+};
+
 #define PERF_MAX_STACK_DEPTH   127
 #define 

Re: [PATCH] xen/netfront: tolerate frags with no data

2018-12-18 Thread Juergen Gross
On 19/12/2018 07:00, David Miller wrote:
> From: Juergen Gross 
> Date: Tue, 18 Dec 2018 16:06:19 +0100
> 
>> At least old Xen net backends seem to send frags with no real data
>> sometimes. In case such a fragment happens to occur with the frag limit
>> already reached the frontend will BUG currently even if this situation
>> is easily recoverable.
>>
>> Modify the BUG_ON() condition accordingly.
>>
>> Tested-by: Dietmar Hahn 
>> Signed-off-by: Juergen Gross 
> 
> Applied and queued up for -stable.
> 
> But many of these BUG's in the driver should be converted to
> WARNs and recovery code added.
> 

Right, but that will be no stable material then. Will start that effort
after Christmas.


Juergen


[PATCH v4 perf, bpf-next 0/7] reveal invisible bpf programs

2018-12-18 Thread Song Liu
This set catches symbol for all bpf programs loaded/unloaded
before/during/after perf-record run PERF_RECORD_KSYMBOL and
PERF_RECORD_BPF_EVENT.

PERF_RECORD_KSYMBOL and PERF_RECORD_BPF_EVENT includes key information
of a bpf program load and unload. They are sent through perf ringbuffer,
and stored in perf.data. PERF_RECORD_KSYMBOL includes basic information
for simple profiling. It is ON by default. PERF_RECORD_BPF_EVENT is
used to gather more information of the bpf program. It is necessary for
perf-annotate of bpf programs.

Before this patch, perf-report will not be able to recover symbols of
bpf programs once the programs are unloaded.

This is to follow up Alexei's early effort [2] to show bpf programs via
mmap events.

Thanks,
Song


Changes v3 -> PATCH v4:
1. Split information about bpf program  into PERF_RECORD_KSYMBOL (with
   name, addr, len); and PERF_RECORD_BPF_EVENT PERF_RECORD_BPF_EVENT
   (with id, tag);
2. Split the implementation in kernel and user space.

Changes v2 -> PATCH v3:
1. Rebase on bpf-next tree, and on top of BPF sub program tag patches [1]
   for latest information in bpf_prog_info.
2. Complete handling and synthesizing PERF_RECORD_BPF_EVENT in perf.

Changes v1 -> PATCH v2:
1. Only 3 of the 5 patches in v1, to focus on ABI first;
2. Generate PERF_RECORD_BPF_EVENT per bpf sub program instead of per prog;
3. Modify PERF_RECORD_BPF_EVENT with more details (addr, len, name),
   so that it can be used for basic profiling without calling sys_bpf.

Changes RFC -> PATCH v1:
1. In perf-record, poll vip events in a separate thread;
2. Add tag to bpf prog name;
3. Small refactorings.

[1] https://patchwork.ozlabs.org/project/netdev/list/?series=81037
[2] https://www.spinics.net/lists/netdev/msg524232.html

Song Liu (7):
  perf, bpf: Introduce PERF_RECORD_KSYMBOL
  sync tools/include/uapi/linux/perf_event.h
  perf, bpf: introduce PERF_RECORD_BPF_EVENT
  sync tools/include/uapi/linux/perf_event.h
  perf util: handle PERF_RECORD_KSYMBOL
  perf util: handle PERF_RECORD_BPF_EVENT
  perf tools: synthesize PERF_RECORD_* for loaded BPF programs

 include/linux/filter.h|   7 +
 include/linux/perf_event.h|   9 ++
 include/uapi/linux/perf_event.h   |  50 +-
 kernel/bpf/core.c |   2 +-
 kernel/bpf/syscall.c  |   2 +
 kernel/events/core.c  | 218 -
 tools/include/uapi/linux/perf_event.h |  50 +-
 tools/perf/builtin-record.c   |   7 +
 tools/perf/perf.h |   1 +
 tools/perf/util/Build |   2 +
 tools/perf/util/bpf-event.c   | 219 ++
 tools/perf/util/bpf-event.h   |  16 ++
 tools/perf/util/event.c   |  40 +
 tools/perf/util/event.h   |  34 
 tools/perf/util/evsel.c   |  19 +++
 tools/perf/util/evsel.h   |   2 +
 tools/perf/util/machine.c |  60 +++
 tools/perf/util/machine.h |   5 +-
 tools/perf/util/session.c |   8 +
 tools/perf/util/tool.h|   5 +-
 20 files changed, 750 insertions(+), 6 deletions(-)
 create mode 100644 tools/perf/util/bpf-event.c
 create mode 100644 tools/perf/util/bpf-event.h

--
2.17.1


[PATCH v4 perf, bpf-next 2/7] sync tools/include/uapi/linux/perf_event.h

2018-12-18 Thread Song Liu
sync changes for PERF_RECORD_KSYMBOL

Signed-off-by: Song Liu 
---
 tools/include/uapi/linux/perf_event.h | 23 ++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/tools/include/uapi/linux/perf_event.h 
b/tools/include/uapi/linux/perf_event.h
index 9de8780ac8d9..6c9e327e87ed 100644
--- a/tools/include/uapi/linux/perf_event.h
+++ b/tools/include/uapi/linux/perf_event.h
@@ -372,7 +372,8 @@ struct perf_event_attr {
context_switch :  1, /* context switch data */
write_backward :  1, /* Write ring buffer from 
end to beginning */
namespaces :  1, /* include namespaces data 
*/
-   __reserved_1   : 35;
+   ksymbol:  1, /* include ksymbol events 
*/
+   __reserved_1   : 34;
 
union {
__u32   wakeup_events;/* wakeup every n events */
@@ -648,11 +649,18 @@ struct perf_event_mmap_page {
  *   PERF_RECORD_MISC_COMM_EXEC  - PERF_RECORD_COMM event
  *   PERF_RECORD_MISC_FORK_EXEC  - PERF_RECORD_FORK event (perf internal)
  *   PERF_RECORD_MISC_SWITCH_OUT - PERF_RECORD_SWITCH* events
+ *   PERF_RECORD_MISC_KSYMBOL_*  - PERF_RECORD_KSYMBOL event
  */
 #define PERF_RECORD_MISC_MMAP_DATA (1 << 13)
 #define PERF_RECORD_MISC_COMM_EXEC (1 << 13)
 #define PERF_RECORD_MISC_FORK_EXEC (1 << 13)
 #define PERF_RECORD_MISC_SWITCH_OUT(1 << 13)
+
+#define PERF_RECORD_MISC_KSYMBOL_UNREGISTER(1 << 3)
+#define PERF_RECORD_MISC_KSYMBOL_TYPE_MASK (7 << 4)
+#define PERF_RECORD_MISC_KSYMBOL_TYPE_UNKNOWN  (0 << 4)
+#define PERF_RECORD_MISC_KSYMBOL_TYPE_BPF  (1 << 4)
+
 /*
  * These PERF_RECORD_MISC_* flags below are safely reused
  * for the following events:
@@ -965,6 +973,19 @@ enum perf_event_type {
 */
PERF_RECORD_NAMESPACES  = 16,
 
+   /*
+* Record ksymbol register/unregister events:
+*
+* struct {
+*  struct perf_event_headerheader;
+*  u64 addr;
+*  u64 len;
+*  charname[];
+*  struct sample_idsample_id;
+* };
+*/
+   PERF_RECORD_KSYMBOL = 17,
+
PERF_RECORD_MAX,/* non-ABI */
 };
 
-- 
2.17.1



[PATCH v4 perf, bpf-next 1/7] perf, bpf: Introduce PERF_RECORD_KSYMBOL

2018-12-18 Thread Song Liu
For better performance analysis of dynamically JITed and loaded kernel
functions, such as BPF programs, this patch introduces
PERF_RECORD_KSYMBOL, a new perf_event_type that exposes kernel symbol
register/unregister information to user space.

The following data structure is used for PERF_RECORD_KSYMBOL.

/*
 * struct {
 *  struct perf_event_headerheader;
 *  u64 addr;
 *  u64 len;
 *  charname[];
 *  struct sample_idsample_id;
 * };
 */

PERF_RECORD_KSYMBOL uses 4 more bits (bit 3-6) in header.misc:
Bit 3 is used to differentiate register vs. unregister. Bit 4-6
encode types of the ksymbol. The following are details of the
assignment of these bits:

Signed-off-by: Song Liu 
---
 include/linux/perf_event.h  |  6 ++
 include/uapi/linux/perf_event.h | 23 +++-
 kernel/events/core.c| 98 -
 3 files changed, 125 insertions(+), 2 deletions(-)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 53c500f0ca79..4fd28b16c526 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -1113,6 +1113,12 @@ static inline void perf_event_task_sched_out(struct 
task_struct *prev,
 }
 
 extern void perf_event_mmap(struct vm_area_struct *vma);
+
+/* callback function to generate ksymbol name */
+typedef int (perf_ksymbol_get_name_f)(char *name, int name_len, void *data);
+extern void perf_event_ksymbol(int type, u64 addr, u64 len, bool unregister,
+  perf_ksymbol_get_name_f get_name, void *data);
+
 extern struct perf_guest_info_callbacks *perf_guest_cbs;
 extern int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks 
*callbacks);
 extern int perf_unregister_guest_info_callbacks(struct 
perf_guest_info_callbacks *callbacks);
diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index 9de8780ac8d9..6c9e327e87ed 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -372,7 +372,8 @@ struct perf_event_attr {
context_switch :  1, /* context switch data */
write_backward :  1, /* Write ring buffer from 
end to beginning */
namespaces :  1, /* include namespaces data 
*/
-   __reserved_1   : 35;
+   ksymbol:  1, /* include ksymbol events 
*/
+   __reserved_1   : 34;
 
union {
__u32   wakeup_events;/* wakeup every n events */
@@ -648,11 +649,18 @@ struct perf_event_mmap_page {
  *   PERF_RECORD_MISC_COMM_EXEC  - PERF_RECORD_COMM event
  *   PERF_RECORD_MISC_FORK_EXEC  - PERF_RECORD_FORK event (perf internal)
  *   PERF_RECORD_MISC_SWITCH_OUT - PERF_RECORD_SWITCH* events
+ *   PERF_RECORD_MISC_KSYMBOL_*  - PERF_RECORD_KSYMBOL event
  */
 #define PERF_RECORD_MISC_MMAP_DATA (1 << 13)
 #define PERF_RECORD_MISC_COMM_EXEC (1 << 13)
 #define PERF_RECORD_MISC_FORK_EXEC (1 << 13)
 #define PERF_RECORD_MISC_SWITCH_OUT(1 << 13)
+
+#define PERF_RECORD_MISC_KSYMBOL_UNREGISTER(1 << 3)
+#define PERF_RECORD_MISC_KSYMBOL_TYPE_MASK (7 << 4)
+#define PERF_RECORD_MISC_KSYMBOL_TYPE_UNKNOWN  (0 << 4)
+#define PERF_RECORD_MISC_KSYMBOL_TYPE_BPF  (1 << 4)
+
 /*
  * These PERF_RECORD_MISC_* flags below are safely reused
  * for the following events:
@@ -965,6 +973,19 @@ enum perf_event_type {
 */
PERF_RECORD_NAMESPACES  = 16,
 
+   /*
+* Record ksymbol register/unregister events:
+*
+* struct {
+*  struct perf_event_headerheader;
+*  u64 addr;
+*  u64 len;
+*  charname[];
+*  struct sample_idsample_id;
+* };
+*/
+   PERF_RECORD_KSYMBOL = 17,
+
PERF_RECORD_MAX,/* non-ABI */
 };
 
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 84530ab358c3..c0ac6dee367c 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -385,6 +385,7 @@ static atomic_t nr_namespaces_events __read_mostly;
 static atomic_t nr_task_events __read_mostly;
 static atomic_t nr_freq_events __read_mostly;
 static atomic_t nr_switch_events __read_mostly;
+static atomic_t nr_ksymbol_events __read_mostly;
 
 static LIST_HEAD(pmus);
 static DEFINE_MUTEX(pmus_lock);
@@ -4235,7 +4236,7 @@ static bool is_sb_event(struct perf_event *event)
 
if (attr->mmap || attr->mmap_data || attr->mmap2 ||
attr->comm || attr->comm_exec ||
-   attr->task ||
+   attr->task || attr->ksymbol ||
attr->context_switch)
  

[PATCH v4 perf, bpf-next 4/7] sync tools/include/uapi/linux/perf_event.h

2018-12-18 Thread Song Liu
sync for PERF_RECORD_BPF_EVENT

Signed-off-by: Song Liu 
---
 tools/include/uapi/linux/perf_event.h | 29 ++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/tools/include/uapi/linux/perf_event.h 
b/tools/include/uapi/linux/perf_event.h
index 6c9e327e87ed..68db04058408 100644
--- a/tools/include/uapi/linux/perf_event.h
+++ b/tools/include/uapi/linux/perf_event.h
@@ -373,7 +373,8 @@ struct perf_event_attr {
write_backward :  1, /* Write ring buffer from 
end to beginning */
namespaces :  1, /* include namespaces data 
*/
ksymbol:  1, /* include ksymbol events 
*/
-   __reserved_1   : 34;
+   bpf_event  :  1, /* include bpf events */
+   __reserved_1   : 33;
 
union {
__u32   wakeup_events;/* wakeup every n events */
@@ -986,9 +987,35 @@ enum perf_event_type {
 */
PERF_RECORD_KSYMBOL = 17,
 
+   /*
+* Record bpf events:
+*  enum perf_bpf_event_type {
+*  PERF_BPF_EVENT_UNKNOWN  = 0,
+*  PERF_BPF_EVENT_PROG_LOAD= 1,
+*  PERF_BPF_EVENT_PROG_UNLOAD  = 2,
+*  };
+*
+* struct {
+*  struct perf_event_headerheader;
+*  u16 type;
+*  u16 flags;
+*  u32 id;
+*  u8  tag[BPF_TAG_SIZE];
+*  struct sample_idsample_id;
+* };
+*/
+   PERF_RECORD_BPF_EVENT   = 18,
+
PERF_RECORD_MAX,/* non-ABI */
 };
 
+enum perf_bpf_event_type {
+   PERF_BPF_EVENT_UNKNOWN  = 0,
+   PERF_BPF_EVENT_PROG_LOAD= 1,
+   PERF_BPF_EVENT_PROG_UNLOAD  = 2,
+   PERF_BPF_EVENT_MAX, /* non-ABI */
+};
+
 #define PERF_MAX_STACK_DEPTH   127
 #define PERF_MAX_CONTEXTS_PER_STACK  8
 
-- 
2.17.1



[PATCH v6 8/8] gpio: pcie-idio-24: Utilize for_each_set_clump8 macro

2018-12-18 Thread William Breathitt Gray
Replace verbose implementation in get_multiple/set_multiple callbacks
with for_each_set_clump8 macro to simplify code and improve clarity.

Signed-off-by: William Breathitt Gray 
---
 drivers/gpio/gpio-pcie-idio-24.c | 109 ---
 1 file changed, 40 insertions(+), 69 deletions(-)

diff --git a/drivers/gpio/gpio-pcie-idio-24.c b/drivers/gpio/gpio-pcie-idio-24.c
index 52f1647a46fd..b1686b052633 100644
--- a/drivers/gpio/gpio-pcie-idio-24.c
+++ b/drivers/gpio/gpio-pcie-idio-24.c
@@ -198,52 +198,34 @@ static int idio_24_gpio_get_multiple(struct gpio_chip 
*chip,
unsigned long *mask, unsigned long *bits)
 {
struct idio_24_gpio *const idio24gpio = gpiochip_get_data(chip);
-   size_t i;
-   const unsigned int gpio_reg_size = 8;
-   unsigned int bits_offset;
-   size_t word_index;
-   unsigned int word_offset;
-   unsigned long word_mask;
-   const unsigned long port_mask = GENMASK(gpio_reg_size - 1, 0);
-   unsigned long port_state;
+   unsigned int offset;
+   unsigned long gpio_mask;
void __iomem *ports[] = {
>reg->out0_7, >reg->out8_15,
>reg->out16_23, >reg->in0_7,
>reg->in8_15, >reg->in16_23,
};
+   size_t index;
+   unsigned long port_state;
const unsigned long out_mode_mask = BIT(1);
 
/* clear bits array to a clean slate */
bitmap_zero(bits, chip->ngpio);
 
-   /* get bits are evaluated a gpio port register at a time */
-   for (i = 0; i < ARRAY_SIZE(ports) + 1; i++) {
-   /* gpio offset in bits array */
-   bits_offset = i * gpio_reg_size;
-
-   /* word index for bits array */
-   word_index = BIT_WORD(bits_offset);
-
-   /* gpio offset within current word of bits array */
-   word_offset = bits_offset % BITS_PER_LONG;
-
-   /* mask of get bits for current gpio within current word */
-   word_mask = mask[word_index] & (port_mask << word_offset);
-   if (!word_mask) {
-   /* no get bits in this port so skip to next one */
-   continue;
-   }
+   for_each_set_clump8(offset, gpio_mask, mask, ARRAY_SIZE(ports) * 8) {
+   index = offset / 8;
 
/* read bits from current gpio port (port 6 is TTL GPIO) */
-   if (i < 6)
-   port_state = ioread8(ports[i]);
+   if (index < 6)
+   port_state = ioread8(ports[index]);
else if (ioread8(>reg->ctl) & out_mode_mask)
port_state = ioread8(>reg->ttl_out0_7);
else
port_state = ioread8(>reg->ttl_in0_7);
 
-   /* store acquired bits at respective bits array offset */
-   bits[word_index] |= (port_state << word_offset) & word_mask;
+   port_state &= gpio_mask;
+
+   bitmap_set_value8(bits, _state, offset);
}
 
return 0;
@@ -294,59 +276,48 @@ static void idio_24_gpio_set_multiple(struct gpio_chip 
*chip,
unsigned long *mask, unsigned long *bits)
 {
struct idio_24_gpio *const idio24gpio = gpiochip_get_data(chip);
-   size_t i;
-   unsigned long bits_offset;
+   unsigned int offset;
unsigned long gpio_mask;
-   const unsigned int gpio_reg_size = 8;
-   const unsigned long port_mask = GENMASK(gpio_reg_size, 0);
-   unsigned long flags;
-   unsigned int out_state;
void __iomem *ports[] = {
>reg->out0_7, >reg->out8_15,
>reg->out16_23
};
+   size_t index;
+   unsigned int bitmask;
+   unsigned long flags;
+   unsigned int out_state;
const unsigned long out_mode_mask = BIT(1);
-   const unsigned int ttl_offset = 48;
-   const size_t ttl_i = BIT_WORD(ttl_offset);
-   const unsigned int word_offset = ttl_offset % BITS_PER_LONG;
-   const unsigned long ttl_mask = (mask[ttl_i] >> word_offset) & port_mask;
-   const unsigned long ttl_bits = (bits[ttl_i] >> word_offset) & ttl_mask;
-
-   /* set bits are processed a gpio port register at a time */
-   for (i = 0; i < ARRAY_SIZE(ports); i++) {
-   /* gpio offset in bits array */
-   bits_offset = i * gpio_reg_size;
-
-   /* check if any set bits for current port */
-   gpio_mask = (*mask >> bits_offset) & port_mask;
-   if (!gpio_mask) {
-   /* no set bits for this port so move on to next port */
-   continue;
-   }
 
-   raw_spin_lock_irqsave(>lock, flags);
+   for_each_set_clump8(offset, gpio_mask, mask, ARRAY_SIZE(ports) * 8) {
+   index = offset / 8;
 
-   /* process output lines */
-   out_state = ioread8(ports[i]) & ~gpio_mask;
-   out_state 

[PATCH v6 5/8] gpio: gpio-mm: Utilize for_each_set_clump8 macro

2018-12-18 Thread William Breathitt Gray
Replace verbose implementation in get_multiple/set_multiple callbacks
with for_each_set_clump8 macro to simplify code and improve clarity.

Signed-off-by: William Breathitt Gray 
---
 drivers/gpio/gpio-gpio-mm.c | 71 +++--
 1 file changed, 20 insertions(+), 51 deletions(-)

diff --git a/drivers/gpio/gpio-gpio-mm.c b/drivers/gpio/gpio-gpio-mm.c
index 8c150fd68d9d..5647abe72376 100644
--- a/drivers/gpio/gpio-gpio-mm.c
+++ b/drivers/gpio/gpio-gpio-mm.c
@@ -172,46 +172,25 @@ static int gpiomm_gpio_get(struct gpio_chip *chip, 
unsigned int offset)
return !!(port_state & mask);
 }
 
+static const size_t ports[] = { 0, 1, 2, 4, 5, 6 };
+
 static int gpiomm_gpio_get_multiple(struct gpio_chip *chip, unsigned long 
*mask,
unsigned long *bits)
 {
struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip);
-   size_t i;
-   static const size_t ports[] = { 0, 1, 2, 4, 5, 6 };
-   const unsigned int gpio_reg_size = 8;
-   unsigned int bits_offset;
-   size_t word_index;
-   unsigned int word_offset;
-   unsigned long word_mask;
-   const unsigned long port_mask = GENMASK(gpio_reg_size - 1, 0);
+   unsigned int offset;
+   unsigned long gpio_mask;
+   unsigned int port_addr;
unsigned long port_state;
 
/* clear bits array to a clean slate */
bitmap_zero(bits, chip->ngpio);
 
-   /* get bits are evaluated a gpio port register at a time */
-   for (i = 0; i < ARRAY_SIZE(ports); i++) {
-   /* gpio offset in bits array */
-   bits_offset = i * gpio_reg_size;
-
-   /* word index for bits array */
-   word_index = BIT_WORD(bits_offset);
-
-   /* gpio offset within current word of bits array */
-   word_offset = bits_offset % BITS_PER_LONG;
-
-   /* mask of get bits for current gpio within current word */
-   word_mask = mask[word_index] & (port_mask << word_offset);
-   if (!word_mask) {
-   /* no get bits in this port so skip to next one */
-   continue;
-   }
-
-   /* read bits from current gpio port */
-   port_state = inb(gpiommgpio->base + ports[i]);
+   for_each_set_clump8(offset, gpio_mask, mask, ARRAY_SIZE(ports) * 8) {
+   port_addr = gpiommgpio->base + ports[offset / 8];
+   port_state = inb(port_addr) & gpio_mask;
 
-   /* store acquired bits at respective bits array offset */
-   bits[word_index] |= (port_state << word_offset) & word_mask;
+   bitmap_set_value8(bits, _state, offset);
}
 
return 0;
@@ -242,37 +221,27 @@ static void gpiomm_gpio_set_multiple(struct gpio_chip 
*chip,
unsigned long *mask, unsigned long *bits)
 {
struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip);
-   unsigned int i;
-   const unsigned int gpio_reg_size = 8;
-   unsigned int port;
-   unsigned int out_port;
+   unsigned int offset;
+   unsigned long gpio_mask;
+   size_t index;
+   unsigned int port_addr;
unsigned int bitmask;
unsigned long flags;
 
-   /* set bits are evaluated a gpio register size at a time */
-   for (i = 0; i < chip->ngpio; i += gpio_reg_size) {
-   /* no more set bits in this mask word; skip to the next word */
-   if (!mask[BIT_WORD(i)]) {
-   i = (BIT_WORD(i) + 1) * BITS_PER_LONG - gpio_reg_size;
-   continue;
-   }
+   for_each_set_clump8(offset, gpio_mask, mask, ARRAY_SIZE(ports) * 8) {
+   index = offset / 8;
+   port_addr = gpiommgpio->base + ports[index];
 
-   port = i / gpio_reg_size;
-   out_port = (port > 2) ? port + 1 : port;
-   bitmask = mask[BIT_WORD(i)] & bits[BIT_WORD(i)];
+   bitmask = bitmap_get_value8(bits, offset) & gpio_mask;
 
spin_lock_irqsave(>lock, flags);
 
/* update output state data and set device gpio register */
-   gpiommgpio->out_state[port] &= ~mask[BIT_WORD(i)];
-   gpiommgpio->out_state[port] |= bitmask;
-   outb(gpiommgpio->out_state[port], gpiommgpio->base + out_port);
+   gpiommgpio->out_state[index] &= ~gpio_mask;
+   gpiommgpio->out_state[index] |= bitmask;
+   outb(gpiommgpio->out_state[index], port_addr);
 
spin_unlock_irqrestore(>lock, flags);
-
-   /* prepare for next gpio register set */
-   mask[BIT_WORD(i)] >>= gpio_reg_size;
-   bits[BIT_WORD(i)] >>= gpio_reg_size;
}
 }
 
-- 
2.20.1



[PATCH v6 6/8] gpio: ws16c48: Utilize for_each_set_clump8 macro

2018-12-18 Thread William Breathitt Gray
Replace verbose implementation in get_multiple/set_multiple callbacks
with for_each_set_clump8 macro to simplify code and improve clarity.

Signed-off-by: William Breathitt Gray 
---
 drivers/gpio/gpio-ws16c48.c | 71 ++---
 1 file changed, 19 insertions(+), 52 deletions(-)

diff --git a/drivers/gpio/gpio-ws16c48.c b/drivers/gpio/gpio-ws16c48.c
index 5cf3697bfb15..b4c544d5da18 100644
--- a/drivers/gpio/gpio-ws16c48.c
+++ b/drivers/gpio/gpio-ws16c48.c
@@ -134,42 +134,19 @@ static int ws16c48_gpio_get_multiple(struct gpio_chip 
*chip,
unsigned long *mask, unsigned long *bits)
 {
struct ws16c48_gpio *const ws16c48gpio = gpiochip_get_data(chip);
-   const unsigned int gpio_reg_size = 8;
-   size_t i;
-   const size_t num_ports = chip->ngpio / gpio_reg_size;
-   unsigned int bits_offset;
-   size_t word_index;
-   unsigned int word_offset;
-   unsigned long word_mask;
-   const unsigned long port_mask = GENMASK(gpio_reg_size - 1, 0);
+   unsigned int offset;
+   unsigned long gpio_mask;
+   unsigned int port_addr;
unsigned long port_state;
 
/* clear bits array to a clean slate */
bitmap_zero(bits, chip->ngpio);
 
-   /* get bits are evaluated a gpio port register at a time */
-   for (i = 0; i < num_ports; i++) {
-   /* gpio offset in bits array */
-   bits_offset = i * gpio_reg_size;
+   for_each_set_clump8(offset, gpio_mask, mask, chip->ngpio) {
+   port_addr = ws16c48gpio->base + offset / 8;
+   port_state = inb(port_addr) & gpio_mask;
 
-   /* word index for bits array */
-   word_index = BIT_WORD(bits_offset);
-
-   /* gpio offset within current word of bits array */
-   word_offset = bits_offset % BITS_PER_LONG;
-
-   /* mask of get bits for current gpio within current word */
-   word_mask = mask[word_index] & (port_mask << word_offset);
-   if (!word_mask) {
-   /* no get bits in this port so skip to next one */
-   continue;
-   }
-
-   /* read bits from current gpio port */
-   port_state = inb(ws16c48gpio->base + i);
-
-   /* store acquired bits at respective bits array offset */
-   bits[word_index] |= (port_state << word_offset) & word_mask;
+   bitmap_set_value8(bits, _state, offset);
}
 
return 0;
@@ -203,39 +180,29 @@ static void ws16c48_gpio_set_multiple(struct gpio_chip 
*chip,
unsigned long *mask, unsigned long *bits)
 {
struct ws16c48_gpio *const ws16c48gpio = gpiochip_get_data(chip);
-   unsigned int i;
-   const unsigned int gpio_reg_size = 8;
-   unsigned int port;
-   unsigned int iomask;
+   unsigned int offset;
+   unsigned long gpio_mask;
+   size_t index;
+   unsigned int port_addr;
unsigned int bitmask;
unsigned long flags;
 
-   /* set bits are evaluated a gpio register size at a time */
-   for (i = 0; i < chip->ngpio; i += gpio_reg_size) {
-   /* no more set bits in this mask word; skip to the next word */
-   if (!mask[BIT_WORD(i)]) {
-   i = (BIT_WORD(i) + 1) * BITS_PER_LONG - gpio_reg_size;
-   continue;
-   }
-
-   port = i / gpio_reg_size;
+   for_each_set_clump8(offset, gpio_mask, mask, chip->ngpio) {
+   index = offset / 8;
+   port_addr = ws16c48gpio->base + index;
 
/* mask out GPIO configured for input */
-   iomask = mask[BIT_WORD(i)] & ~ws16c48gpio->io_state[port];
-   bitmask = iomask & bits[BIT_WORD(i)];
+   gpio_mask &= ~ws16c48gpio->io_state[index];
+   bitmask = bitmap_get_value8(bits, offset) & gpio_mask;
 
raw_spin_lock_irqsave(>lock, flags);
 
/* update output state data and set device gpio register */
-   ws16c48gpio->out_state[port] &= ~iomask;
-   ws16c48gpio->out_state[port] |= bitmask;
-   outb(ws16c48gpio->out_state[port], ws16c48gpio->base + port);
+   ws16c48gpio->out_state[index] &= ~gpio_mask;
+   ws16c48gpio->out_state[index] |= bitmask;
+   outb(ws16c48gpio->out_state[index], port_addr);
 
raw_spin_unlock_irqrestore(>lock, flags);
-
-   /* prepare for next gpio register set */
-   mask[BIT_WORD(i)] >>= gpio_reg_size;
-   bits[BIT_WORD(i)] >>= gpio_reg_size;
}
 }
 
-- 
2.20.1



[PATCH v6 7/8] gpio: pci-idio-16: Utilize for_each_set_clump8 macro

2018-12-18 Thread William Breathitt Gray
Replace verbose implementation in get_multiple/set_multiple callbacks
with for_each_set_clump8 macro to simplify code and improve clarity.

Signed-off-by: William Breathitt Gray 
---
 drivers/gpio/gpio-pci-idio-16.c | 73 -
 1 file changed, 26 insertions(+), 47 deletions(-)

diff --git a/drivers/gpio/gpio-pci-idio-16.c b/drivers/gpio/gpio-pci-idio-16.c
index 6b7349783223..4eb89f8b5f9b 100644
--- a/drivers/gpio/gpio-pci-idio-16.c
+++ b/drivers/gpio/gpio-pci-idio-16.c
@@ -108,45 +108,23 @@ static int idio_16_gpio_get_multiple(struct gpio_chip 
*chip,
unsigned long *mask, unsigned long *bits)
 {
struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip);
-   size_t i;
-   const unsigned int gpio_reg_size = 8;
-   unsigned int bits_offset;
-   size_t word_index;
-   unsigned int word_offset;
-   unsigned long word_mask;
-   const unsigned long port_mask = GENMASK(gpio_reg_size - 1, 0);
-   unsigned long port_state;
+   unsigned int offset;
+   unsigned long gpio_mask;
void __iomem *ports[] = {
>reg->out0_7, >reg->out8_15,
>reg->in0_7, >reg->in8_15,
};
+   void __iomem *port_addr;
+   unsigned long port_state;
 
/* clear bits array to a clean slate */
bitmap_zero(bits, chip->ngpio);
 
-   /* get bits are evaluated a gpio port register at a time */
-   for (i = 0; i < ARRAY_SIZE(ports); i++) {
-   /* gpio offset in bits array */
-   bits_offset = i * gpio_reg_size;
-
-   /* word index for bits array */
-   word_index = BIT_WORD(bits_offset);
-
-   /* gpio offset within current word of bits array */
-   word_offset = bits_offset % BITS_PER_LONG;
+   for_each_set_clump8(offset, gpio_mask, mask, ARRAY_SIZE(ports) * 8) {
+   port_addr = ports[offset / 8];
+   port_state = ioread8(port_addr) & gpio_mask;
 
-   /* mask of get bits for current gpio within current word */
-   word_mask = mask[word_index] & (port_mask << word_offset);
-   if (!word_mask) {
-   /* no get bits in this port so skip to next one */
-   continue;
-   }
-
-   /* read bits from current gpio port */
-   port_state = ioread8(ports[i]);
-
-   /* store acquired bits at respective bits array offset */
-   bits[word_index] |= (port_state << word_offset) & word_mask;
+   bitmap_set_value8(bits, _state, offset);
}
 
return 0;
@@ -186,30 +164,31 @@ static void idio_16_gpio_set_multiple(struct gpio_chip 
*chip,
unsigned long *mask, unsigned long *bits)
 {
struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip);
+   unsigned int offset;
+   unsigned long gpio_mask;
+   void __iomem *ports[] = {
+   >reg->out0_7, >reg->out8_15,
+   };
+   size_t index;
+   void __iomem *port_addr;
+   unsigned int bitmask;
unsigned long flags;
unsigned int out_state;
 
-   raw_spin_lock_irqsave(>lock, flags);
+   for_each_set_clump8(offset, gpio_mask, mask, ARRAY_SIZE(ports) * 8) {
+   index = offset / 8;
+   port_addr = ports[index];
 
-   /* process output lines 0-7 */
-   if (*mask & 0xFF) {
-   out_state = ioread8(>reg->out0_7) & ~*mask;
-   out_state |= *mask & *bits;
-   iowrite8(out_state, >reg->out0_7);
-   }
+   bitmask = bitmap_get_value8(bits, offset) & gpio_mask;
+
+   raw_spin_lock_irqsave(>lock, flags);
 
-   /* shift to next output line word */
-   *mask >>= 8;
+   out_state = ioread8(port_addr) & ~gpio_mask;
+   out_state |= bitmask;
+   iowrite8(out_state, port_addr);
 
-   /* process output lines 8-15 */
-   if (*mask & 0xFF) {
-   *bits >>= 8;
-   out_state = ioread8(>reg->out8_15) & ~*mask;
-   out_state |= *mask & *bits;
-   iowrite8(out_state, >reg->out8_15);
+   raw_spin_unlock_irqrestore(>lock, flags);
}
-
-   raw_spin_unlock_irqrestore(>lock, flags);
 }
 
 static void idio_16_irq_ack(struct irq_data *data)
-- 
2.20.1



[PATCH v6 4/8] gpio: 104-idi-48: Utilize for_each_set_clump8 macro

2018-12-18 Thread William Breathitt Gray
Replace verbose implementation in get_multiple/set_multiple callbacks
with for_each_set_clump8 macro to simplify code and improve clarity.

Signed-off-by: William Breathitt Gray 
---
 drivers/gpio/gpio-104-idi-48.c | 36 +++---
 1 file changed, 7 insertions(+), 29 deletions(-)

diff --git a/drivers/gpio/gpio-104-idi-48.c b/drivers/gpio/gpio-104-idi-48.c
index 88dc6f2449f6..fdf1b8b64cc4 100644
--- a/drivers/gpio/gpio-104-idi-48.c
+++ b/drivers/gpio/gpio-104-idi-48.c
@@ -93,42 +93,20 @@ static int idi_48_gpio_get_multiple(struct gpio_chip *chip, 
unsigned long *mask,
unsigned long *bits)
 {
struct idi_48_gpio *const idi48gpio = gpiochip_get_data(chip);
-   size_t i;
+   unsigned int offset;
+   unsigned long gpio_mask;
static const size_t ports[] = { 0, 1, 2, 4, 5, 6 };
-   const unsigned int gpio_reg_size = 8;
-   unsigned int bits_offset;
-   size_t word_index;
-   unsigned int word_offset;
-   unsigned long word_mask;
-   const unsigned long port_mask = GENMASK(gpio_reg_size - 1, 0);
+   unsigned int port_addr;
unsigned long port_state;
 
/* clear bits array to a clean slate */
bitmap_zero(bits, chip->ngpio);
 
-   /* get bits are evaluated a gpio port register at a time */
-   for (i = 0; i < ARRAY_SIZE(ports); i++) {
-   /* gpio offset in bits array */
-   bits_offset = i * gpio_reg_size;
+   for_each_set_clump8(offset, gpio_mask, mask, ARRAY_SIZE(ports) * 8) {
+   port_addr = idi48gpio->base + ports[offset / 8];
+   port_state = inb(port_addr) & gpio_mask;
 
-   /* word index for bits array */
-   word_index = BIT_WORD(bits_offset);
-
-   /* gpio offset within current word of bits array */
-   word_offset = bits_offset % BITS_PER_LONG;
-
-   /* mask of get bits for current gpio within current word */
-   word_mask = mask[word_index] & (port_mask << word_offset);
-   if (!word_mask) {
-   /* no get bits in this port so skip to next one */
-   continue;
-   }
-
-   /* read bits from current gpio port */
-   port_state = inb(idi48gpio->base + ports[i]);
-
-   /* store acquired bits at respective bits array offset */
-   bits[word_index] |= (port_state << word_offset) & word_mask;
+   bitmap_set_value8(bits, _state, offset);
}
 
return 0;
-- 
2.20.1



[PATCH v6 2/8] lib/test_bitmap.c: Add for_each_set_clump8 test cases

2018-12-18 Thread William Breathitt Gray
The introduction of the for_each_set_clump8 macro warrants test cases to
verify the implementation. This patch adds test case checks for whether
an out-of-bounds clump index is returned, a zero clump is returned, or
the returned clump value differs from the expected clump value.

Cc: Andy Shevchenko 
Cc: Andrew Morton 
Cc: Rasmus Villemoes 
Signed-off-by: William Breathitt Gray 
---
 lib/test_bitmap.c | 65 +++
 1 file changed, 65 insertions(+)

diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index 6cd7d0740005..66ddb3fb98cb 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -88,6 +88,36 @@ __check_eq_u32_array(const char *srcfile, unsigned int line,
return true;
 }
 
+static bool __init __check_eq_clump8(const char *srcfile, unsigned int line,
+   const unsigned int offset,
+   const unsigned int size,
+   const unsigned char *const clump_exp,
+   const unsigned long *const clump)
+{
+   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 / 8];
+   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; \
@@ -104,6 +134,7 @@ __check_eq_u32_array(const char *srcfile, unsigned int line,
 #define expect_eq_bitmap(...)  __expect_eq(bitmap, ##__VA_ARGS__)
 #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__)
 
 static void __init test_zero_clear(void)
 {
@@ -361,6 +392,39 @@ static void noinline __init test_mem_optimisations(void)
}
 }
 
+static const unsigned char clump_exp[] __initconst = {
+   0x01,   /* 1 bit set */
+   0x02,   /* non-edge 1 bit set */
+   0x00,   /* zero bits set */
+   0x28,   /* 3 bits set across 4-bit boundary */
+   0x28,   /* Repeated clump */
+   0x0F,   /* 4 bits set */
+   0xFF,   /* all bits set */
+   0x05,   /* non-adjacent 2 bits set */
+};
+
+static void __init test_for_each_set_clump8(void)
+{
+#define CLUMP_EXP_NUMBITS 64
+   DECLARE_BITMAP(bits, CLUMP_EXP_NUMBITS);
+   unsigned int start;
+   unsigned long clump;
+
+   /* set bitmap to test case */
+   bitmap_zero(bits, CLUMP_EXP_NUMBITS);
+   bitmap_set(bits, 0, 1); /* 0x01 */
+   bitmap_set(bits, 8, 1); /* 0x02 */
+   bitmap_set(bits, 27, 3);/* 0x28 */
+   bitmap_set(bits, 35, 3);/* 0x28 */
+   bitmap_set(bits, 40, 4);/* 0x0F */
+   bitmap_set(bits, 48, 8);/* 0xFF */
+   bitmap_set(bits, 56, 1);/* 0x05 - part 1 */
+   bitmap_set(bits, 58, 1);/* 0x05 - part 2 */
+
+   for_each_set_clump8(start, clump, bits, CLUMP_EXP_NUMBITS)
+   expect_eq_clump8(start, CLUMP_EXP_NUMBITS, clump_exp, );
+}
+
 static int __init test_bitmap_init(void)
 {
test_zero_clear();
@@ -369,6 +433,7 @@ static int __init test_bitmap_init(void)
test_bitmap_arr32();
test_bitmap_parselist();
test_mem_optimisations();
+   test_for_each_set_clump8();
 
if (failed_tests == 0)
pr_info("all %u tests passed\n", total_tests);
-- 
2.20.1



[PATCH v6 3/8] gpio: 104-dio-48e: Utilize for_each_set_clump8 macro

2018-12-18 Thread William Breathitt Gray
Replace verbose implementation in get_multiple/set_multiple callbacks
with for_each_set_clump8 macro to simplify code and improve clarity.

Signed-off-by: William Breathitt Gray 
---
 drivers/gpio/gpio-104-dio-48e.c | 71 ++---
 1 file changed, 20 insertions(+), 51 deletions(-)

diff --git a/drivers/gpio/gpio-104-dio-48e.c b/drivers/gpio/gpio-104-dio-48e.c
index 92c8f944bf64..b68c39f8aa23 100644
--- a/drivers/gpio/gpio-104-dio-48e.c
+++ b/drivers/gpio/gpio-104-dio-48e.c
@@ -183,46 +183,25 @@ static int dio48e_gpio_get(struct gpio_chip *chip, 
unsigned offset)
return !!(port_state & mask);
 }
 
+static const size_t ports[] = { 0, 1, 2, 4, 5, 6 };
+
 static int dio48e_gpio_get_multiple(struct gpio_chip *chip, unsigned long 
*mask,
unsigned long *bits)
 {
struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip);
-   size_t i;
-   static const size_t ports[] = { 0, 1, 2, 4, 5, 6 };
-   const unsigned int gpio_reg_size = 8;
-   unsigned int bits_offset;
-   size_t word_index;
-   unsigned int word_offset;
-   unsigned long word_mask;
-   const unsigned long port_mask = GENMASK(gpio_reg_size - 1, 0);
+   unsigned int offset;
+   unsigned long gpio_mask;
+   unsigned int port_addr;
unsigned long port_state;
 
/* clear bits array to a clean slate */
bitmap_zero(bits, chip->ngpio);
 
-   /* get bits are evaluated a gpio port register at a time */
-   for (i = 0; i < ARRAY_SIZE(ports); i++) {
-   /* gpio offset in bits array */
-   bits_offset = i * gpio_reg_size;
-
-   /* word index for bits array */
-   word_index = BIT_WORD(bits_offset);
-
-   /* gpio offset within current word of bits array */
-   word_offset = bits_offset % BITS_PER_LONG;
-
-   /* mask of get bits for current gpio within current word */
-   word_mask = mask[word_index] & (port_mask << word_offset);
-   if (!word_mask) {
-   /* no get bits in this port so skip to next one */
-   continue;
-   }
-
-   /* read bits from current gpio port */
-   port_state = inb(dio48egpio->base + ports[i]);
+   for_each_set_clump8(offset, gpio_mask, mask, ARRAY_SIZE(ports) * 8) {
+   port_addr = dio48egpio->base + ports[offset / 8];
+   port_state = inb(port_addr) & gpio_mask;
 
-   /* store acquired bits at respective bits array offset */
-   bits[word_index] |= (port_state << word_offset) & word_mask;
+   bitmap_set_value8(bits, _state, offset);
}
 
return 0;
@@ -252,37 +231,27 @@ static void dio48e_gpio_set_multiple(struct gpio_chip 
*chip,
unsigned long *mask, unsigned long *bits)
 {
struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip);
-   unsigned int i;
-   const unsigned int gpio_reg_size = 8;
-   unsigned int port;
-   unsigned int out_port;
+   unsigned int offset;
+   unsigned long gpio_mask;
+   size_t index;
+   unsigned int port_addr;
unsigned int bitmask;
unsigned long flags;
 
-   /* set bits are evaluated a gpio register size at a time */
-   for (i = 0; i < chip->ngpio; i += gpio_reg_size) {
-   /* no more set bits in this mask word; skip to the next word */
-   if (!mask[BIT_WORD(i)]) {
-   i = (BIT_WORD(i) + 1) * BITS_PER_LONG - gpio_reg_size;
-   continue;
-   }
+   for_each_set_clump8(offset, gpio_mask, mask, ARRAY_SIZE(ports) * 8) {
+   index = offset / 8;
+   port_addr = dio48egpio->base + ports[index];
 
-   port = i / gpio_reg_size;
-   out_port = (port > 2) ? port + 1 : port;
-   bitmask = mask[BIT_WORD(i)] & bits[BIT_WORD(i)];
+   bitmask = bitmap_get_value8(bits, offset) & gpio_mask;
 
raw_spin_lock_irqsave(>lock, flags);
 
/* update output state data and set device gpio register */
-   dio48egpio->out_state[port] &= ~mask[BIT_WORD(i)];
-   dio48egpio->out_state[port] |= bitmask;
-   outb(dio48egpio->out_state[port], dio48egpio->base + out_port);
+   dio48egpio->out_state[index] &= ~gpio_mask;
+   dio48egpio->out_state[index] |= bitmask;
+   outb(dio48egpio->out_state[index], port_addr);
 
raw_spin_unlock_irqrestore(>lock, flags);
-
-   /* prepare for next gpio register set */
-   mask[BIT_WORD(i)] >>= gpio_reg_size;
-   bits[BIT_WORD(i)] >>= gpio_reg_size;
}
 }
 
-- 
2.20.1



Re: [PATCH] xen/netfront: tolerate frags with no data

2018-12-18 Thread David Miller
From: Juergen Gross 
Date: Tue, 18 Dec 2018 16:06:19 +0100

> At least old Xen net backends seem to send frags with no real data
> sometimes. In case such a fragment happens to occur with the frag limit
> already reached the frontend will BUG currently even if this situation
> is easily recoverable.
> 
> Modify the BUG_ON() condition accordingly.
> 
> Tested-by: Dietmar Hahn 
> Signed-off-by: Juergen Gross 

Applied and queued up for -stable.

But many of these BUG's in the driver should be converted to
WARNs and recovery code added.


[PATCH v6 1/8] bitops: Introduce the for_each_set_clump8 macro

2018-12-18 Thread William Breathitt Gray
This macro iterates for each 8-bit 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_value8 and bitmap_set_value8 functions are introduced to
respectively get and set an 8-bit value in a bitmap memory region.

Suggested-by: Andy Shevchenko 
Suggested-by: Rasmus Villemoes 
Cc: Arnd Bergmann 
Cc: Andrew Morton 
Signed-off-by: William Breathitt Gray 
---
 include/asm-generic/bitops/find.h | 14 +++
 include/linux/bitops.h|  5 +++
 lib/find_bit.c| 63 +++
 3 files changed, 82 insertions(+)

diff --git a/include/asm-generic/bitops/find.h 
b/include/asm-generic/bitops/find.h
index 8a1ee10014de..457b93e6f5c9 100644
--- a/include/asm-generic/bitops/find.h
+++ b/include/asm-generic/bitops/find.h
@@ -80,4 +80,18 @@ extern unsigned long find_first_zero_bit(const unsigned long 
*addr,
 
 #endif /* CONFIG_GENERIC_FIND_FIRST_BIT */
 
+unsigned int bitmap_get_value8(const unsigned long *const bitmap,
+  const unsigned int start);
+
+void bitmap_set_value8(unsigned long *const bitmap,
+  const unsigned long *const value,
+  const unsigned int start);
+
+unsigned int find_next_clump8(unsigned long *const clump,
+ const unsigned long *const addr,
+ unsigned int offset, const unsigned int size);
+
+#define find_first_clump8(clump, bits, size) \
+   find_next_clump8((clump), (bits), 0, (size))
+
 #endif /*_ASM_GENERIC_BITOPS_FIND_H_ */
diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index 705f7c442691..61c10f20079e 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -40,6 +40,11 @@ extern unsigned long __sw_hweight64(__u64 w);
 (bit) < (size);\
 (bit) = find_next_zero_bit((addr), (size), (bit) + 1))
 
+#define for_each_set_clump8(start, clump, bits, size) \
+   for ((start) = find_first_clump8(&(clump), (bits), (size)); \
+(start) < (size); \
+(start) = find_next_clump8(&(clump), (bits), (start) + 8, (size)))
+
 static inline int get_bitmask_order(unsigned int count)
 {
int order;
diff --git a/lib/find_bit.c b/lib/find_bit.c
index ee3df93ba69a..2e56d2b907bc 100644
--- a/lib/find_bit.c
+++ b/lib/find_bit.c
@@ -218,3 +218,66 @@ EXPORT_SYMBOL(find_next_bit_le);
 #endif
 
 #endif /* __BIG_ENDIAN */
+
+/**
+ * bitmap_get_value8 - get an 8-bit value within a memory region
+ * @bitmap: address to the bitmap memory region
+ * @start: bit offset of the 8-bit value
+ *
+ * Returns the 8-bit value located at the @start bit offset within the @bitmap
+ * memory region.
+ */
+unsigned int bitmap_get_value8(const unsigned long *const bitmap,
+  const unsigned int start)
+{
+   const size_t index = BIT_WORD(start);
+   const unsigned int offset = start % BITS_PER_LONG;
+
+   return (bitmap[index] >> offset) & 0xFF;
+}
+EXPORT_SYMBOL(bitmap_get_value8);
+
+/**
+ * bitmap_set_value8 - set an 8-bit value within a memory region
+ * @bitmap: address to the bitmap memory region
+ * @value: the 8-bit value
+ * @start: bit offset of the 8-bit value
+ */
+void bitmap_set_value8(unsigned long *const bitmap,
+  const unsigned long *const value,
+  const unsigned int start)
+{
+   const size_t index = BIT_WORD(start);
+   const unsigned int offset = start % BITS_PER_LONG;
+   const unsigned long mask = GENMASK(7, offset);
+
+   bitmap[index] &= ~mask;
+   bitmap[index] |= (*value << offset) & mask;
+}
+EXPORT_SYMBOL(bitmap_set_value8);
+
+/**
+ * find_next_clump8 - find next 8-bit clump with set bits in a memory region
+ * @clump: location to store copy of found clump
+ * @addr: address to base the search on
+ * @offset: bit offset at which to start searching
+ * @size: bitmap size in number of 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.
+ */
+unsigned int find_next_clump8(unsigned long *const clump,
+ const unsigned long *const addr,
+ unsigned int offset, const unsigned int size)
+{
+   for (; offset < size; offset += 8) {
+   *clump = bitmap_get_value8(addr, offset);
+   if (!*clump)
+   continue;
+
+   return offset;
+   }
+
+   return size;
+}
+EXPORT_SYMBOL(find_next_clump8);
-- 
2.20.1



[PATCH v6 0/8] Introduce the for_each_set_clump8 macro

2018-12-18 Thread William Breathitt Gray
Changes in v6:
  - Fix typo in for_each_set_clump8 macro definition ('offset' should be
'start')
  - Fix data type mismatch for format specifier of warning print
statements in __check_eq_clump8
  - Fix typo in symbol suffix for definition of __check_eq_clump8
  - Fix typo in parameter passed to expect_eq_clump8 (missing '&' for
clump argument)

While adding GPIO get_multiple/set_multiple callback support for various
drivers, I noticed a pattern of looping manifesting that would be useful
standardized as a macro.

This patchset introduces the for_each_set_clump8 macro and utilizes it
in several GPIO drivers. The for_each_set_clump macro8 facilitates 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.

The for_each_set_clump8 macro has four parameters:

* start: set to the bit offset of the current clump
* clump: set to the current clump value
* bits: bitmap to search within
* size: bitmap size in number of bits

In this version of the patchset, the for_each_set_clump macro has been
reimplemented and simplified based on the suggestions provided by Rasmus
Villemoes and Andy Shevchenko in the version 4 submission.

In particular, the function of the for_each_set_clump macro has been
restricted to handle only 8-bit clumps; the drivers that use the
for_each_set_clump macro only handle 8-bit ports so a generic
for_each_set_clump implementation is not necessary. Thus, a solution for
odd-sized clumps (e.g. 3-bit, 7-bit, etc.) mismatching word boundaries
can be postponed until a driver appears that actually requires a generic
for_each_set_clump implementation.

In addition, the bitmap_get_value8 and bitmap_set_value8 functions are
introduced to get and set 8-bit values respectively. Their use is based
on the behavior suggested in the patchset version 4 review. Similarly,
the implementation of the find_next_clump function has been simplified
in order for the function to match the syntax and use of the
find_next_bit function.

William Breathitt Gray (8):
  bitops: Introduce the for_each_set_clump8 macro
  lib/test_bitmap.c: Add for_each_set_clump8 test cases
  gpio: 104-dio-48e: Utilize for_each_set_clump8 macro
  gpio: 104-idi-48: Utilize for_each_set_clump8 macro
  gpio: gpio-mm: Utilize for_each_set_clump8 macro
  gpio: ws16c48: Utilize for_each_set_clump8 macro
  gpio: pci-idio-16: Utilize for_each_set_clump8 macro
  gpio: pcie-idio-24: Utilize for_each_set_clump8 macro

 drivers/gpio/gpio-104-dio-48e.c   |  71 ++-
 drivers/gpio/gpio-104-idi-48.c|  36 ++
 drivers/gpio/gpio-gpio-mm.c   |  71 ++-
 drivers/gpio/gpio-pci-idio-16.c   |  73 +++-
 drivers/gpio/gpio-pcie-idio-24.c  | 109 +++---
 drivers/gpio/gpio-ws16c48.c   |  71 ++-
 include/asm-generic/bitops/find.h |  14 
 include/linux/bitops.h|   5 ++
 lib/find_bit.c|  63 +
 lib/test_bitmap.c |  65 ++
 10 files changed, 279 insertions(+), 299 deletions(-)

-- 
2.20.1



Re: [PATCH v5 19/25] xtensa: define syscall_get_* functions

2018-12-18 Thread kbuild test robot
Hi Dmitry,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v4.20-rc7]
[cannot apply to next-20181218]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Dmitry-V-Levin/ptrace-add-PTRACE_GET_SYSCALL_INFO-request/20181210-174745
config: xtensa-iss_defconfig (attached as .config)
compiler: xtensa-linux-gcc (GCC) 8.1.0
reproduce:
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=8.1.0 make.cross ARCH=xtensa 

All errors (new ones prefixed by >>):

   ^~
   include/linux/signal.h:122:20: note: in definition of macro '_SIG_SET_BINOP'
static inline void name(sigset_t *r, const sigset_t *a, const sigset_t *b) \
   ^~~~
   include/linux/signal.h:153:16: error: invalid storage class for function 
'sigandnsets'
_SIG_SET_BINOP(sigandnsets, _sig_andn)
   ^~~
   include/linux/signal.h:122:20: note: in definition of macro '_SIG_SET_BINOP'
static inline void name(sigset_t *r, const sigset_t *a, const sigset_t *b) \
   ^~~~
   include/linux/signal.h:177:13: error: invalid storage class for function 
'signotset'
_SIG_SET_OP(signotset, _sig_not)
^
   include/linux/signal.h:161:20: note: in definition of macro '_SIG_SET_OP'
static inline void name(sigset_t *set) \
   ^~~~
   include/linux/signal.h:182:20: error: invalid storage class for function 
'sigemptyset'
static inline void sigemptyset(sigset_t *set)
   ^~~
   include/linux/signal.h:195:20: error: invalid storage class for function 
'sigfillset'
static inline void sigfillset(sigset_t *set)
   ^~
   include/linux/signal.h:210:20: error: invalid storage class for function 
'sigaddsetmask'
static inline void sigaddsetmask(sigset_t *set, unsigned long mask)
   ^
   include/linux/signal.h:215:20: error: invalid storage class for function 
'sigdelsetmask'
static inline void sigdelsetmask(sigset_t *set, unsigned long mask)
   ^
   include/linux/signal.h:220:19: error: invalid storage class for function 
'sigtestsetmask'
static inline int sigtestsetmask(sigset_t *set, unsigned long mask)
  ^~
   include/linux/signal.h:225:20: error: invalid storage class for function 
'siginitset'
static inline void siginitset(sigset_t *set, unsigned long mask)
   ^~
   include/linux/signal.h:237:20: error: invalid storage class for function 
'siginitsetinv'
static inline void siginitsetinv(sigset_t *set, unsigned long mask)
   ^
   include/linux/signal.h:251:20: error: invalid storage class for function 
'init_sigpending'
static inline void init_sigpending(struct sigpending *sig)
   ^~~
   include/linux/signal.h:260:19: error: invalid storage class for function 
'valid_signal'
static inline int valid_signal(unsigned long sig)
  ^~~~
   include/linux/signal.h:285:20: error: invalid storage class for function 
'allow_signal'
static inline void allow_signal(int sig)
   ^~~~
   include/linux/signal.h:295:20: error: invalid storage class for function 
'disallow_signal'
static inline void disallow_signal(int sig)
   ^~~
   In file included from include/linux/key.h:22,
from include/linux/syscalls.h:83,
from arch/xtensa/kernel/syscall.c:24:
   include/linux/sysctl.h:100:21: error: invalid storage class for function 
'proc_sys_poll_event'
static inline void *proc_sys_poll_event(struct ctl_table_poll *poll)
^~~
   In file included from include/linux/static_key.h:1,
from include/linux/tracepoint-defs.h:12,
from include/linux/tracepoint.h:23,
from include/trace/syscall.h:5,
from include/linux/syscalls.h:85,
from arch/xtensa/kernel/syscall.c:24:
   include/linux/jump_label.h:253:19: error: invalid storage class for function 
'static_key_count'
static inline int static_key_count(struct static_key *key)
  ^~~~
   include/linux/jump_label.h:258:29: error: invalid storage class for function 
'jump_label_init'
static __always_inline void jump_label_init(void)
^~~
   include/linux/jump_label.h:263:29: error: invalid storage class for function 
'static_key_false'
static __always_inlin

Re: [RFC PATCH 1/2] mm: swap: check if swap backing device is congested or not

2018-12-18 Thread Yang Shi




On 12/18/18 4:16 PM, Tim Chen wrote:

On 12/18/18 3:43 PM, Yang Shi wrote:


On 12/18/18 11:29 AM, Tim Chen wrote:

On 12/17/18 10:52 PM, Yang Shi wrote:


diff --git a/mm/swap_state.c b/mm/swap_state.c
index fd2f21e..7cc3c29 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -538,11 +538,15 @@ struct page *swap_cluster_readahead(swp_entry_t entry, 
gfp_t gfp_mask,
   bool do_poll = true, page_allocated;
   struct vm_area_struct *vma = vmf->vma;
   unsigned long addr = vmf->address;
+    struct inode *inode = si->swap_file->f_mapping->host;
     mask = swapin_nr_pages(offset) - 1;
   if (!mask)
   goto skip;
   

Shmem will also be using this function and I don't think the 
inode_read_congested
logic is relevant for that case.

IMHO, shmem is also relevant. As long as it is trying to readahead from swap, 
it should check if the underlying device is busy or not regardless of shmem or 
anon page.


I don't think your dereference inode = si->swap_file->f_mapping->host
is always safe.  You should do it only when (si->flags & SWP_FS) is true.


Do you mean it is not safe for swap partition?

I tested with swap partition too. It looks fine. Opening block device 
also gets inode.


Filename    Type    Size Used    
Priority

/dev/sdb1   partition 20970492    850168  -2

Thanks,
Yang



Tim




Re: hard-coded limit on unresolved multicast route cache in ipv4/ipmr.c causes slow, unreliable creation of multicast routes on busy networks

2018-12-18 Thread David Miller
From: Sukumar Gopalakrishnan 
Date: Wed, 19 Dec 2018 10:57:02 +0530

> Hi David,
> 
>   There are two patch for this issue:
>1) Your changes which removes cache_resolve_queue_len
> 2) Hangbin's changes which make cache_resolve_queue_len configurable.
> 
> Which one will be chosen for this issue ?

I do plan to look into this, sorry for taking so long.

Right now I am overwhelmed preparing for the next merge window and
synchronizing with other developers for that.

Please be patient.


Re: [PATCH net-next] MAINTAINERS: Add a maintainer for Microsemi switches

2018-12-18 Thread David Miller
From: Alexandre Belloni 
Date: Tue, 18 Dec 2018 15:25:39 +0100

> Microsemi has been bought by Microchip and Microchip is supporting those
> switches.
> 
> Signed-off-by: Alexandre Belloni 

Applied.


Re: [PATCH net] net: phy: Fix the issue that netif always links up after resuming

2018-12-18 Thread David Miller
From: Kunihiko Hayashi 
Date: Tue, 18 Dec 2018 16:57:04 +0900

> Even though the link is down before entering hibernation,
> there is an issue that the network interface always links up after resuming
> from hibernation.
> 
> If the link is still down before enabling the network interface,
> and after resuming from hibernation, the phydev->state is forcibly set
> to PHY_UP in mdio_bus_phy_restore(), and the link becomes up.
> 
> In suspend sequence, only if the PHY is attached, mdio_bus_phy_suspend()
> calls phy_stop_machine(), and mdio_bus_phy_resume() calls
> phy_start_machine().
> In resume sequence, it's enough to do the same as mdio_bus_phy_resume()
> because the state has been preserved.
> 
> This patch fixes the issue by calling phy_start_machine() in
> mdio_bus_phy_restore() in the same way as mdio_bus_phy_resume().
> 
> Suggested-by: Heiner Kallweit 
> Signed-off-by: Kunihiko Hayashi 

Applied and queued up for -stable.


Re: [PATCH v2] include/linux/nodemask.h: Use nr_node_ids (not MAX_NUMNODES) in __nodemask_pr_numnodes()

2018-12-18 Thread kbuild test robot
Hi Waiman,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v4.20-rc7 next-20181218]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Waiman-Long/include-linux-nodemask-h-Use-nr_node_ids-not-MAX_NUMNODES-in-__nodemask_pr_numnodes/20181219-110121
config: arm-omap2plus_defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.2.0 make.cross ARCH=arm 

All errors (new ones prefixed by >>):

   kernel/cgroup/cpuset.o: In function `cpuset_common_seq_show':
>> cpuset.c:(.text+0xe2c): undefined reference to `nr_node_ids'
   kernel/cgroup/cpuset.o: In function `cpuset_print_current_mems_allowed':
   cpuset.c:(.text+0x4624): undefined reference to `nr_node_ids'
   kernel/cgroup/cpuset.o: In function `cpuset_task_status_allowed':
   cpuset.c:(.text+0x4d5c): undefined reference to `nr_node_ids'
   mm/oom_kill.o: In function `dump_header':
   oom_kill.c:(.text.unlikely+0x3c4): undefined reference to `nr_node_ids'
   mm/page_alloc.o: In function `warn_alloc':
   page_alloc.c:(.text+0x4ae0): undefined reference to `nr_node_ids'

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


Re: [PATCH v12 2/2] cpufreq: qcom-hw: Add support for QCOM cpufreq HW driver

2018-12-18 Thread Viresh Kumar
On 18-12-18, 11:13, Stephen Boyd wrote:
> I don't see any failure returned from cpufreq_dt's cpufreq_init()
> function. Maybe put a static int counter = 0 and then fail
> cpufreq_init() the second time that it's called for the same policy
> pointer? I have a system with two policies, so I made it fail and return
> -EINVAL when the counter == 2 and I see the lockdep splat.

Yuck. You were so clear on this earlier, how can I forget it. :(

Here is the additional diff. And I do get this print message on my screen while
I try to online CPU4.

diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c
index 639feca22d27..b836e93fd87d 100644
--- a/drivers/cpufreq/cpufreq-dt.c
+++ b/drivers/cpufreq/cpufreq-dt.c
@@ -151,6 +151,11 @@ static int cpufreq_init(struct cpufreq_policy *policy)
const char *name;
int ret;
 
+   if (policy->count++) {
+   pr_info("%s: %d\n", __func__, __LINE__);
+   return -EINVAL;
+   }
+
cpu_dev = get_cpu_device(policy->cpu);
if (!cpu_dev) {
pr_err("failed to get cpu%d device\n", policy->cpu);
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index 882a9b9e34bc..643141a2013f 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -151,6 +151,7 @@ struct cpufreq_policy {
 
/* For cpufreq driver's internal use */
void*driver_data;
+   int count;
 };

> I did the following:
> 
>   grep . /sys/devices/system/cpu/cpufreq/*/* >/dev/null
>   echo 0 > /sys/devices/system/cpu/cpu4/online 
>   echo 0 > /sys/devices/system/cpu/cpu5/online 
>   echo 0 > /sys/devices/system/cpu/cpu6/online 
>   echo 0 > /sys/devices/system/cpu/cpu7/online 
>   echo 1 > /sys/devices/system/cpu/cpu4/online 
>   dmesg
> 
> And boom, lockdep splat.

  502  grep . /sys/devices/system/cpu/cpufreq/*/*
  503  echo 0 > /sys/devices/system/cpu/cpu4/online
  504  echo 0 > /sys/devices/system/cpu/cpu5/online
  505  echo 0 > /sys/devices/system/cpu/cpu6/online
  506  echo 0 > /sys/devices/system/cpu/cpu7/online
  507  grep . /sys/devices/system/cpu/cpufreq/*/*
  508  echo 1 > /sys/devices/system/cpu/cpu4/online
  509  dmesg 


But still no lockdep :(

Can you try that on mainline as well ?

-- 
viresh


Re: [v2, PATCH 0/2] add ethernet binding and modify ethernet driver for mt2712

2018-12-18 Thread David Miller
From: Biao Huang 
Date: Tue, 18 Dec 2018 13:48:14 +0800

> changes in v2 as comments from Sean:
> 1. fix typo.
> 2. use capital letters for RMII/MII/RGMII in driver and bindings.
> 
> v1:
> This new series is the result of discussion in:
> http://lkml.org/lkml/2018/12/13/1007
> http://lkml.org/lkml/2018/12/14/53
> 
> 1. ethernet binding file move to this series.
> 2. remove fine tune property in device tree
> 3. remove fine tune flow in ethernet driver
> 4. set rgmii timing according to the value in device tree,
> and don't care whether phy insert internal delay  or not.

This series doesn't apply cleanly to the net-next tree.


[PATCH] ARM: dts: imx6sl: correct PWM ipg clock source

2018-12-18 Thread Anson Huang
>From i.MX6SL Reference Manual, the PWMx's ipg clock
for registers access is from perclk, correct them.

Signed-off-by: Anson Huang 
---
 arch/arm/boot/dts/imx6sl.dtsi | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/arm/boot/dts/imx6sl.dtsi b/arch/arm/boot/dts/imx6sl.dtsi
index e7524e7..4b4813f 100644
--- a/arch/arm/boot/dts/imx6sl.dtsi
+++ b/arch/arm/boot/dts/imx6sl.dtsi
@@ -338,7 +338,7 @@
compatible = "fsl,imx6sl-pwm", "fsl,imx27-pwm";
reg = <0x0208 0x4000>;
interrupts = <0 83 IRQ_TYPE_LEVEL_HIGH>;
-   clocks = < IMX6SL_CLK_PWM1>,
+   clocks = < IMX6SL_CLK_PERCLK>,
 < IMX6SL_CLK_PWM1>;
clock-names = "ipg", "per";
};
@@ -348,7 +348,7 @@
compatible = "fsl,imx6sl-pwm", "fsl,imx27-pwm";
reg = <0x02084000 0x4000>;
interrupts = <0 84 IRQ_TYPE_LEVEL_HIGH>;
-   clocks = < IMX6SL_CLK_PWM2>,
+   clocks = < IMX6SL_CLK_PERCLK>,
 < IMX6SL_CLK_PWM2>;
clock-names = "ipg", "per";
};
@@ -358,7 +358,7 @@
compatible = "fsl,imx6sl-pwm", "fsl,imx27-pwm";
reg = <0x02088000 0x4000>;
interrupts = <0 85 IRQ_TYPE_LEVEL_HIGH>;
-   clocks = < IMX6SL_CLK_PWM3>,
+   clocks = < IMX6SL_CLK_PERCLK>,
 < IMX6SL_CLK_PWM3>;
clock-names = "ipg", "per";
};
@@ -368,7 +368,7 @@
compatible = "fsl,imx6sl-pwm", "fsl,imx27-pwm";
reg = <0x0208c000 0x4000>;
interrupts = <0 86 IRQ_TYPE_LEVEL_HIGH>;
-   clocks = < IMX6SL_CLK_PWM4>,
+   clocks = < IMX6SL_CLK_PERCLK>,
 < IMX6SL_CLK_PWM4>;
clock-names = "ipg", "per";
};
-- 
2.7.4



Re: linux-next: build warning after merge of the net-next tree

2018-12-18 Thread Stephen Rothwell
Hi Gustavo,

On Tue, 18 Dec 2018 21:07:06 -0600 "Gustavo A. R. Silva" 
 wrote:
>
> On 12/18/18 8:42 PM, Stephen Rothwell wrote:
> > Hi all,
> > 
> > On Thu, 29 Nov 2018 11:24:28 +1100 Stephen Rothwell  
> > wrote:  
> >>
> >> After merging the net-next tree, today's linux-next build
> >> (x86_64_allmodconfig) produced this warning:
> >>
> >> drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c: In function 'run_xdp':
> >> drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c:324:3: warning: this 
> >> statement may fall through [-Wimplicit-fallthrough=]
> >> bpf_warn_invalid_xdp_action(xdp_act);
> >> ^~~~
> >> drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c:325:2: note: here
> >>case XDP_ABORTED:
> >>^~~~
> >> drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c:326:3: warning: this 
> >> statement may fall through [-Wimplicit-fallthrough=]
> >> trace_xdp_exception(priv->net_dev, xdp_prog, xdp_act);
> >> ^
> >> drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c:327:2: note: here
> >>case XDP_DROP:
> >>^~~~
> >>
> >> Introduced by commit
> >>
> >>7e273a8ebdd3 ("dpaa2-eth: Add basic XDP support")
> >>
> >> This due to my use of -Wimplicit-fallthrough.  This is new code.  The
> >> warning can be suppressed by adding a comment like /* fall through */
> >> at the appropriate places to indicate that the fallthrough is intended.  
> > 
> > I am still seeing these warnings.
> >   
> 
> That's weird. I don't see them anymore in next-20181218.
> 
> They were fixed by this commit: c1cb11bcbd09f5f027cbc7fadddab169714948df

My mistake (patter mismatch :-)), there are very similar warnings in
drivers/net/veth.c which are older.  Someone could fix those if they
wanted to :-)

drivers/net/veth.c: In function 'veth_xdp_rcv_one':
drivers/net/veth.c:542:4: warning: this statement may fall through 
[-Wimplicit-fallthrough=]
bpf_warn_invalid_xdp_action(act);
^~~~
drivers/net/veth.c:543:3: note: here
   case XDP_ABORTED:
   ^~~~
drivers/net/veth.c: In function 'veth_xdp_rcv_skb':
drivers/net/veth.c:663:3: warning: this statement may fall through 
[-Wimplicit-fallthrough=]
   bpf_warn_invalid_xdp_action(act);
   ^~~~
drivers/net/veth.c:664:2: note: here
  case XDP_ABORTED:
  ^~~~

-- 
Cheers,
Stephen Rothwell


pgpJJCOcNdCuM.pgp
Description: OpenPGP digital signature


Re: [PATCH] lib/rhashtable: Fix work initialization in rhashtable_init()

2018-12-18 Thread David Miller
From: Bart Van Assche 
Date: Mon, 17 Dec 2018 13:40:58 -0800

> The test_insert_dup() function from lib/test_rhashtable.c passes a
> pointer to a stack object to rhltable_init(). Avoid that the following
> is reported with object debugging enabled while running the selftest
> from lib/test_rhashtable.c:
 ...
> Signed-off-by: Bart Van Assche 

Please just fix the test to use the global object created for this purpose
instead of an unnecessary on-stack instance.

Thanks.


Re: [PATCH 1/2] mm: introduce put_user_page*(), placeholder versions

2018-12-18 Thread Dan Williams
On Tue, Dec 18, 2018 at 7:03 PM Jason Gunthorpe  wrote:
>
> On Wed, Dec 19, 2018 at 10:42:54AM +1100, Dave Chinner wrote:
>
> > Essentially, what we are talking about is how to handle broken
> > hardware. I say we should just brun it with napalm and thermite
> > (i.e. taint the kernel with "unsupportable hardware") and force
> > wait_for_stable_page() to trigger when there are GUP mappings if
> > the underlying storage doesn't already require it.
>
> If you want to ban O_DIRECT/etc from writing to file backed pages,
> then just do it.
>
> Otherwise I'm not sure demanding some unrealistic HW design is
> reasonable. ie nvme drives are not likely to add page faulting to
> their IO path any time soon.
>
> A SW architecture that relies on page faulting is just not going to
> support real world block IO devices.
>
> GPUs and one RDMA are about the only things that can do this today,
> and they are basically irrelevant to O_DIRECT.

Yes.

I'm missing why a bounce buffer is needed. If writeback hits a
DMA-writable page why can't that path just turn around and trigger
another mkwrite notifcation on behalf of hardware that will never send
it? "Nice try writeback, this page is dirty again".


[PATCH] pwm: imx: add ipg clock operation

2018-12-18 Thread Anson Huang
i.MX PWM module's ipg_clk_s is for PWM register access, on
most of i.MX SoCs, this ipg_clk_s is from system ipg clock
or perclk which is always enabled, but on i.MX7D, the ipg_clk_s
is from PWM1_CLK_ROOT which is controlled by CCGR132, that means
the CCGR132 MUST be enabled first before accessing PWM registers
on i.MX7D. This patch adds ipg clock operation to make sure
register access successfully on i.MX7D and it fixes Linux kernel
boot up hang during PWM driver probe.

Fixes: 4a23e6ee9f69 ("ARM: dts: imx7d-sdb: Restore pwm backlight support")
Signed-off-by: Anson Huang 
---
 drivers/pwm/pwm-imx.c | 53 ++-
 1 file changed, 48 insertions(+), 5 deletions(-)

diff --git a/drivers/pwm/pwm-imx.c b/drivers/pwm/pwm-imx.c
index 6cd3b72..55a3a36 100644
--- a/drivers/pwm/pwm-imx.c
+++ b/drivers/pwm/pwm-imx.c
@@ -87,6 +87,8 @@
 #define MX3_PWMPR_MAX  0xfffe
 
 struct imx_chip {
+   struct clk  *clk_ipg;
+
struct clk  *clk_per;
 
void __iomem*mmio_base;
@@ -96,6 +98,32 @@ struct imx_chip {
 
 #define to_imx_chip(chip)  container_of(chip, struct imx_chip, chip)
 
+static int imx_pwm_clk_prepare_enable(struct pwm_chip *chip)
+{
+   struct imx_chip *imx = to_imx_chip(chip);
+   int ret;
+
+   ret = clk_prepare_enable(imx->clk_ipg);
+   if (ret)
+   return ret;
+
+   ret = clk_prepare_enable(imx->clk_per);
+   if (ret) {
+   clk_disable_unprepare(imx->clk_ipg);
+   return ret;
+   }
+
+   return 0;
+}
+
+static void imx_pwm_clk_disable_unprepare(struct pwm_chip *chip)
+{
+   struct imx_chip *imx = to_imx_chip(chip);
+
+   clk_disable_unprepare(imx->clk_per);
+   clk_disable_unprepare(imx->clk_ipg);
+}
+
 static void imx_pwm_get_state(struct pwm_chip *chip,
struct pwm_device *pwm, struct pwm_state *state)
 {
@@ -103,11 +131,15 @@ static void imx_pwm_get_state(struct pwm_chip *chip,
u32 period, prescaler, pwm_clk, ret, val;
u64 tmp;
 
+   ret = imx_pwm_clk_prepare_enable(chip);
+   if (ret < 0)
+   return;
+
val = readl(imx->mmio_base + MX3_PWMCR);
 
if (val & MX3_PWMCR_EN) {
state->enabled = true;
-   ret = clk_prepare_enable(imx->clk_per);
+   ret = imx_pwm_clk_prepare_enable(chip);
if (ret)
return;
} else {
@@ -143,6 +175,8 @@ static void imx_pwm_get_state(struct pwm_chip *chip,
} else {
state->duty_cycle = 0;
}
+
+   imx_pwm_clk_disable_unprepare(chip);
 }
 
 static int imx_pwm_config_v1(struct pwm_chip *chip,
@@ -180,7 +214,7 @@ static int imx_pwm_enable_v1(struct pwm_chip *chip, struct 
pwm_device *pwm)
u32 val;
int ret;
 
-   ret = clk_prepare_enable(imx->clk_per);
+   ret = imx_pwm_clk_prepare_enable(chip);
if (ret < 0)
return ret;
 
@@ -200,7 +234,7 @@ static void imx_pwm_disable_v1(struct pwm_chip *chip, 
struct pwm_device *pwm)
val &= ~MX1_PWMC_EN;
writel(val, imx->mmio_base + MX1_PWMC);
 
-   clk_disable_unprepare(imx->clk_per);
+   imx_pwm_clk_disable_unprepare(chip);
 }
 
 static void imx_pwm_sw_reset(struct pwm_chip *chip)
@@ -286,7 +320,7 @@ static int imx_pwm_apply_v2(struct pwm_chip *chip, struct 
pwm_device *pwm,
if (cstate.enabled) {
imx_pwm_wait_fifo_slot(chip, pwm);
} else {
-   ret = clk_prepare_enable(imx->clk_per);
+   ret = imx_pwm_clk_prepare_enable(chip);
if (ret)
return ret;
 
@@ -309,7 +343,7 @@ static int imx_pwm_apply_v2(struct pwm_chip *chip, struct 
pwm_device *pwm,
} else if (cstate.enabled) {
writel(0, imx->mmio_base + MX3_PWMCR);
 
-   clk_disable_unprepare(imx->clk_per);
+   imx_pwm_clk_disable_unprepare(chip);
}
 
return 0;
@@ -367,6 +401,13 @@ static int imx_pwm_probe(struct platform_device *pdev)
if (imx == NULL)
return -ENOMEM;
 
+   imx->clk_ipg = devm_clk_get(>dev, "ipg");
+   if (IS_ERR(imx->clk_ipg)) {
+   dev_err(>dev, "getting ipg clock failed with %ld\n",
+   PTR_ERR(imx->clk_ipg));
+   return PTR_ERR(imx->clk_ipg);
+   }
+
imx->clk_per = devm_clk_get(>dev, "per");
if (IS_ERR(imx->clk_per)) {
dev_err(>dev, "getting per clock failed with %ld\n",
@@ -406,6 +447,8 @@ static int imx_pwm_remove(struct platform_device *pdev)
if (imx == NULL)
return -ENODEV;
 
+   imx_pwm_clk_disable_unprepare(>chip);
+
return pwmchip_remove(>chip);
 }
 
-- 
2.7.4



Re: [PATCH v17 18/23] platform/x86: Intel SGX driver

2018-12-18 Thread Jarkko Sakkinen
On Wed, Dec 19, 2018 at 06:47:32AM +0200, Jarkko Sakkinen wrote:
> On Tue, Dec 18, 2018 at 07:44:18AM -0800, Sean Christopherson wrote:
> > My fd/inode knowledge is lacking, to say the least.  Whatever works, so
> > long as we have a way to uniquely identify enclaves.
> 
> I will simply trial and error :-) I think it should work since it does
> own an address space, but yeah, testing will tell. We can go also with
> anon inode if required.

I think this can be concluded with the fact that it is nice to be able
to multiplex the dev fd. That is the key reason for using anon inode.
You KVM comment locks the decision here.

/Jarkko


Re: [PATCH v17 18/23] platform/x86: Intel SGX driver

2018-12-18 Thread Jarkko Sakkinen
On Mon, Dec 17, 2018 at 09:55:08PM -0800, Andy Lutomirski wrote:
> On Thu, Nov 15, 2018 at 5:08 PM Jarkko Sakkinen
>  wrote:
> >
> > Intel Software Guard eXtensions (SGX) is a set of CPU instructions that
> > can be used by applications to set aside private regions of code and
> > data. The code outside the enclave is disallowed to access the memory
> > inside the enclave by the CPU access control.
> 
> This is a very partial review.

Thank you, appreciate it.

> > +int sgx_encl_find(struct mm_struct *mm, unsigned long addr,
> > + struct vm_area_struct **vma)
> > +{
> > +   struct vm_area_struct *result;
> > +   struct sgx_encl *encl;
> > +
> > +   result = find_vma(mm, addr);
> > +   if (!result || result->vm_ops != _vm_ops || addr < 
> > result->vm_start)
> > +   return -EINVAL;
> > +
> > +   encl = result->vm_private_data;
> > +   *vma = result;
> > +
> > +   return encl ? 0 : -ENOENT;
> > +}
> 
> I realize that this function may go away entirely but, if you keep it:
> what are the locking rules?  What, if anything, prevents another
> thread from destroying the enclave after sgx_encl_find() returns?

The kref inside the enclave is used to manage this but this function
directly does not prevent it (see for example sgx_encl_get). But yes,
this function does not give any guarantees (should probably have
a documentation stating this).

> > +static int sgx_validate_secs(const struct sgx_secs *secs,
> > +unsigned long ssaframesize)
> > +{
> 
> ...
> 
> > +   if (secs->attributes & SGX_ATTR_MODE64BIT) {
> > +   if (secs->size > sgx_encl_size_max_64)
> > +   return -EINVAL;
> > +   } else {
> > +   /* On 64-bit architecture allow 32-bit encls only in
> > +* the compatibility mode.
> > +*/
> > +   if (!test_thread_flag(TIF_ADDR32))
> > +   return -EINVAL;
> > +   if (secs->size > sgx_encl_size_max_32)
> > +   return -EINVAL;
> > +   }
> 
> Why do we need the 32-bit-on-64-bit check?  In general, anything that
> checks per-task or per-mm flags like TIF_ADDR32 is IMO likely to be
> problematic.  You're allowing 64-bit enclaves in 32-bit tasks, so I'm
> guessing you could just delete the check.

I guess you are right. I can remove this.


> 
> > +
> > +   if (!(secs->xfrm & XFEATURE_MASK_FP) ||
> > +   !(secs->xfrm & XFEATURE_MASK_SSE) ||
> > +   (((secs->xfrm >> XFEATURE_BNDREGS) & 1) !=
> > +((secs->xfrm >> XFEATURE_BNDCSR) & 1)) ||
> > +   (secs->xfrm & ~sgx_xfrm_mask))
> > +   return -EINVAL;
> 
> Do we need to check that the enclave doesn't use xfeatures that the
> kernel doesn't know about?  Or are they all safe by design in enclave
> mode?

Really good catch BTW. We don't check what kernel doesn't know about.

I'm not sure what harm this would have as the enclave cannot have much
effect to the outside world. Is there easy way to get similar mask
of kernel supported features as sgx_xfrm_mask? The safe play would
be to use such here as I don't have definitive answer to your second
question.

> 
> > +static int sgx_encl_pm_notifier(struct notifier_block *nb,
> > +   unsigned long action, void *data)
> > +{
> > +   struct sgx_encl *encl = container_of(nb, struct sgx_encl, 
> > pm_notifier);
> > +
> > +   if (action != PM_SUSPEND_PREPARE && action != 
> > PM_HIBERNATION_PREPARE)
> > +   return NOTIFY_DONE;
> 
> Hmm.  There's an argument to made that omitting this would better
> exercise the code that handles fully asynchronous loss of an enclave.
> Also, I think you're unnecessarily killing enclaves when suspend is
> attempted but fails.

Are you proposing to not do anything at all to the enclaves? There was
is a problem that it could lead to infinite #PF loop if we don't do
it.


> 
> > +
> > +static int sgx_get_key_hash(const void *modulus, void *hash)
> > +{
> > +   struct crypto_shash *tfm;
> > +   int ret;
> > +
> > +   tfm = crypto_alloc_shash("sha256", 0, CRYPTO_ALG_ASYNC);
> > +   if (IS_ERR(tfm))
> > +   return PTR_ERR(tfm);
> > +
> > +   ret = __sgx_get_key_hash(tfm, modulus, hash);
> > +
> > +   crypto_free_shash(tfm);
> > +   return ret;
> > +}
> > +
> 
> I'm so sorry you had to deal with this API.  Once Zinc lands, you
> could clean this up :)
> 
> 
> > +static int sgx_encl_get(unsigned long addr, struct sgx_encl **encl)
> > +{
> > +   struct mm_struct *mm = current->mm;
> > +   struct vm_area_struct *vma;
> > +   int ret;
> > +
> > +   if (addr & (PAGE_SIZE - 1))
> > +   return -EINVAL;
> > +
> > +   down_read(>mmap_sem);
> > +
> > +   ret = sgx_encl_find(mm, addr, );
> > +   if (!ret) {
> > +   *encl = vma->vm_private_data;
> > +
> > +   if ((*encl)->flags & 

Re: [PATCH v17 18/23] platform/x86: Intel SGX driver

2018-12-18 Thread Jarkko Sakkinen
On Wed, Dec 19, 2018 at 07:00:47AM +0200, Jarkko Sakkinen wrote:
> On Tue, Dec 18, 2018 at 10:53:49AM -0800, Sean Christopherson wrote:
> > What if we re-organize the ioctls in such a way that we leave open the
> > possibility of allocating raw EPC for KVM via /dev/sgx?  I'm not 100%
> > positive this approach will work[1], but conceptually it fits well with
> > KVM's memory model, e.g. KVM is aware of the GPA<->HVA association but
> > generally speaking doesn't know what's physically backing each memory
> > region.
> 
> Why would you want to pass EPC through user space to KVM rather than
> KVM allocating it through kernel interfaces?
> 
> > Tangentially related, I think we should support allocating multiple
> > enclaves from a single /dev/sgx fd, i.e. a process shouldn't have to
> > open /dev/sgx every time it wants to create a new enclave.
> 
> I'm fine with this. It just requires to create anon inode. I'll just
> add a new field called 'enclave_fd' to struct sgx_enclave_create and
> that's all.
> 
> I think I have otherwise ingredients for v19 ready except where to swap.

If I follow your proposal here and allow to create multiple enclaves
(i.e. with anon inodes for each) with one descriptor, is that sufficient
API to later add what you want to KVM?

/Jarkko


[PATCH] drivers/regulator: fix a missing check of return value

2018-12-18 Thread Kangjie Lu
If palmas_smps_read() fails, we should not use the read data in "reg"
which may contain random value. The fix inserts a check for the return
value of palmas_smps_read(): If it fails, we return the error code
upstream and stop using "reg".

Signed-off-by: Kangjie Lu 
---
 drivers/regulator/palmas-regulator.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/regulator/palmas-regulator.c 
b/drivers/regulator/palmas-regulator.c
index bb5ab7d78895..c2cc392a27d4 100644
--- a/drivers/regulator/palmas-regulator.c
+++ b/drivers/regulator/palmas-regulator.c
@@ -443,13 +443,16 @@ static int palmas_ldo_write(struct palmas *palmas, 
unsigned int reg,
 static int palmas_set_mode_smps(struct regulator_dev *dev, unsigned int mode)
 {
int id = rdev_get_id(dev);
+   int ret;
struct palmas_pmic *pmic = rdev_get_drvdata(dev);
struct palmas_pmic_driver_data *ddata = pmic->palmas->pmic_ddata;
struct palmas_regs_info *rinfo = >palmas_regs_info[id];
unsigned int reg;
bool rail_enable = true;
 
-   palmas_smps_read(pmic->palmas, rinfo->ctrl_addr, );
+   ret = palmas_smps_read(pmic->palmas, rinfo->ctrl_addr, );
+   if (ret)
+   return ret;
 
reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
 
-- 
2.17.2 (Apple Git-113)



Re: [RFC PATCH v5 0/5] x86: Add vDSO exception fixup for SGX

2018-12-18 Thread Jarkko Sakkinen
On Wed, Dec 19, 2018 at 06:43:46AM +0200, Jarkko Sakkinen wrote:
> On Tue, Dec 18, 2018 at 07:08:15AM -0800, Sean Christopherson wrote:
> > On Tue, Dec 18, 2018 at 06:18:15AM +0200, Jarkko Sakkinen wrote:
> > > On Fri, Dec 14, 2018 at 01:57:24PM -0800, Sean Christopherson wrote:
> > > > __vdso_sgx_enter_enclave() gets another rewrite, this time to strip
> > > > it down to the bare minimum and explicitly break compliance with the
> > > > x86-64 ABI.  Feedback from v4 revealed that __vdso_sgx_enter_enclave()
> > > > would need to save (a lot) more than just the non-volatile GPRs to be
> > > > compliant with the x86-64 ABI, at which point breaking from the ABI
> > > > completely became much more palatable.
> > > > 
> > > > The non-standard ABI also solves the question of "which GPRs should be
> > > > marshalled to/from the enclave" by getting out of the way entirely and
> > > > letting userspace have free reign (except for RSP, which has a big ol'
> > > > DO NOT TOUCH sign on it).
> > > 
> > > Can you share a reference, or is this better documented in the
> > > accompanied patches?
> > 
> > Patch 5/5 has more details, and v4 of the series has a lot of background
> > info by way of discussion:
> > 
> > https://lkml.kernel.org/r/20181213213135.12913-1-sean.j.christopher...@intel.com
> 
> Thanks Sean, I will. Have not had yet much time to look at this.

Might make sense to summarize the design decisions for future
patch set versions to the cover letter at least, namely the
reasoning why not to follow the ABI.

/Jarkko


Re: [PATCH v17 18/23] platform/x86: Intel SGX driver

2018-12-18 Thread Jarkko Sakkinen
On Tue, Dec 18, 2018 at 10:53:49AM -0800, Sean Christopherson wrote:
> What if we re-organize the ioctls in such a way that we leave open the
> possibility of allocating raw EPC for KVM via /dev/sgx?  I'm not 100%
> positive this approach will work[1], but conceptually it fits well with
> KVM's memory model, e.g. KVM is aware of the GPA<->HVA association but
> generally speaking doesn't know what's physically backing each memory
> region.

Why would you want to pass EPC through user space to KVM rather than
KVM allocating it through kernel interfaces?

> Tangentially related, I think we should support allocating multiple
> enclaves from a single /dev/sgx fd, i.e. a process shouldn't have to
> open /dev/sgx every time it wants to create a new enclave.

I'm fine with this. It just requires to create anon inode. I'll just
add a new field called 'enclave_fd' to struct sgx_enclave_create and
that's all.

I think I have otherwise ingredients for v19 ready except where to swap.

/Jarkko


Re: [PATCH v17 18/23] platform/x86: Intel SGX driver

2018-12-18 Thread Jarkko Sakkinen
On Tue, Dec 18, 2018 at 07:44:18AM -0800, Sean Christopherson wrote:
> My fd/inode knowledge is lacking, to say the least.  Whatever works, so
> long as we have a way to uniquely identify enclaves.

I will simply trial and error :-) I think it should work since it does
own an address space, but yeah, testing will tell. We can go also with
anon inode if required.

/Jarkko


[v5] PCI: imx: make msi work without CONFIG_PCIEPORTBUS=y

2018-12-18 Thread Richard Zhu
Assertion of the MSI Enable bit of RC's MSI CAP is mandatory required to
trigger MSI on i.MX6 PCIe.
This bit would be asserted when CONFIG_PCIEPORTBUS=y.
Thus, the MSI works fine on i.MX6 PCIe before the commit "f3fdfc4".

Assert it unconditionally when MSI is enabled.
Otherwise, the MSI wouldn't be triggered although the EP is present and
the MSIs are assigned.

Signed-off-by: Richard Zhu 
Reviewed-by: Lucas Stach 
---
Changes v1 -> v2:
* Assert the MSI_EN unconditionally when MSI is supported.
Changes v2 -> v3:
* Remove the IS_ENABLED(CONFIG_PCI_MSI) since the driver depends on
PCI_MSI_IRQ_DOMAIN
* Extended with a check for pci_msi_enabled() to see if the user
explicitly want legacy IRQs
Changes v3 -> v4:
* Refer to Bjorn's comments, refine the subject and commit log and change
the PCI_MSI_CAP to PCIE_RC_IMX6_MSI_CAP.
Changes v4 -> v5:
* Correct one spell mistake from PCIE_RC_MSI_IMX6_CAP to
PCIE_RC_IMX6_MSI_CAP.
---
 drivers/pci/controller/dwc/pci-imx6.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/drivers/pci/controller/dwc/pci-imx6.c 
b/drivers/pci/controller/dwc/pci-imx6.c
index e563ca9..73542dd 100644
--- a/drivers/pci/controller/dwc/pci-imx6.c
+++ b/drivers/pci/controller/dwc/pci-imx6.c
@@ -82,6 +82,7 @@ struct imx6_pcie {
 #define PHY_PLL_LOCK_WAIT_USLEEP_MAX   200
 
 /* PCIe Root Complex registers (memory-mapped) */
+#define PCIE_RC_IMX6_MSI_CAP   0x50
 #define PCIE_RC_LCR0x7c
 #define PCIE_RC_LCR_MAX_LINK_SPEEDS_GEN1   0x1
 #define PCIE_RC_LCR_MAX_LINK_SPEEDS_GEN2   0x2
@@ -999,6 +1000,7 @@ static int imx6_pcie_probe(struct platform_device *pdev)
struct resource *dbi_base;
struct device_node *node = dev->of_node;
int ret;
+   u16 val;
 
imx6_pcie = devm_kzalloc(dev, sizeof(*imx6_pcie), GFP_KERNEL);
if (!imx6_pcie)
@@ -1149,6 +1151,14 @@ static int imx6_pcie_probe(struct platform_device *pdev)
if (ret < 0)
return ret;
 
+   if (pci_msi_enabled()) {
+   val = dw_pcie_readw_dbi(pci, PCIE_RC_IMX6_MSI_CAP +
+   PCI_MSI_FLAGS);
+   val |= PCI_MSI_FLAGS_ENABLE;
+   dw_pcie_writew_dbi(pci, PCIE_RC_IMX6_MSI_CAP +
+   PCI_MSI_FLAGS, val);
+   }
+
return 0;
 }
 
-- 
2.7.4



Re: [RFC PATCH v5 0/5] x86: Add vDSO exception fixup for SGX

2018-12-18 Thread Jarkko Sakkinen
On Tue, Dec 18, 2018 at 07:08:15AM -0800, Sean Christopherson wrote:
> On Tue, Dec 18, 2018 at 06:18:15AM +0200, Jarkko Sakkinen wrote:
> > On Fri, Dec 14, 2018 at 01:57:24PM -0800, Sean Christopherson wrote:
> > > __vdso_sgx_enter_enclave() gets another rewrite, this time to strip
> > > it down to the bare minimum and explicitly break compliance with the
> > > x86-64 ABI.  Feedback from v4 revealed that __vdso_sgx_enter_enclave()
> > > would need to save (a lot) more than just the non-volatile GPRs to be
> > > compliant with the x86-64 ABI, at which point breaking from the ABI
> > > completely became much more palatable.
> > > 
> > > The non-standard ABI also solves the question of "which GPRs should be
> > > marshalled to/from the enclave" by getting out of the way entirely and
> > > letting userspace have free reign (except for RSP, which has a big ol'
> > > DO NOT TOUCH sign on it).
> > 
> > Can you share a reference, or is this better documented in the
> > accompanied patches?
> 
> Patch 5/5 has more details, and v4 of the series has a lot of background
> info by way of discussion:
> 
> https://lkml.kernel.org/r/20181213213135.12913-1-sean.j.christopher...@intel.com

Thanks Sean, I will. Have not had yet much time to look at this.

/Jarkko


Re: [PATCH] powerpc/prom: move the device tree if not in declared memory.

2018-12-18 Thread Michael Ellerman
Christophe Leroy  writes:

> If the device tree doesn't reside in the memory which is declared
> inside it, it has to be moved as well as this memory will not be
> mapped by the kernel.

I worry this will break some obscure platform, but I'll merge it anyway
and we'll see :)

cheers

> diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
> index 87a68e2dc531..4181ec715f88 100644
> --- a/arch/powerpc/kernel/prom.c
> +++ b/arch/powerpc/kernel/prom.c
> @@ -124,8 +124,8 @@ static void __init move_device_tree(void)
>   size = fdt_totalsize(initial_boot_params);
>  
>   if ((memory_limit && (start + size) > PHYSICAL_START + memory_limit) ||
> - overlaps_crashkernel(start, size) ||
> - overlaps_initrd(start, size)) {
> + !memblock_is_memory(start + size - 1) ||
> + overlaps_crashkernel(start, size) || overlaps_initrd(start, size)) {
>   p = __va(memblock_phys_alloc(size, PAGE_SIZE));
>   memcpy(p, initial_boot_params, size);
>   initial_boot_params = p;
> -- 
> 2.13.3


Re: [PATCH v5 1/2] scsi: hisi_sas: Add support for DIF feature for v2 hw

2018-12-18 Thread Martin K. Petersen


John,

> From: Xiang Chen 
>
> For v3 hw, we support DIF operation for SAS, but not SATA.
>
> In addition, DIF CRC16 is supported.
>
> This patchset adds the SW support for the described features. The main
> components are as follows:
> - Get protection mask from module param
> - Fill PI fields
> - Fill related to DIF in DQ and protection iu memories

Applied to 4.21/scsi-queue, thanks!

-- 
Martin K. Petersen  Oracle Linux Engineering


linux-next: build failure after merge of the kvm tree

2018-12-18 Thread Stephen Rothwell
Hi all,

After merging the kvm tree, today's linux-next build (x86_64 allmodconfig)
failed like this:

arch/x86/kvm/vmx/nested.c: In function 'prepare_vmcs02_full':
arch/x86/kvm/vmx/nested.c:2242:6: error: implicit declaration of function 
'kvm_mpx_supported'; did you mean 'vmx_mpx_supported'? 
[-Werror=implicit-function-declaration]
  if (kvm_mpx_supported()) {
  ^
  vmx_mpx_supported

Caused by commit

  55d2375e58a6 ("KVM: nVMX: Move nested code to dedicated files")

interacting with commit

  eb012ef3b4e3 ("x86: Remove Intel MPX")

from the tip tree.

I applied the following merge fix patch for today:

From: Stephen Rothwell 
Date: Wed, 19 Dec 2018 15:28:31 +1100
Subject: [PATCH] kvm: tidy up from MPX removal

Signed-off-by: Stephen Rothwell 
---
 arch/x86/kvm/vmx/nested.c | 13 -
 arch/x86/kvm/vmx/vmx.c| 40 +++
 2 files changed, 3 insertions(+), 50 deletions(-)

diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index 3f019aa63341..59e6da4171a8 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -2238,14 +2238,6 @@ static void prepare_vmcs02_full(struct vcpu_vmx *vmx, 
struct vmcs12 *vmcs12)
vmcs_write32(VM_ENTRY_MSR_LOAD_COUNT, vmx->msr_autoload.guest.nr);
 
set_cr4_guest_host_mask(vmx);
-
-   if (kvm_mpx_supported()) {
-   if (vmx->nested.nested_run_pending &&
-   (vmcs12->vm_entry_controls & VM_ENTRY_LOAD_BNDCFGS))
-   vmcs_write64(GUEST_BNDCFGS, vmcs12->guest_bndcfgs);
-   else
-   vmcs_write64(GUEST_BNDCFGS, 
vmx->nested.vmcs01_guest_bndcfgs);
-   }
 }
 
 /*
@@ -2971,9 +2963,6 @@ int nested_vmx_enter_non_root_mode(struct kvm_vcpu *vcpu, 
bool from_vmentry)
 
if (!(vmcs12->vm_entry_controls & VM_ENTRY_LOAD_DEBUG_CONTROLS))
vmx->nested.vmcs01_debugctl = vmcs_read64(GUEST_IA32_DEBUGCTL);
-   if (kvm_mpx_supported() &&
-   !(vmcs12->vm_entry_controls & VM_ENTRY_LOAD_BNDCFGS))
-   vmx->nested.vmcs01_guest_bndcfgs = vmcs_read64(GUEST_BNDCFGS);
 
vmx_switch_vmcs(vcpu, >nested.vmcs02);
 
@@ -3496,8 +3485,6 @@ static void sync_vmcs12(struct kvm_vcpu *vcpu, struct 
vmcs12 *vmcs12)
vmcs12->guest_sysenter_cs = vmcs_read32(GUEST_SYSENTER_CS);
vmcs12->guest_sysenter_esp = vmcs_readl(GUEST_SYSENTER_ESP);
vmcs12->guest_sysenter_eip = vmcs_readl(GUEST_SYSENTER_EIP);
-   if (kvm_mpx_supported())
-   vmcs12->guest_bndcfgs = vmcs_read64(GUEST_BNDCFGS);
 }
 
 /*
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index c90fffdc5a93..ccab822be9cd 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -1527,12 +1527,7 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct 
msr_data *msr_info)
msr_info->data = vmcs_readl(GUEST_SYSENTER_ESP);
break;
case MSR_IA32_BNDCFGS:
-   if (!kvm_mpx_supported() ||
-   (!msr_info->host_initiated &&
-!guest_cpuid_has(vcpu, X86_FEATURE_MPX)))
-   return 1;
-   msr_info->data = vmcs_read64(GUEST_BNDCFGS);
-   break;
+   return 1;
case MSR_IA32_MCG_EXT_CTL:
if (!msr_info->host_initiated &&
!(vmx->msr_ia32_feature_control &
@@ -1610,15 +1605,7 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct 
msr_data *msr_info)
vmcs_writel(GUEST_SYSENTER_ESP, data);
break;
case MSR_IA32_BNDCFGS:
-   if (!kvm_mpx_supported() ||
-   (!msr_info->host_initiated &&
-!guest_cpuid_has(vcpu, X86_FEATURE_MPX)))
-   return 1;
-   if (is_noncanonical_address(data & PAGE_MASK, vcpu) ||
-   (data & MSR_IA32_BNDCFGS_RSVD))
-   return 1;
-   vmcs_write64(GUEST_BNDCFGS, data);
-   break;
+   return 1;
case MSR_IA32_SPEC_CTRL:
if (!msr_info->host_initiated &&
!guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL))
@@ -3868,8 +3855,6 @@ static void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool 
init_event)
vmcs_write32(GUEST_ACTIVITY_STATE, GUEST_ACTIVITY_ACTIVE);
vmcs_write32(GUEST_INTERRUPTIBILITY_INFO, 0);
vmcs_writel(GUEST_PENDING_DBG_EXCEPTIONS, 0);
-   if (kvm_mpx_supported())
-   vmcs_write64(GUEST_BNDCFGS, 0);
 
setup_msrs(vmx);
 
@@ -6636,23 +6621,6 @@ static void nested_vmx_cr_fixed1_bits_update(struct 
kvm_vcpu *vcpu)
 #undef cr4_fixed1_update
 }
 
-static void nested_vmx_entry_exit_ctls_update(struct kvm_vcpu *vcpu)
-{
-   struct vcpu_vmx *vmx = to_vmx(vcpu);
-
-   if (kvm_mpx_supported()) {
-   bool mpx_enabled = guest_cpuid_has(vcpu, X86_FEATURE_MPX);
-
-   if (mpx_enabled) {
-   

Re: Fixing MIPS delay slot emulation weakness?

2018-12-18 Thread Paul Burton
Hello,

On Sat, Dec 15, 2018 at 11:19:37AM -0800, Andy Lutomirski wrote:
> The really simple but possibly suboptimal fix is to get rid of
> VM_WRITE and to use get_user_pages(..., FOLL_FORCE) to write to it.

I actually wound up trying this route because it seemed like it would
produce a nice small patch that would be simple to backport, and we
could clean up mainline afterwards.

Unfortunately though things fail because get_user_pages() returns
-EFAULT for the delay slot emulation page, due to the !is_cow_mapping()
check in check_vma_flags(). This was introduced by commit cda540ace6a1
("mm: get_user_pages(write,force) refuse to COW in shared areas"). I'm a
little confused as to its behaviour...

is_cow_mapping() returns true if the VM_MAYWRITE flag is set and
VM_SHARED is not set - this suggests a private & potentially-writable
area, right? That fits in nicely with an area we'd want to COW. Why then
does check_vma_flags() use the inverse of this to indicate a shared
area? This fails if we have a private mapping where VM_MAYWRITE is not
set, but where FOLL_FORCE would otherwise provide a means of writing to
the memory.

If I remove this check in check_vma_flags() then I have a nice simple
patch which seems to work well, leaving the user mapping of the delay
slot emulation page non-writeable. I'm not sure I'm following the mm
innards here though - is there something I should change about the delay
slot page instead? Should I be marking it shared, even though it isn't
really? Or perhaps I'm misunderstanding what VM_MAYWRITE does & I should
set that - would that allow a user to use mprotect() to make the region
writeable..?

The work-in-progress patch can be seen below if it's helpful (and yes, I
realise that the modified condition in check_vma_flags() became
impossible & that removing it would be equivalent).

Or perhaps this is only confusing because it's 4:25am & I'm massively
jetlagged... :)

> A possibly nicer way to accomplish more or less the same thing would
> be to allocate the area with _install_special_mapping() and arrange to
> keep a reference to the struct page around.

I looked at this, but it ends up being a much bigger patch. Perhaps it
could be something to look into as a follow-on cleanup, though it
complicates things a little because we need to actually allocate the
page, preferrably only on demand, which is handled for us with the
current mmap_region() code.

Thanks,
Paul

---
diff --git a/arch/mips/kernel/vdso.c b/arch/mips/kernel/vdso.c
index 48a9c6b90e07..9476efb54d18 100644
--- a/arch/mips/kernel/vdso.c
+++ b/arch/mips/kernel/vdso.c
@@ -126,8 +126,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, 
int uses_interp)
 
/* Map delay slot emulation page */
base = mmap_region(NULL, STACK_TOP, PAGE_SIZE,
-  VM_READ|VM_WRITE|VM_EXEC|
-  VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
+  VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC,
   0, NULL);
if (IS_ERR_VALUE(base)) {
ret = base;
diff --git a/arch/mips/math-emu/dsemul.c b/arch/mips/math-emu/dsemul.c
index 5450f4d1c920..3aa8e3b90efb 100644
--- a/arch/mips/math-emu/dsemul.c
+++ b/arch/mips/math-emu/dsemul.c
@@ -67,11 +67,6 @@ struct emuframe {
 
 static const int emupage_frame_count = PAGE_SIZE / sizeof(struct emuframe);
 
-static inline __user struct emuframe *dsemul_page(void)
-{
-   return (__user struct emuframe *)STACK_TOP;
-}
-
 static int alloc_emuframe(void)
 {
mm_context_t *mm_ctx = >mm->context;
@@ -139,7 +134,7 @@ static void free_emuframe(int idx, struct mm_struct *mm)
 
 static bool within_emuframe(struct pt_regs *regs)
 {
-   unsigned long base = (unsigned long)dsemul_page();
+   unsigned long base = STACK_TOP;
 
if (regs->cp0_epc < base)
return false;
@@ -172,8 +167,8 @@ bool dsemul_thread_cleanup(struct task_struct *tsk)
 
 bool dsemul_thread_rollback(struct pt_regs *regs)
 {
-   struct emuframe __user *fr;
-   int fr_idx;
+   struct emuframe fr;
+   int fr_idx, ret;
 
/* Do nothing if we're not executing from a frame */
if (!within_emuframe(regs))
@@ -183,7 +178,12 @@ bool dsemul_thread_rollback(struct pt_regs *regs)
fr_idx = atomic_read(>thread.bd_emu_frame);
if (fr_idx == BD_EMUFRAME_NONE)
return false;
-   fr = _page()[fr_idx];
+
+   ret = access_process_vm(current,
+   STACK_TOP + (fr_idx * sizeof(fr)),
+   , sizeof(fr), FOLL_FORCE);
+   if (WARN_ON(ret != sizeof(fr)))
+   return false;
 
/*
 * If the PC is at the emul instruction, roll back to the branch. If
@@ -192,9 +192,9 @@ bool dsemul_thread_rollback(struct pt_regs *regs)
 * then something is amiss & the user has branched into some other area
 * of the emupage - we'll free the allocated frame anyway.
 */

Re: [RESEND PATCH v2] megaraid: fix out-of-bound array accesses

2018-12-18 Thread Martin K. Petersen


> diff --git a/drivers/scsi/megaraid/megaraid_sas_fp.c 
> b/drivers/scsi/megaraid/megaraid_sas_fp.c
> index 59ecbb3b53b5..a33628550425 100644
> --- a/drivers/scsi/megaraid/megaraid_sas_fp.c
> +++ b/drivers/scsi/megaraid/megaraid_sas_fp.c
> @@ -1266,7 +1266,7 @@ void mr_update_load_balance_params(struct 
> MR_DRV_RAID_MAP_ALL *drv_map,
>  
>   for (ldCount = 0; ldCount < MAX_LOGICAL_DRIVES_EXT; ldCount++) {
>   ld = MR_TargetIdToLdGet(ldCount, drv_map);
> - if (ld >= MAX_LOGICAL_DRIVES_EXT) {
> + if (ld >= MAX_LOGICAL_DRIVES_EXT - 1) {
>   lbInfo[ldCount].loadBalanceFlag = 0;
>   continue;
>   }
> diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c 
> b/drivers/scsi/megaraid/megaraid_sas_fusion.c
> index f74b5ea24f0f..49eaa87608f6 100644
> --- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
> +++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
> @@ -2832,7 +2832,7 @@ static void megasas_build_ld_nonrw_fusion(struct 
> megasas_instance *instance,
>   device_id < instance->fw_supported_vd_count)) {
>  
>   ld = MR_TargetIdToLdGet(device_id, local_map_ptr);
> - if (ld >= instance->fw_supported_vd_count)
> + if (ld >= instance->fw_supported_vd_count - 1)
>   fp_possible = 0;
>   else {
>   raid = MR_LdRaidGet(ld, local_map_ptr);

Kashyap, Sumit, Shivasharan: Please review!

-- 
Martin K. Petersen  Oracle Linux Engineering


Re: [PATCH] cifs: fix rmdir + azure + compounding regression

2018-12-18 Thread Steve French
Updated the patch to merge it with mine.  This will need to go in ASAP
to avoid the regression.  Running additional functional tests on it
and resending to get more eyes on it.


On Tue, Dec 18, 2018 at 9:57 PM Ronnie Sahlberg  wrote:
>
> When we send a SET_INFO command for file disposition, this ends up as
> an iov of a single byte. This causes problems with SMB3 and encryption.
>
> To avoid this, instead of creating a one byte iov for the disposition value
> and then appending an additional iov with a 7 byte padding we now handle this
> as a single 8 byte iov containing both the disposition byte as well as the
> padding in one single buffer.
>
> Signed-off-by: Ronnie Sahlberg 
> ---
>  fs/cifs/smb2inode.c | 14 +++---
>  fs/cifs/smb2ops.c   | 23 +++
>  fs/cifs/smb2proto.h |  3 ++-
>  3 files changed, 24 insertions(+), 16 deletions(-)
>
> diff --git a/fs/cifs/smb2inode.c b/fs/cifs/smb2inode.c
> index 633d20b7ca03..a8999f930b22 100644
> --- a/fs/cifs/smb2inode.c
> +++ b/fs/cifs/smb2inode.c
> @@ -97,7 +97,7 @@ smb2_compound_op(const unsigned int xid, struct cifs_tcon 
> *tcon,
> if (rc)
> goto finished;
>
> -   smb2_set_next_command(server, [num_rqst++]);
> +   smb2_set_next_command(server, [num_rqst++], 0);
>
> /* Operation */
> switch (command) {
> @@ -111,7 +111,7 @@ smb2_compound_op(const unsigned int xid, struct cifs_tcon 
> *tcon,
> SMB2_O_INFO_FILE, 0,
> sizeof(struct smb2_file_all_info) +
>   PATH_MAX * 2, 0, NULL);
> -   smb2_set_next_command(server, [num_rqst]);
> +   smb2_set_next_command(server, [num_rqst], 0);
> smb2_set_related([num_rqst++]);
> break;
> case SMB2_OP_DELETE:
> @@ -134,7 +134,7 @@ smb2_compound_op(const unsigned int xid, struct cifs_tcon 
> *tcon,
> COMPOUND_FID, current->tgid,
> FILE_DISPOSITION_INFORMATION,
> SMB2_O_INFO_FILE, 0, data, size);
> -   smb2_set_next_command(server, [num_rqst]);
> +   smb2_set_next_command(server, [num_rqst], 1);
> smb2_set_related([num_rqst++]);
> break;
> case SMB2_OP_SET_EOF:
> @@ -149,7 +149,7 @@ smb2_compound_op(const unsigned int xid, struct cifs_tcon 
> *tcon,
> COMPOUND_FID, current->tgid,
> FILE_END_OF_FILE_INFORMATION,
> SMB2_O_INFO_FILE, 0, data, size);
> -   smb2_set_next_command(server, [num_rqst]);
> +   smb2_set_next_command(server, [num_rqst], 0);
> smb2_set_related([num_rqst++]);
> break;
> case SMB2_OP_SET_INFO:
> @@ -165,7 +165,7 @@ smb2_compound_op(const unsigned int xid, struct cifs_tcon 
> *tcon,
> COMPOUND_FID, current->tgid,
> FILE_BASIC_INFORMATION,
> SMB2_O_INFO_FILE, 0, data, size);
> -   smb2_set_next_command(server, [num_rqst]);
> +   smb2_set_next_command(server, [num_rqst], 0);
> smb2_set_related([num_rqst++]);
> break;
> case SMB2_OP_RENAME:
> @@ -189,7 +189,7 @@ smb2_compound_op(const unsigned int xid, struct cifs_tcon 
> *tcon,
> COMPOUND_FID, current->tgid,
> FILE_RENAME_INFORMATION,
> SMB2_O_INFO_FILE, 0, data, size);
> -   smb2_set_next_command(server, [num_rqst]);
> +   smb2_set_next_command(server, [num_rqst], 0);
> smb2_set_related([num_rqst++]);
> break;
> case SMB2_OP_HARDLINK:
> @@ -213,7 +213,7 @@ smb2_compound_op(const unsigned int xid, struct cifs_tcon 
> *tcon,
> COMPOUND_FID, current->tgid,
> FILE_LINK_INFORMATION,
> SMB2_O_INFO_FILE, 0, data, size);
> -   smb2_set_next_command(server, [num_rqst]);
> +   smb2_set_next_command(server, [num_rqst], 0);
> smb2_set_related([num_rqst++]);
> break;
> default:
> diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
> index 225fec1cfa67..e25c7aade98a 100644
> --- a/fs/cifs/smb2ops.c
> +++ b/fs/cifs/smb2ops.c
> @@ -1194,7 +1194,7 @@ smb2_ioctl_query_info(const unsigned int xid,
> rc = SMB2_open_init(tcon, [0], , , path);
> if (rc)
> goto iqinf_exit;
> -   smb2_set_next_command(ses->server, [0]);
> +   smb2_set_next_command(ses->server, [0], 0);
>
> /* Query */
> 

linux-next: manual merge of the kvm tree with the tip tree

2018-12-18 Thread Stephen Rothwell
Hi all,

Today's linux-next merge of the kvm tree got a conflict in:

  arch/x86/kvm/x86.c

between commit:

  eb012ef3b4e3 ("x86: Remove Intel MPX")

from the tip tree and commit:

  b666a4b69739 ("kvm: x86: Dynamically allocate guest_fpu")

from the kvm tree.

I fixed it up (the former removed some code updated by the latter, so I
did that) and can carry the fix as necessary. This is now fixed as far as
linux-next is concerned, but any non trivial conflicts should be mentioned
to your upstream maintainer when your tree is submitted for merging.
You may also want to consider cooperating with the maintainer of the
conflicting tree to minimise any particularly complex conflicts.

-- 
Cheers,
Stephen Rothwell


pgpDrDCKpEQvs.pgp
Description: OpenPGP digital signature


Re: WARNING in __rcu_read_unlock

2018-12-18 Thread Cong Wang
On Tue, Dec 18, 2018 at 4:40 AM Stefano Brivio  wrote:
> Not as far as I know. The selftests checking this path, by design, only
> use supported configurations, they don't forge packets.
>
> Maybe it would be nice to have a semi-automated way to isolate and
> describe/name specific conditions found by syzbot via fuzzing and turn
> those into tests that are then repeated periodically. I'm not sure how
> that would look like, but I think it's still more maintainable than a
> pile of C reproducers with forged packets in selftests/net.
>
> Eric, Cong, Xin, as you also recently fixed a nice deal of similar cases
> reported by syzbot, what do you think? Did you ever feel the need to
> turn a syzbot reproducer into a regression test case?

I think it is a very good idea to archive these C reproducers in
tools/testing/selftests/. After this is done, kbuild bot could do these
regression tests, no longer need to bother syzbot to run them again. :)

Thanks.


  1   2   3   4   5   6   7   8   9   10   >