Re: [PATCH 4/4] arm64: dts: qcom: msm8916: add bindings for i2c1, i2c3, i2c5

2017-11-10 Thread Bjorn Andersson
On Thu 09 Nov 09:14 PST 2017, Damien Riegel wrote:

> Hi Bjorn,
> 
> 
> On Thu, Nov 09, 2017 at 09:00:16AM -0800, Bjorn Andersson wrote:
> > On Wed 01 Nov 10:53 PDT 2017, Damien Riegel wrote:
> > 
> > I think it's better to use the word "nodes" (add nodes...)
> 
> Will reword that.
> 
> > 
> > > Signed-off-by: Damien Riegel 
> > > ---
> > >  arch/arm64/boot/dts/qcom/msm8916-pins.dtsi | 72 
> > > ++
> > >  arch/arm64/boot/dts/qcom/msm8916.dtsi  | 45 +++
> > >  2 files changed, 117 insertions(+)
> > > 
> > > diff --git a/arch/arm64/boot/dts/qcom/msm8916-pins.dtsi 
> > > b/arch/arm64/boot/dts/qcom/msm8916-pins.dtsi
> > > index c67ad8ed8b60..1cec5b30ed6e 100644
> > > --- a/arch/arm64/boot/dts/qcom/msm8916-pins.dtsi
> > > +++ b/arch/arm64/boot/dts/qcom/msm8916-pins.dtsi
> > > @@ -270,6 +270,30 @@
> > >   };
> > >   };
> > >  
> > > + i2c1_default: i2c1_default {
> > > + pinmux {
> > > + function = "blsp_i2c1";
> > > + pins = "gpio2", "gpio3";
> > > + };
> > > + pinconf {
> > > + pins = "gpio2", "gpio3";
> > > + drive-strength = <16>;
> > > + bias-disable;
> > > + };
> > 
> > pinconf is typically board specific, so please leave these out from the
> > base dtsi.
> 
> I don't mind dropping that, but pinconf for i2c{2,4,6} is already in
> msm8916-pins.dtsi, so we should either drop them all, or add pinconf for
> i2c{1,3,5} for consistency.

You're right, this needs to be consistent. So I would like us to update
the existing nodes,

> And if I read the pinctrl driver correctly,
> I2C cannot be routed to other pins, the only properties that users may
> want to modify are drive-strength and bias. Let me know which option you
> prefer.
> 

I discussed the matter with my colleagues and we concluded that we want
to keep the muxing in the platform.dtsi and move the specification of
the electrical properties (pinconf) to the board.dts(i).

We did discuss having some "default values" in the platform file, but
pushing these down to the board file gives an indication to others that
these values are board specific.


PS. If you're willing to provide a patch for the existing nodes I would
be happy to review this as well!

Regards,
Bjorn


Re: staging: pi433: Possible bug in rf69.c

2017-11-10 Thread Marcus Wolf
Hi Dan,

I checked it on my local SVN. You are right. I submitted the code with '&'.
Accodring to a check-in message on my SVN, there was a bugreport end of
July and most probably a patch - either from me, you, Joseph Wright,
Colin King or Julia Lawall, changing '&' to '|'. I guess the patch for
some reason wasn't accepted, but fortunatley I introduced the change to
my SVN.

So from my point of view, we need a change from '&' to '|'.

I could prepare such a patch, but I am still unsure, which repo to use.

Shortly befor I fell ill, you proposed me to use Gregs staging for my
further development. But Colin yesterday was working on a repo, called
linux-next.

Can you (or anyone else) please tell me, when (or for which kind of
patches) to use the Gregs staging and wehen (or for which kind of
patches) to use the linux-next? Sorry for not being familiar with that
stuff!

Thanks a lot,

Marcus



Am 10.11.2017 um 20:32 schrieb Dan Carpenter:
> On Fri, Nov 10, 2017 at 06:23:32PM +0100, Marcus Wolf wrote:
>> Hi everybody!
>>
>> Just comparing the master of Gregs statging of pi433 with my local SVN
>> to review all changes, that were done the last monthes.
>>
>> I am not sure, but maybe we imported a bug in rf69.c lines 378 and
>> following:
>>
>> Gregs repo:
>>  case automatic:  return WRITE_REG(REG_LNA, ( (READ_REG(REG_LNA) & 
>> ~MASK_LNA_GAIN) & LNA_GAIN_AUTO) );
>> my repo:
>>  case automatic:  return WRITE_REG(REG_LNA, ( (READ_REG(REG_LNA) & 
>> ~MASK_LNA_GAIN) | LNA_GAIN_AUTO) );
> 
> I edited the lines for clarity.  The difference is that your repo does
> a bitwise OR "| LNA_GAIN_AUTO" and the kernel.org code does a bitwise
> "& LNA_GAIN_AUTO".
> 
> The kernel repo hasn't changed since you sent us the driver in commit
> 874bcba65f9a ('staging: pi433: New driver').  I agree that & doesn't
> seem to make sense and I'm disapointed that it doesn't cause a Smatch
> warning.
> 
> But LNA_GAIN_AUTO is zero so maybe | BIT(LNA_GAIN_AUTO) was intended
> instead of | LNA_GAIN_AUTO.  I don't know...  No one on this list knows
> the answer probably.  :/
> 
> regards,
> dan caprenter
> 


Re: [Cocci] [PATCH v2] coccinelle: fix parallel build with CHECK=scripts/coccicheck

2017-11-10 Thread Julia Lawall


On Fri, 10 Nov 2017, Julia Lawall wrote:

>
>
> On Thu, 9 Nov 2017, Masahiro Yamada wrote:
>
> > The command "make -j8 C=1 CHECK=scripts/coccicheck" produces lots of
> > "coccicheck failed" error messages.
>
> The question is where parallelism should be specified.  Currently, make
> coccicheck picks up the number of cores on the machine and passes that to
> Coccinelle.
>
> OPTIONS="$OPTIONS --jobs $NPROC --chunksize 1"
>
> On my 80 core machine with hyperthreading, this runs 160 jobs in parallel,
> while in practice that degrades the performance as compared to 40 or 80
> cores.
>
> On the other hand, if we use the make command line argument (-j), then we
> will only get parallelism up to the number of semantic patches.  Since
> some finish quickly, there will be a lot of wasted cycles.
>
> The best would be that the user knows what works well for his machine, and
> specifies it on the command line, and then that value gets propagated to
> Coccinelle, eg so that -j8 would cause not 8 semantic patches to run in
> parallel but instead would cause Coccinelle to run one semantic patch on 8
> files in parallel.  But I don't know if that can be done.

Sorry for these fairly nonsensical comments.  make -j is going to consider
every file, then parse and run every semantic patch on that file.  If the
parallelism is pushed down into Coccinelle, each semantic patch will be
parsed only once, and then Coccinelle will choose the files for which it
is relevant.  If indexing is used (idutils, glimpse), then for semantic
patches that focus on specific keywords, Coccinelle will efficiently
ignore files that are not relevant.  I don't think there would be many
cases where make -j would win.  Perhaps it would be possible to detect
its used and abort with an appopriate message?

julia


>
> julia
>
> >
> > I do not know the coccinelle internals, but I guess --jobs does not
> > work well if spatch is invoked from Make running in parallel.
> > Disable --jobs in this case.
> >
> > Signed-off-by: Masahiro Yamada 
> > ---
> >
> > Changes in v2:
> >   - Grep '-j' instead of '--jobserver-auth'.
> > '--jobserver-*' is not a stable option flag.
> > Make 4.2 change '--jobserver-fds' into '--jobserver-auth'
> >   - Add -q option to grep
> >
> >  scripts/coccicheck | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/scripts/coccicheck b/scripts/coccicheck
> > index 040a8b1..8bab11e 100755
> > --- a/scripts/coccicheck
> > +++ b/scripts/coccicheck
> > @@ -70,6 +70,9 @@ if [ "$C" = "1" -o "$C" = "2" ]; then
> >  # Take only the last argument, which is the C file to test
> >  shift $(( $# - 1 ))
> >  OPTIONS="$COCCIINCLUDE $1"
> > +
> > +# --jobs does not work if Make is running in parallel
> > +echo $MAKEFLAGS | grep -q -E '(^| )-j' && USE_JOBS="no"
> >  else
> >  ONLINE=0
> >  if [ "$KBUILD_EXTMOD" = "" ] ; then
> > --
> > 2.7.4
> >
> >
> ___
> Cocci mailing list
> co...@systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>


Re: [PATCH 1/1] ALSA: usb: initial USB Audio Device Class 3.0 support

2017-11-10 Thread Takashi Iwai
On Sat, 11 Nov 2017 03:56:17 +0100,
Ruslan Bilovol wrote:
> 
> On Thu, Nov 9, 2017 at 10:33 AM, Greg Kroah-Hartman
>  wrote:
> > On Thu, Nov 09, 2017 at 09:16:52AM +0100, Takashi Iwai wrote:
> >> On Thu, 09 Nov 2017 09:04:58 +0100,
> >> Greg Kroah-Hartman wrote:
> >> >
> >> > On Wed, Nov 08, 2017 at 03:38:35PM +0100, Takashi Iwai wrote:
> >> > > On Tue, 07 Nov 2017 03:01:20 +0100,
> >> > > Ruslan Bilovol wrote:
> >> > > >
> >> > > > Recently released USB Audio Class 3.0 specification
> >> > > > introduces many significant changes comparing to
> >> > > > previous versions, like
> >> > > >  - new Power Domains, support for LPM/L1
> >> > > >  - new Cluster descriptor
> >> > > >  - changed layout of all class-specific descriptors
> >> > > >  - new High Capability descriptors
> >> > > >  - New class-specific String descriptors
> >> > > >  - new and removed units
> >> > > >  - additional sources for interrupts
> >> > > >  - removed Type II Audio Data Formats
> >> > > >  - ... and many other things (check spec)
> >> > > >
> >> > > > It also provides backward compatibility through
> >> > > > multiple configurations, as well as requires
> >> > > > mandatory support for BADD (Basic Audio Device
> >> > > > Definition) on each ADC3.0 compliant device
> >> > > >
> >> > > > This patch adds initial support of UAC3 specification
> >> > > > that is enough for Generic I/O Profile (BAOF, BAIF)
> >> > > > device support from BADD document.
> >> > > >
> >> > > > Signed-off-by: Ruslan Bilovol 
> >> > >
> >> > > The patch looks good, but the timing is fairly late for merging to
> >> > > 4.15.
> >> >
> >> > Isn't kbuild barfing all over these?  Is that because of the cross-tree
> >> > changes needed?
> >>
> >> No, it's just local to the audio driver, plus a few
> >> include/linux/usb/*.h modification / addition.
> >> So there shouldn't be a big breakage in that regard.
> 
> The UAC3 gadget driver (which I sent to linux-usb mailing list) depends on
> a new audio-v3.h header which is a part of this patch.
> 
> So Felipe's tree will have dependency on Takashi's tree; and that's why
> kbuild notifies about build failure of UAC3 gadget driver.

OK, I see.  I can prepare an immutable branch once when the patches
are ready to merge.


Takashi


Re: [PATCH net-next 0/6] net: dsa: simplify switchdev prepare phase

2017-11-10 Thread David Miller
From: Vivien Didelot 
Date: Wed,  8 Nov 2017 12:19:11 -0500

> This patch series brings no functional changes.
> 
> It removes the unused switchdev_trans arguments from the dsa_switch_ops
> for both MDB and VLAN operations, and provides function to prepare and
> add these objects for a given bitmap of ports.

This series doesn't apply to net-next and it also seems to duplicate
some fixes that went into 'net'.

Please don't do things this way.

When a fix has to go to 'net' fix, _wait_ until it propagates to
'net-next' if you must use it as a dependency.

Thank you.


Re: [PATCH net] net: dsa: return after vlan prepare phase

2017-11-10 Thread David Miller
From: Vivien Didelot 
Date: Wed,  8 Nov 2017 10:50:10 -0500

> The current code does not return after successfully preparing the VLAN
> addition on every ports member of a it. Fix this.
> 
> Fixes: 1ca4aa9cd4cc ("net: dsa: check VLAN capability of every switch")
> Signed-off-by: Vivien Didelot 

Applied.


Re: [PATCH net] net: dsa: return after mdb prepare phase

2017-11-10 Thread David Miller
From: Vivien Didelot 
Date: Wed,  8 Nov 2017 10:49:56 -0500

> The current code does not return after successfully preparing the MDB
> addition on every ports member of a multicast group. Fix this.
> 
> Fixes: a1a6b7ea7f2d ("net: dsa: add cross-chip multicast support")
> Reported-by: Egil Hjelmeland 
> Signed-off-by: Vivien Didelot 

Applied.


[PATCH net v3 04/12] net/sonic: Clean up and modernize log messages

2017-11-10 Thread Finn Thain
Add missing printk severity levels by adopting pr_foo() calls for the
platform_driver and dev_foo() calls for the nubus_driver.
Avoid KERN_CONT usage as per advice from checkpatch.
Avoid #ifdef around printk calls.

Cc: Thomas Bogendoerfer 
Cc: Chris Zankel 
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
Only the macsonic.c changes have been tested. The other changes
are similar but untested.
---
 drivers/net/ethernet/natsemi/jazzsonic.c | 13 
 drivers/net/ethernet/natsemi/macsonic.c  | 54 ++--
 drivers/net/ethernet/natsemi/xtsonic.c   | 11 ---
 3 files changed, 36 insertions(+), 42 deletions(-)

diff --git a/drivers/net/ethernet/natsemi/jazzsonic.c 
b/drivers/net/ethernet/natsemi/jazzsonic.c
index a6caeb567c0d..2cd88b4b5eac 100644
--- a/drivers/net/ethernet/natsemi/jazzsonic.c
+++ b/drivers/net/ethernet/natsemi/jazzsonic.c
@@ -141,17 +141,14 @@ static int sonic_probe1(struct net_device *dev)
i++;
 
if (known_revisions[i] == 0x) {
-   printk("SONIC ethernet controller not found (0x%4x)\n",
-  silicon_revision);
+   pr_info("SONIC ethernet controller not found (0x%4x)\n",
+   silicon_revision);
goto out;
}
 
if (sonic_debug  &&  version_printed++ == 0)
printk(version);
 
-   printk(KERN_INFO "%s: Sonic ethernet found at 0x%08lx, ",
-  dev_name(lp->device), dev->base_addr);
-
/*
 * Put the sonic into software reset, then
 * retrieve and print the ethernet address.
@@ -244,12 +241,14 @@ static int jazz_sonic_probe(struct platform_device *pdev)
err = sonic_probe1(dev);
if (err)
goto out;
+
+   pr_info("SONIC ethernet @%08lx, MAC %pM, IRQ %d\n",
+   dev->base_addr, dev->dev_addr, dev->irq);
+
err = register_netdev(dev);
if (err)
goto out1;
 
-   printk("%s: MAC %pM IRQ %d\n", dev->name, dev->dev_addr, dev->irq);
-
return 0;
 
 out1:
diff --git a/drivers/net/ethernet/natsemi/macsonic.c 
b/drivers/net/ethernet/natsemi/macsonic.c
index 8a135abe136f..c8c40e4708f3 100644
--- a/drivers/net/ethernet/natsemi/macsonic.c
+++ b/drivers/net/ethernet/natsemi/macsonic.c
@@ -313,8 +313,6 @@ static int mac_onboard_sonic_probe(struct net_device *dev)
if (!MACH_IS_MAC)
return -ENODEV;
 
-   printk(KERN_INFO "Checking for internal Macintosh ethernet (SONIC).. ");
-
/* Bogus probing, on the models which may or may not have
   Ethernet (BTW, the Ethernet *is* always at the same
   address, and nothing else lives there, at least if Apple's
@@ -324,13 +322,11 @@ static int mac_onboard_sonic_probe(struct net_device *dev)
 
card_present = hwreg_present((void*)ONBOARD_SONIC_REGISTERS);
if (!card_present) {
-   printk("none.\n");
+   pr_info("Onboard/comm-slot SONIC not found\n");
return -ENODEV;
}
}
 
-   printk("yes\n");
-
/* Danger!  My arms are flailing wildly!  You *must* set lp->reg_offset
 * and dev->base_addr before using SONIC_READ() or SONIC_WRITE() */
dev->base_addr = ONBOARD_SONIC_REGISTERS;
@@ -343,14 +339,11 @@ static int mac_onboard_sonic_probe(struct net_device *dev)
printk(KERN_INFO "%s", version);
sonic_version_printed = 1;
}
-   printk(KERN_INFO "%s: onboard / comm-slot SONIC at 0x%08lx\n",
-  dev_name(lp->device), dev->base_addr);
 
/* The PowerBook's SONIC is 16 bit always. */
if (macintosh_config->ident == MAC_MODEL_PB520) {
lp->reg_offset = 0;
lp->dma_bitmode = SONIC_BITMODE16;
-   sr = SONIC_READ(SONIC_SR);
} else if (commslot) {
/* Some of the comm-slot cards are 16 bit.  But some
   of them are not.  The 32-bit cards use offset 2 and
@@ -367,22 +360,21 @@ static int mac_onboard_sonic_probe(struct net_device *dev)
else {
lp->dma_bitmode = SONIC_BITMODE16;
lp->reg_offset = 0;
-   sr = SONIC_READ(SONIC_SR);
}
} else {
/* All onboard cards are at offset 2 with 32 bit DMA. */
lp->reg_offset = 2;
lp->dma_bitmode = SONIC_BITMODE32;
-   sr = SONIC_READ(SONIC_SR);
}
-   printk(KERN_INFO
-  "%s: revision 0x%04x, using %d bit DMA and register offset %d\n",
-  dev_name(lp->device), sr, lp->dma_bitmode?32:16, lp->reg_offset);
 
-#if 0 /* This is sometimes useful to find out how MacOS configured the card. */
-   printk(KERN_INFO "%s: DCR: 0x%04x, DCR2: 0x%04x\n", 
dev_name(lp->device),
-  SONIC_READ(SONIC_DCR) & 0x, SONIC_READ(SONIC_DCR2) & 0

[PATCH net v3 02/12] net/mac89x0: Convert to platform_driver

2017-11-10 Thread Finn Thain
Apparently these Dayna cards don't have a pseudoslot declaration ROM
which means they can't be probed like NuBus cards.

Cc: Geert Uytterhoeven 
Signed-off-by: Finn Thain 
---
 arch/m68k/mac/config.c|  4 +++
 drivers/net/Space.c   |  3 --
 drivers/net/ethernet/cirrus/mac89x0.c | 64 +++
 include/net/Space.h   |  1 -
 4 files changed, 32 insertions(+), 40 deletions(-)

diff --git a/arch/m68k/mac/config.c b/arch/m68k/mac/config.c
index d3d435248a24..c73eb8209555 100644
--- a/arch/m68k/mac/config.c
+++ b/arch/m68k/mac/config.c
@@ -1088,6 +1088,10 @@ int __init mac_platform_init(void)
macintosh_config->expansion_type == MAC_EXP_PDS_COMM)
platform_device_register_simple("macsonic", -1, NULL, 0);
 
+   if (macintosh_config->expansion_type == MAC_EXP_PDS ||
+   macintosh_config->expansion_type == MAC_EXP_PDS_COMM)
+   platform_device_register_simple("mac89x0", -1, NULL, 0);
+
if (macintosh_config->ether_type == MAC_ETHER_MACE)
platform_device_register_simple("macmace", -1, NULL, 0);
 
diff --git a/drivers/net/Space.c b/drivers/net/Space.c
index 11fe71278f40..fe123808c6b8 100644
--- a/drivers/net/Space.c
+++ b/drivers/net/Space.c
@@ -117,9 +117,6 @@ static struct devprobe2 m68k_probes[] __initdata = {
 #ifdef CONFIG_MAC8390   /* NuBus NS8390-based cards */
{mac8390_probe, 0},
 #endif
-#ifdef CONFIG_MAC89x0
-   {mac89x0_probe, 0},
-#endif
{NULL, 0},
 };
 
diff --git a/drivers/net/ethernet/cirrus/mac89x0.c 
b/drivers/net/ethernet/cirrus/mac89x0.c
index f910f0f386d6..8a23d2fc0e28 100644
--- a/drivers/net/ethernet/cirrus/mac89x0.c
+++ b/drivers/net/ethernet/cirrus/mac89x0.c
@@ -93,6 +93,7 @@ static const char version[] =
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -105,6 +106,7 @@ static const char version[] =
 
 #include "cs89x0.h"
 
+static int debug;
 static unsigned int net_debug = NET_DEBUG;
 
 /* Information that need to be kept for each board. */
@@ -176,10 +178,9 @@ static const struct net_device_ops mac89x0_netdev_ops = {
 
 /* Probe for the CS8900 card in slot E.  We won't bother looking
anywhere else until we have a really good reason to do so. */
-struct net_device * __init mac89x0_probe(int unit)
+static int mac89x0_device_probe(struct platform_device *pdev)
 {
struct net_device *dev;
-   static int once_is_enough;
struct net_local *lp;
static unsigned version_printed;
int i, slot;
@@ -189,20 +190,13 @@ struct net_device * __init mac89x0_probe(int unit)
int err = -ENODEV;
 
if (!MACH_IS_MAC)
-   return ERR_PTR(-ENODEV);
+   return -ENODEV;
+
+   net_debug = debug;
 
dev = alloc_etherdev(sizeof(struct net_local));
if (!dev)
-   return ERR_PTR(-ENOMEM);
-
-   if (unit >= 0) {
-   sprintf(dev->name, "eth%d", unit);
-   netdev_boot_setup_check(dev);
-   }
-
-   if (once_is_enough)
-   goto out;
-   once_is_enough = 1;
+   return -ENOMEM;
 
/* We might have to parameterize this later */
slot = 0xE;
@@ -228,6 +222,8 @@ struct net_device * __init mac89x0_probe(int unit)
if (sig != swab16(CHIP_EISA_ID_SIG))
goto out;
 
+   SET_NETDEV_DEV(dev, &pdev->dev);
+
/* Initialize the net_device structure. */
lp = netdev_priv(dev);
 
@@ -287,12 +283,14 @@ struct net_device * __init mac89x0_probe(int unit)
err = register_netdev(dev);
if (err)
goto out1;
-   return NULL;
+
+   platform_set_drvdata(pdev, dev);
+   return 0;
 out1:
nubus_writew(0, dev->base_addr + ADD_PORT);
 out:
free_netdev(dev);
-   return ERR_PTR(err);
+   return err;
 }
 
 #if 0
@@ -601,32 +599,26 @@ static int set_mac_address(struct net_device *dev, void 
*addr)
return 0;
 }
 
-#ifdef MODULE
-
-static struct net_device *dev_cs89x0;
-static int debug;
-
 module_param(debug, int, 0);
 MODULE_PARM_DESC(debug, "CS89[02]0 debug level (0-5)");
 MODULE_LICENSE("GPL");
 
-int __init
-init_module(void)
+static int mac89x0_device_remove(struct platform_device *pdev)
 {
-   net_debug = debug;
-dev_cs89x0 = mac89x0_probe(-1);
-   if (IS_ERR(dev_cs89x0)) {
-printk(KERN_WARNING "mac89x0.c: No card found\n");
-   return PTR_ERR(dev_cs89x0);
-   }
+   struct net_device *dev = platform_get_drvdata(pdev);
+
+   unregister_netdev(dev);
+   nubus_writew(0, dev->base_addr + ADD_PORT);
+   free_netdev(dev);
return 0;
 }
 
-void
-cleanup_module(void)
-{
-   unregister_netdev(dev_cs89x0);
-   nubus_writew(0, dev_cs89x0->base_addr + ADD_PORT);
-   free_netdev(dev_cs89x0);
-}
-#endif /* MODULE */
+static struct platform_driver mac89x0_platform_driver = {
+   .probe = mac89

[PATCH net v3 03/12] net/mac8390: Convert to nubus_driver

2017-11-10 Thread Finn Thain
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/net/Space.c |   3 --
 drivers/net/ethernet/8390/mac8390.c | 105 ++--
 include/net/Space.h |   1 -
 3 files changed, 53 insertions(+), 56 deletions(-)

diff --git a/drivers/net/Space.c b/drivers/net/Space.c
index fe123808c6b8..3afda6561434 100644
--- a/drivers/net/Space.c
+++ b/drivers/net/Space.c
@@ -114,9 +114,6 @@ static struct devprobe2 m68k_probes[] __initdata = {
 #ifdef CONFIG_MVME147_NET  /* MVME147 internal Ethernet */
{mvme147lance_probe, 0},
 #endif
-#ifdef CONFIG_MAC8390   /* NuBus NS8390-based cards */
-   {mac8390_probe, 0},
-#endif
{NULL, 0},
 };
 
diff --git a/drivers/net/ethernet/8390/mac8390.c 
b/drivers/net/ethernet/8390/mac8390.c
index 0367c9ada7c6..80bbaa3c7241 100644
--- a/drivers/net/ethernet/8390/mac8390.c
+++ b/drivers/net/ethernet/8390/mac8390.c
@@ -123,8 +123,7 @@ enum mac8390_access {
 };
 
 extern int mac8390_memtest(struct net_device *dev);
-static int mac8390_initdev(struct net_device *dev,
-  struct nubus_functional_resource *ndev,
+static int mac8390_initdev(struct net_device *dev, struct nubus_board *board,
   enum mac8390_type type);
 
 static int mac8390_open(struct net_device *dev);
@@ -170,7 +169,7 @@ static void word_memcpy_tocard(unsigned long tp, const void 
*fp, int count);
 static void word_memcpy_fromcard(void *tp, unsigned long fp, int count);
 static u32 mac8390_msg_enable;
 
-static enum mac8390_type __init mac8390_ident(struct nubus_functional_resource 
*dev)
+static enum mac8390_type mac8390_ident(struct nubus_functional_resource *dev)
 {
switch (dev->dr_sw) {
case NUBUS_DRSW_3COM:
@@ -236,7 +235,7 @@ static enum mac8390_type __init mac8390_ident(struct 
nubus_functional_resource *
return MAC8390_NONE;
 }
 
-static enum mac8390_access __init mac8390_testio(volatile unsigned long 
membase)
+static enum mac8390_access mac8390_testio(unsigned long membase)
 {
unsigned long outdata = 0xA5A0B5B0;
unsigned long indata =  0x;
@@ -254,7 +253,7 @@ static enum mac8390_access __init mac8390_testio(volatile 
unsigned long membase)
return ACCESS_UNKNOWN;
 }
 
-static int __init mac8390_memsize(unsigned long membase)
+static int mac8390_memsize(unsigned long membase)
 {
unsigned long flags;
int i, j;
@@ -290,9 +289,9 @@ static int __init mac8390_memsize(unsigned long membase)
return i * 0x1000;
 }
 
-static bool __init mac8390_init(struct net_device *dev,
-   struct nubus_functional_resource *ndev,
-   enum mac8390_type cardtype)
+static bool mac8390_rsrc_init(struct net_device *dev,
+ struct nubus_functional_resource *ndev,
+ enum mac8390_type cardtype)
 {
struct nubus_dir dir;
struct nubus_dirent ent;
@@ -393,49 +392,40 @@ static bool __init mac8390_init(struct net_device *dev,
return true;
 }
 
-struct net_device * __init mac8390_probe(int unit)
+static int mac8390_device_probe(struct nubus_board *board)
 {
struct net_device *dev;
-   struct nubus_functional_resource *ndev = NULL;
int err = -ENODEV;
struct ei_device *ei_local;
-
-   static unsigned int slots;
-
-   enum mac8390_type cardtype;
-
-   /* probably should check for Nubus instead */
+   struct nubus_functional_resource *fres;
+   enum mac8390_type cardtype = MAC8390_NONE;
 
if (!MACH_IS_MAC)
-   return ERR_PTR(-ENODEV);
+   return -ENODEV;
 
dev = alloc_ei_netdev(0);
if (!dev)
-   return ERR_PTR(-ENOMEM);
+   return -ENOMEM;
 
-   if (unit >= 0)
-   sprintf(dev->name, "eth%d", unit);
+   SET_NETDEV_DEV(dev, &board->dev);
 
-   while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK, NUBUS_TYPE_ETHERNET,
-  ndev))) {
-   /* Have we seen it already? */
-   if (slots & (1 << ndev->board->slot))
+   for_each_board_func_rsrc(board, fres) {
+   if (fres->category != NUBUS_CAT_NETWORK ||
+   fres->type != NUBUS_TYPE_ETHERNET)
continue;
-   slots |= 1 << ndev->board->slot;
 
-   cardtype = mac8390_ident(ndev);
+   cardtype = mac8390_ident(fres);
if (cardtype == MAC8390_NONE)
continue;
 
-   if (!mac8390_init(dev, ndev, cardtype))
-   continue;
-
-   /* Do the nasty 8390 stuff */
-   if (!mac8390_initdev(dev, ndev, cardtype))
+   if (mac8390_rsrc_init(dev, fres, cardtype))
break;
}
+   if (!fres)
+   goto out;
 
-   if (!ndev)
+   err = mac8390_initdev(

[PATCH net v3 06/12] net/mac89x0: Remove dead or unreachable code

2017-11-10 Thread Finn Thain
Signed-off-by: Finn Thain 
---
 drivers/net/ethernet/cirrus/mac89x0.c | 31 ---
 1 file changed, 31 deletions(-)

diff --git a/drivers/net/ethernet/cirrus/mac89x0.c 
b/drivers/net/ethernet/cirrus/mac89x0.c
index 8a23d2fc0e28..c1a3d1aed037 100644
--- a/drivers/net/ethernet/cirrus/mac89x0.c
+++ b/drivers/net/ethernet/cirrus/mac89x0.c
@@ -121,10 +121,6 @@ struct net_local {
 };
 
 /* Index to functions, as function prototypes. */
-
-#if 0
-extern void reset_chip(struct net_device *dev);
-#endif
 static int net_open(struct net_device *dev);
 static int net_send_packet(struct sk_buff *skb, struct net_device *dev);
 static irqreturn_t net_interrupt(int irq, void *dev_id);
@@ -134,10 +130,6 @@ static int net_close(struct net_device *dev);
 static struct net_device_stats *net_get_stats(struct net_device *dev);
 static int set_mac_address(struct net_device *dev, void *addr);
 
-
-/* Example routines you must write ;->. */
-#define tx_done(dev) 1
-
 /* For reading/writing registers ISA-style */
 static inline int
 readreg_io(struct net_device *dev, int portno)
@@ -293,24 +285,6 @@ static int mac89x0_device_probe(struct platform_device 
*pdev)
return err;
 }
 
-#if 0
-/* This is useful for something, but I don't know what yet. */
-void __init reset_chip(struct net_device *dev)
-{
-   int reset_start_time;
-
-   writereg(dev, PP_SelfCTL, readreg(dev, PP_SelfCTL) | POWER_ON_RESET);
-
-   /* wait 30 ms */
-   msleep_interruptible(30);
-
-   /* Wait until the chip is reset */
-   reset_start_time = jiffies;
-   while( (readreg(dev, PP_SelfST) & INIT_DONE) == 0 && jiffies - 
reset_start_time < 2)
-   ;
-}
-#endif
-
 /* Open/initialize the board.  This is called (in the current kernel)
sometime after booting when the 'ifconfig' program is run.
 
@@ -412,11 +386,6 @@ static irqreturn_t net_interrupt(int irq, void *dev_id)
struct net_local *lp;
int ioaddr, status;
 
-   if (dev == NULL) {
-   printk ("net_interrupt(): irq %d for unknown device.\n", irq);
-   return IRQ_NONE;
-   }
-
ioaddr = dev->base_addr;
lp = netdev_priv(dev);
 
-- 
2.13.6



[PATCH net v3 08/12] net/mac89x0: Replace custom debug logging with netif_* calls

2017-11-10 Thread Finn Thain
Signed-off-by: Finn Thain 
---
 drivers/net/ethernet/cirrus/mac89x0.c | 52 ---
 1 file changed, 18 insertions(+), 34 deletions(-)

diff --git a/drivers/net/ethernet/cirrus/mac89x0.c 
b/drivers/net/ethernet/cirrus/mac89x0.c
index 4575370d57db..9348c095c898 100644
--- a/drivers/net/ethernet/cirrus/mac89x0.c
+++ b/drivers/net/ethernet/cirrus/mac89x0.c
@@ -61,18 +61,6 @@
 static const char version[] =
 "cs89x0.c:v1.02 11/26/96 Russell Nelson \n";
 
-/* === configure the driver here === */
-
-/* use 0 for production, 1 for verification, >2 for debug */
-#ifndef NET_DEBUG
-#define NET_DEBUG 0
-#endif
-
-/* === end of configuration === */
-
-
-/* Always include 'config.h' first in case the user wants to turn on
-   or override something. */
 #include 
 
 /*
@@ -108,11 +96,13 @@ static const char version[] =
 
 #include "cs89x0.h"
 
-static int debug;
-static unsigned int net_debug = NET_DEBUG;
+static int debug = -1;
+module_param(debug, int, 0);
+MODULE_PARM_DESC(debug, "debug message level");
 
 /* Information that need to be kept for each board. */
 struct net_local {
+   int msg_enable;
int chip_type;  /* one of: CS8900, CS8920, CS8920M */
char chip_revision; /* revision letter of the chip ('A'...) */
int send_cmd;   /* the propercommand used to send a packet. */
@@ -176,7 +166,6 @@ static int mac89x0_device_probe(struct platform_device 
*pdev)
 {
struct net_device *dev;
struct net_local *lp;
-   static unsigned version_printed;
int i, slot;
unsigned rev_type = 0;
unsigned long ioaddr;
@@ -186,8 +175,6 @@ static int mac89x0_device_probe(struct platform_device 
*pdev)
if (!MACH_IS_MAC)
return -ENODEV;
 
-   net_debug = debug;
-
dev = alloc_etherdev(sizeof(struct net_local));
if (!dev)
return -ENOMEM;
@@ -221,6 +208,8 @@ static int mac89x0_device_probe(struct platform_device 
*pdev)
/* Initialize the net_device structure. */
lp = netdev_priv(dev);
 
+   lp->msg_enable = netif_msg_init(debug, 0);
+
/* Fill in the 'dev' fields. */
dev->base_addr = ioaddr;
dev->mem_start = (unsigned long)
@@ -243,8 +232,7 @@ static int mac89x0_device_probe(struct platform_device 
*pdev)
if (lp->chip_type != CS8900 && lp->chip_revision >= 'C')
lp->send_cmd = TX_NOW;
 
-   if (net_debug && version_printed++ == 0)
-   printk(version);
+   netif_dbg(lp, drv, dev, "%s", version);
 
pr_info("CS89%c0%s rev %c found at %#8lx\n",
lp->chip_type == CS8900 ? '0' : '2',
@@ -344,11 +332,9 @@ net_send_packet(struct sk_buff *skb, struct net_device 
*dev)
struct net_local *lp = netdev_priv(dev);
unsigned long flags;
 
-   if (net_debug > 3)
-   printk("%s: sent %d byte packet of type %x\n",
-  dev->name, skb->len,
-  (skb->data[ETH_ALEN+ETH_ALEN] << 8)
-  | skb->data[ETH_ALEN+ETH_ALEN+1]);
+   netif_dbg(lp, tx_queued, dev, "sent %d byte packet of type %x\n",
+ skb->len, skb->data[ETH_ALEN + ETH_ALEN] << 8 |
+   skb->data[ETH_ALEN + ETH_ALEN + 1]);
 
/* keep the upload from being interrupted, since we
   ask the chip to start transmitting before the
@@ -397,7 +383,7 @@ static irqreturn_t net_interrupt(int irq, void *dev_id)
faster than you can read them off, you're screwed.  Hasta la
vista, baby!  */
while ((status = swab16(nubus_readw(dev->base_addr + ISQ_PORT {
-   if (net_debug > 4)printk("%s: event=%04x\n", dev->name, status);
+   netif_dbg(lp, intr, dev, "status=%04x\n", status);
switch(status & ISQ_EVENT_MASK) {
case ISQ_RECEIVER_EVENT:
/* Got a packet(s). */
@@ -427,7 +413,7 @@ static irqreturn_t net_interrupt(int irq, void *dev_id)
netif_wake_queue(dev);
}
if (status & TX_UNDERRUN) {
-   if (net_debug > 0) printk("%s: transmit 
underrun\n", dev->name);
+   netif_dbg(lp, tx_err, dev, "transmit 
underrun\n");
 lp->send_underrun++;
 if (lp->send_underrun == 3) lp->send_cmd = 
TX_AFTER_381;
 else if (lp->send_underrun == 6) lp->send_cmd 
= TX_AFTER_ALL;
@@ -448,6 +434,7 @@ static irqreturn_t net_interrupt(int irq, void *dev_id)
 static void
 net_rx(struct net_device *dev)
 {
+   struct net_local *lp = netdev_priv(dev);
struct sk_buff *skb;
int status, length;
 
@@ -479,10 +466,9 @@ net_rx(struct net_device *dev)
skb_copy_to_linear_data(skb, (void *)(dev->mem

[PATCH net v3 05/12] net/sonic: Replace custom debug logging with netif_* calls

2017-11-10 Thread Finn Thain
Eliminate duplicated debug code by moving it into the core driver.
Don't log the only valid silicon revision number (it's in the source).

Cc: Thomas Bogendoerfer 
Cc: Chris Zankel 
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
Only the sonic.[ch] and macsonic.c changes have been tested. The other
changes are similar but untested.
---
 drivers/net/ethernet/natsemi/jazzsonic.c | 19 +--
 drivers/net/ethernet/natsemi/macsonic.c  | 25 ++---
 drivers/net/ethernet/natsemi/sonic.c | 92 +++-
 drivers/net/ethernet/natsemi/sonic.h |  2 +
 drivers/net/ethernet/natsemi/xtsonic.c   | 19 +--
 5 files changed, 54 insertions(+), 103 deletions(-)

diff --git a/drivers/net/ethernet/natsemi/jazzsonic.c 
b/drivers/net/ethernet/natsemi/jazzsonic.c
index 2cd88b4b5eac..1dfb5e53af22 100644
--- a/drivers/net/ethernet/natsemi/jazzsonic.c
+++ b/drivers/net/ethernet/natsemi/jazzsonic.c
@@ -59,14 +59,6 @@ do { 
\
*((volatile unsigned int *)dev->base_addr+(reg)) = (val);   
\
 } while (0)
 
-
-/* use 0 for production, 1 for verification, >1 for debug */
-#ifdef SONIC_DEBUG
-static unsigned int sonic_debug = SONIC_DEBUG;
-#else
-static unsigned int sonic_debug = 1;
-#endif
-
 /*
  * We cannot use station (ethernet) address prefixes to detect the
  * sonic controller since these are board manufacturer depended.
@@ -116,7 +108,6 @@ static const struct net_device_ops sonic_netdev_ops = {
 
 static int sonic_probe1(struct net_device *dev)
 {
-   static unsigned version_printed;
unsigned int silicon_revision;
unsigned int val;
struct sonic_local *lp = netdev_priv(dev);
@@ -132,9 +123,6 @@ static int sonic_probe1(struct net_device *dev)
 * the expected location.
 */
silicon_revision = SONIC_READ(SONIC_SR);
-   if (sonic_debug > 1)
-   printk("SONIC Silicon Revision = 0x%04x\n",silicon_revision);
-
i = 0;
while (known_revisions[i] != 0x &&
   known_revisions[i] != silicon_revision)
@@ -146,9 +134,6 @@ static int sonic_probe1(struct net_device *dev)
goto out;
}
 
-   if (sonic_debug  &&  version_printed++ == 0)
-   printk(version);
-
/*
 * Put the sonic into software reset, then
 * retrieve and print the ethernet address.
@@ -245,6 +230,8 @@ static int jazz_sonic_probe(struct platform_device *pdev)
pr_info("SONIC ethernet @%08lx, MAC %pM, IRQ %d\n",
dev->base_addr, dev->dev_addr, dev->irq);
 
+   sonic_msg_init(dev);
+
err = register_netdev(dev);
if (err)
goto out1;
@@ -260,8 +247,6 @@ static int jazz_sonic_probe(struct platform_device *pdev)
 }
 
 MODULE_DESCRIPTION("Jazz SONIC ethernet driver");
-module_param(sonic_debug, int, 0);
-MODULE_PARM_DESC(sonic_debug, "jazzsonic debug level (1-4)");
 MODULE_ALIAS("platform:jazzsonic");
 
 #include "sonic.c"
diff --git a/drivers/net/ethernet/natsemi/macsonic.c 
b/drivers/net/ethernet/natsemi/macsonic.c
index c8c40e4708f3..e2f34bfdde4e 100644
--- a/drivers/net/ethernet/natsemi/macsonic.c
+++ b/drivers/net/ethernet/natsemi/macsonic.c
@@ -69,15 +69,6 @@
 #define SONIC_WRITE(reg,val) (nubus_writew(val, dev->base_addr + (reg * 4) \
  + lp->reg_offset))
 
-/* use 0 for production, 1 for verification, >1 for debug */
-#ifdef SONIC_DEBUG
-static unsigned int sonic_debug = SONIC_DEBUG;
-#else
-static unsigned int sonic_debug = 1;
-#endif
-
-static int sonic_version_printed;
-
 /* For onboard SONIC */
 #define ONBOARD_SONIC_REGISTERS0x50F0A000
 #define ONBOARD_SONIC_PROM_BASE0x50f08000
@@ -335,11 +326,6 @@ static int mac_onboard_sonic_probe(struct net_device *dev)
else
dev->irq = IRQ_NUBUS_9;
 
-   if (!sonic_version_printed) {
-   printk(KERN_INFO "%s", version);
-   sonic_version_printed = 1;
-   }
-
/* The PowerBook's SONIC is 16 bit always. */
if (macintosh_config->ident == MAC_MODEL_PB520) {
lp->reg_offset = 0;
@@ -501,11 +487,6 @@ static int mac_sonic_nubus_probe_board(struct nubus_board 
*board, int id,
lp->dma_bitmode = dma_bitmode;
dev->irq = SLOT2IRQ(board->slot);
 
-   if (!sonic_version_printed) {
-   printk(KERN_INFO "%s", version);
-   sonic_version_printed = 1;
-   }
-
dev_info(&board->dev, "%s, revision 0x%04x, %d bit DMA, register offset 
%d\n",
 board->name, SONIC_READ(SONIC_SR),
 lp->dma_bitmode ? 32 : 16, lp->reg_offset);
@@ -557,6 +538,8 @@ static int mac_sonic_platform_probe(struct platform_device 
*pdev)
if (err)
goto out;
 
+   sonic_msg_init(dev);
+
err = register_netdev(dev);
if (err)
goto out;
@@ -570,8 +553,6 @@ static int mac_sonic_platform_probe(struct platform_d

[PATCH net v3 12/12] net/smc9194: Remove bogus CONFIG_MAC reference

2017-11-10 Thread Finn Thain
AFAIK the only version of smc9194.c with Mac support is the one in the
linux-mac68k CVS repo, which never made it to the mainline.

Despite that, as of v2.3.45, arch/m68k/config.in listed CONFIG_SMC9194
under CONFIG_MAC. This mistake got carried over into Kconfig in v2.5.55.
(See pre-git era "[PATCH] add m68k dependencies to net driver config".)

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/net/ethernet/smsc/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/smsc/Kconfig 
b/drivers/net/ethernet/smsc/Kconfig
index 63aca9f847e1..4c2f612e4414 100644
--- a/drivers/net/ethernet/smsc/Kconfig
+++ b/drivers/net/ethernet/smsc/Kconfig
@@ -20,7 +20,7 @@ if NET_VENDOR_SMSC
 
 config SMC9194
tristate "SMC 9194 support"
-   depends on (ISA || MAC && BROKEN)
+   depends on ISA
select CRC32
---help---
  This is support for the SMC9xxx based Ethernet cards. Choose this
-- 
2.13.6



[PATCH net v3 07/12] net/mac89x0: Fix and modernize log messages

2017-11-10 Thread Finn Thain
Fix log message fragments which no longer produce the desired output
(since the behaviour of printk() was changed).
Add missing printk severity levels.
Drop deprecated "out of memory" message as per checkpatch advice.

Signed-off-by: Finn Thain 
---
 drivers/net/ethernet/cirrus/mac89x0.c | 19 +--
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/cirrus/mac89x0.c 
b/drivers/net/ethernet/cirrus/mac89x0.c
index c1a3d1aed037..4575370d57db 100644
--- a/drivers/net/ethernet/cirrus/mac89x0.c
+++ b/drivers/net/ethernet/cirrus/mac89x0.c
@@ -56,6 +56,8 @@
   local_irq_{dis,en}able()
 */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 static const char version[] =
 "cs89x0.c:v1.02 11/26/96 Russell Nelson \n";
 
@@ -244,16 +246,14 @@ static int mac89x0_device_probe(struct platform_device 
*pdev)
if (net_debug && version_printed++ == 0)
printk(version);
 
-   printk(KERN_INFO "%s: cs89%c0%s rev %c found at %#8lx",
-  dev->name,
-  lp->chip_type==CS8900?'0':'2',
-  lp->chip_type==CS8920M?"M":"",
-  lp->chip_revision,
-  dev->base_addr);
+   pr_info("CS89%c0%s rev %c found at %#8lx\n",
+   lp->chip_type == CS8900 ? '0' : '2',
+   lp->chip_type == CS8920M ? "M" : "",
+   lp->chip_revision, dev->base_addr);
 
/* Try to read the MAC address */
if ((readreg(dev, PP_SelfST) & (EEPROM_PRESENT | EEPROM_OK)) == 0) {
-   printk("\nmac89x0: No EEPROM, giving up now.\n");
+   pr_info("No EEPROM, giving up now\n");
goto out1;
 } else {
 for (i = 0; i < ETH_ALEN; i += 2) {
@@ -268,7 +268,7 @@ static int mac89x0_device_probe(struct platform_device 
*pdev)
 
/* print the IRQ and ethernet address. */
 
-   printk(" IRQ %d ADDR %pM\n", dev->irq, dev->dev_addr);
+   pr_info("MAC %pM, IRQ %d\n", dev->dev_addr, dev->irq);
 
dev->netdev_ops = &mac89x0_netdev_ops;
 
@@ -471,7 +471,6 @@ net_rx(struct net_device *dev)
/* Malloc up new buffer. */
skb = alloc_skb(length, GFP_ATOMIC);
if (skb == NULL) {
-   printk("%s: Memory squeeze, dropping packet.\n", dev->name);
dev->stats.rx_dropped++;
return;
}
@@ -559,7 +558,7 @@ static int set_mac_address(struct net_device *dev, void 
*addr)
return -EADDRNOTAVAIL;
 
memcpy(dev->dev_addr, saddr->sa_data, ETH_ALEN);
-   printk("%s: Setting MAC address to %pM\n", dev->name, dev->dev_addr);
+   netdev_info(dev, "Setting MAC address to %pM\n", dev->dev_addr);
 
/* set the Ethernet address */
for (i=0; i < ETH_ALEN/2; i++)
-- 
2.13.6



[PATCH net v3 11/12] net/macmace: Fix and clean up log messages

2017-11-10 Thread Finn Thain
Don't log unexpanded "eth%d".
Log the chip revision in the probe message (consistent with mace.c).
Drop redundant debug messages for FIFO events recorded in the
interface statistics (also consistent with mace.c).

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/net/ethernet/apple/macmace.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/apple/macmace.c 
b/drivers/net/ethernet/apple/macmace.c
index f17a160dbff2..47d6f1f90116 100644
--- a/drivers/net/ethernet/apple/macmace.c
+++ b/drivers/net/ethernet/apple/macmace.c
@@ -247,8 +247,8 @@ static int mace_probe(struct platform_device *pdev)
dev->netdev_ops = &mace_netdev_ops;
dev->watchdog_timeo = TX_TIMEOUT;
 
-   printk(KERN_INFO "%s: 68K MACE, hardware address %pM\n",
-  dev->name, dev->dev_addr);
+   pr_info("Onboard MACE, hardware address %pM, chip revision 0x%04X\n",
+   dev->dev_addr, mp->chipid);
 
err = register_netdev(dev);
if (!err)
@@ -589,7 +589,6 @@ static irqreturn_t mace_interrupt(int irq, void *dev_id)
else if (fs & (UFLO|LCOL|RTRY)) {
++dev->stats.tx_aborted_errors;
if (mb->xmtfs & UFLO) {
-   printk(KERN_ERR "%s: DMA underrun.\n", 
dev->name);
dev->stats.tx_fifo_errors++;
mace_txdma_reset(dev);
}
@@ -644,10 +643,8 @@ static void mace_dma_rx_frame(struct net_device *dev, 
struct mace_frame *mf)
 
if (frame_status & (RS_OFLO | RS_CLSN | RS_FRAMERR | RS_FCSERR)) {
dev->stats.rx_errors++;
-   if (frame_status & RS_OFLO) {
-   printk(KERN_DEBUG "%s: fifo overflow.\n", dev->name);
+   if (frame_status & RS_OFLO)
dev->stats.rx_fifo_errors++;
-   }
if (frame_status & RS_CLSN)
dev->stats.collisions++;
if (frame_status & RS_FRAMERR)
-- 
2.13.6



[PATCH net v3 01/12] net/macsonic: Convert to nubus_driver

2017-11-10 Thread Finn Thain
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/net/ethernet/natsemi/macsonic.c | 170 ++--
 1 file changed, 118 insertions(+), 52 deletions(-)

diff --git a/drivers/net/ethernet/natsemi/macsonic.c 
b/drivers/net/ethernet/natsemi/macsonic.c
index b3d626da0cc4..8a135abe136f 100644
--- a/drivers/net/ethernet/natsemi/macsonic.c
+++ b/drivers/net/ethernet/natsemi/macsonic.c
@@ -59,8 +59,6 @@
 #include 
 #include 
 
-static char mac_sonic_string[] = "macsonic";
-
 #include "sonic.h"
 
 /* These should basically be bus-size and endian independent (since
@@ -409,7 +407,7 @@ static int mac_onboard_sonic_probe(struct net_device *dev)
return macsonic_init(dev);
 }
 
-static int mac_nubus_sonic_ethernet_addr(struct net_device *dev,
+static int mac_sonic_nubus_ethernet_addr(struct net_device *dev,
 unsigned long prom_addr, int id)
 {
int i;
@@ -448,68 +446,49 @@ static int macsonic_ident(struct 
nubus_functional_resource *ndev)
return -1;
 }
 
-static int mac_nubus_sonic_probe(struct net_device *dev)
+static int mac_sonic_nubus_probe_board(struct nubus_board *board, int id,
+  struct net_device *dev)
 {
-   static int slots;
-   struct nubus_functional_resource *ndev = NULL;
struct sonic_local* lp = netdev_priv(dev);
unsigned long base_addr, prom_addr;
u16 sonic_dcr;
-   int id = -1;
int reg_offset, dma_bitmode;
 
-   /* Find the first SONIC that hasn't been initialized already */
-   while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK,
-  NUBUS_TYPE_ETHERNET, ndev)) != NULL)
-   {
-   /* Have we seen it already? */
-   if (slots & (1slot))
-   continue;
-   slots |= 1slot;
-
-   /* Is it one of ours? */
-   if ((id = macsonic_ident(ndev)) != -1)
-   break;
-   }
-
-   if (ndev == NULL)
-   return -ENODEV;
-
switch (id) {
case MACSONIC_DUODOCK:
-   base_addr = ndev->board->slot_addr + DUODOCK_SONIC_REGISTERS;
-   prom_addr = ndev->board->slot_addr + DUODOCK_SONIC_PROM_BASE;
+   base_addr = board->slot_addr + DUODOCK_SONIC_REGISTERS;
+   prom_addr = board->slot_addr + DUODOCK_SONIC_PROM_BASE;
sonic_dcr = SONIC_DCR_EXBUS | SONIC_DCR_RFT0 | SONIC_DCR_RFT1 |
SONIC_DCR_TFT0;
reg_offset = 2;
dma_bitmode = SONIC_BITMODE32;
break;
case MACSONIC_APPLE:
-   base_addr = ndev->board->slot_addr + APPLE_SONIC_REGISTERS;
-   prom_addr = ndev->board->slot_addr + APPLE_SONIC_PROM_BASE;
+   base_addr = board->slot_addr + APPLE_SONIC_REGISTERS;
+   prom_addr = board->slot_addr + APPLE_SONIC_PROM_BASE;
sonic_dcr = SONIC_DCR_BMS | SONIC_DCR_RFT1 | SONIC_DCR_TFT0;
reg_offset = 0;
dma_bitmode = SONIC_BITMODE32;
break;
case MACSONIC_APPLE16:
-   base_addr = ndev->board->slot_addr + APPLE_SONIC_REGISTERS;
-   prom_addr = ndev->board->slot_addr + APPLE_SONIC_PROM_BASE;
+   base_addr = board->slot_addr + APPLE_SONIC_REGISTERS;
+   prom_addr = board->slot_addr + APPLE_SONIC_PROM_BASE;
sonic_dcr = SONIC_DCR_EXBUS | SONIC_DCR_RFT1 | SONIC_DCR_TFT0 |
SONIC_DCR_PO1 | SONIC_DCR_BMS;
reg_offset = 0;
dma_bitmode = SONIC_BITMODE16;
break;
case MACSONIC_DAYNALINK:
-   base_addr = ndev->board->slot_addr + APPLE_SONIC_REGISTERS;
-   prom_addr = ndev->board->slot_addr + DAYNALINK_PROM_BASE;
+   base_addr = board->slot_addr + APPLE_SONIC_REGISTERS;
+   prom_addr = board->slot_addr + DAYNALINK_PROM_BASE;
sonic_dcr = SONIC_DCR_RFT1 | SONIC_DCR_TFT0 |
SONIC_DCR_PO1 | SONIC_DCR_BMS;
reg_offset = 0;
dma_bitmode = SONIC_BITMODE16;
break;
case MACSONIC_DAYNA:
-   base_addr = ndev->board->slot_addr + DAYNA_SONIC_REGISTERS;
-   prom_addr = ndev->board->slot_addr + DAYNA_SONIC_MAC_ADDR;
+   base_addr = board->slot_addr + DAYNA_SONIC_REGISTERS;
+   prom_addr = board->slot_addr + DAYNA_SONIC_MAC_ADDR;
sonic_dcr = SONIC_DCR_BMS |
SONIC_DCR_RFT1 | SONIC_DCR_TFT0 | SONIC_DCR_PO1;
reg_offset = 0;
@@ -525,14 +504,14 @@ static int mac_nubus_sonic_probe(struct net_device *dev)
dev->base_addr = base_addr;
lp->reg_offset = reg_offset;
lp->dma_bitmode = dma_bitmode;
-   dev->irq = SLOT2IRQ(ndev->board->slot);
+ 

[PATCH net v3 00/12] Fixes, cleanup and modernization for some legacy ethernet NIC drivers

2017-11-10 Thread Finn Thain
This patch series adds support for the Linux Driver Model for Mac NIC
drivers, fixes some logging bugs, removes dead code, and adopts netif_*
calls to reduce code duplication.

All up, about 100 lines of code are eliminated.

This patch series has been tested on a variety of Macs, with coverage
for the changes to lib8390.c, mac8390.c, macsonic.c, sonic.[ch] and
macmace.c.

This patch series should be applied after the NuBus subsystem
modernization patch series.

Changes since v1:
- Keep the once_is_enough test in mac89x0.c.
- Add tested-by tags.
- Move netdev_info() call to correct branch in macmace.c.

Changes since v2:
- Modernize NuBus drivers by adopting the Linux Driver Model.
- Use dev_foo() in NuBus drivers.
- Don't log any probe messages after register_netdev().


Finn Thain (12):
  net/macsonic: Convert to nubus_driver
  net/mac89x0: Convert to platform_driver
  net/mac8390: Convert to nubus_driver
  net/sonic: Clean up and modernize log messages
  net/sonic: Replace custom debug logging with netif_* calls
  net/mac89x0: Remove dead or unreachable code
  net/mac89x0: Fix and modernize log messages
  net/mac89x0: Replace custom debug logging with netif_* calls
  net/8390: Fix redundant code
  net/mac8390: Fix log messages
  net/macmace: Fix and clean up log messages
  net/smc9194: Remove bogus CONFIG_MAC reference

 arch/m68k/mac/config.c   |   4 +
 drivers/net/Space.c  |   6 -
 drivers/net/ethernet/8390/ax88796.c  |   3 -
 drivers/net/ethernet/8390/axnet_cs.c |   2 -
 drivers/net/ethernet/8390/etherh.c   |  17 ---
 drivers/net/ethernet/8390/hydra.c|   4 -
 drivers/net/ethernet/8390/lib8390.c  |   2 +
 drivers/net/ethernet/8390/mac8390.c  | 144 +--
 drivers/net/ethernet/8390/mcf8390.c  |   4 -
 drivers/net/ethernet/8390/pcnet_cs.c |   4 -
 drivers/net/ethernet/8390/zorro8390.c|   5 -
 drivers/net/ethernet/apple/macmace.c |   9 +-
 drivers/net/ethernet/cirrus/mac89x0.c| 160 +++--
 drivers/net/ethernet/natsemi/jazzsonic.c |  32 ++---
 drivers/net/ethernet/natsemi/macsonic.c  | 239 ++-
 drivers/net/ethernet/natsemi/sonic.c |  92 ++--
 drivers/net/ethernet/natsemi/sonic.h |   2 +
 drivers/net/ethernet/natsemi/xtsonic.c   |  30 ++--
 drivers/net/ethernet/smsc/Kconfig|   2 +-
 include/net/Space.h  |   2 -
 20 files changed, 333 insertions(+), 430 deletions(-)

-- 
2.13.6



[PATCH net v3 10/12] net/mac8390: Fix log messages

2017-11-10 Thread Finn Thain
Use dev_foo() and log the slot number instead of the unexpanded "eth%d".
Disambiguate the two identical "Card type %s is unsupported" messages.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/net/ethernet/8390/mac8390.c | 36 +---
 1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/drivers/net/ethernet/8390/mac8390.c 
b/drivers/net/ethernet/8390/mac8390.c
index fb62310610a8..b091f24f7914 100644
--- a/drivers/net/ethernet/8390/mac8390.c
+++ b/drivers/net/ethernet/8390/mac8390.c
@@ -308,14 +308,14 @@ static bool mac8390_rsrc_init(struct net_device *dev,
 */
 
if (nubus_get_func_dir(ndev, &dir) == -1) {
-   pr_err("%s: Unable to get Nubus functional directory for slot 
%X!\n",
-  dev->name, ndev->board->slot);
+   dev_err(&ndev->board->dev,
+   "Unable to get functional directory\n");
return false;
}
 
/* Get the MAC address */
if (nubus_find_rsrc(&dir, NUBUS_RESID_MAC_ADDRESS, &ent) == -1) {
-   pr_info("%s: Couldn't get MAC address!\n", dev->name);
+   dev_info(&ndev->board->dev, "MAC address resource not found\n");
return false;
}
 
@@ -325,8 +325,8 @@ static bool mac8390_rsrc_init(struct net_device *dev,
nubus_rewinddir(&dir);
if (nubus_find_rsrc(&dir, NUBUS_RESID_MINOR_BASEOS,
&ent) == -1) {
-   pr_err("%s: Memory offset resource for slot %X not 
found!\n",
-  dev->name, ndev->board->slot);
+   dev_err(&ndev->board->dev,
+   "Memory offset resource not found\n");
return false;
}
nubus_get_rsrc_mem(&offset, &ent, 4);
@@ -336,8 +336,8 @@ static bool mac8390_rsrc_init(struct net_device *dev,
nubus_rewinddir(&dir);
if (nubus_find_rsrc(&dir, NUBUS_RESID_MINOR_LENGTH,
&ent) == -1) {
-   pr_info("%s: Memory length resource for slot %X not 
found, probing\n",
-   dev->name, ndev->board->slot);
+   dev_info(&ndev->board->dev,
+"Memory length resource not found, probing\n");
offset = mac8390_memsize(dev->mem_start);
} else {
nubus_get_rsrc_mem(&offset, &ent, 4);
@@ -380,8 +380,8 @@ static bool mac8390_rsrc_init(struct net_device *dev,
break;
 
default:
-   pr_err("Card type %s is unsupported, sorry\n",
-  ndev->board->name);
+   dev_err(&ndev->board->dev,
+   "No known base address for card type\n");
return false;
}
}
@@ -537,7 +537,8 @@ static int mac8390_initdev(struct net_device *dev,
case MAC8390_APPLE:
switch (mac8390_testio(dev->mem_start)) {
case ACCESS_UNKNOWN:
-   pr_err("Don't know how to access card memory!\n");
+   dev_err(&board->dev,
+   "Don't know how to access card memory\n");
return -ENODEV;
 
case ACCESS_16:
@@ -603,21 +604,18 @@ static int mac8390_initdev(struct net_device *dev,
break;
 
default:
-   pr_err("Card type %s is unsupported, sorry\n",
-  board->name);
+   dev_err(&board->dev, "Unsupported card type\n");
return -ENODEV;
}
 
__NS8390_init(dev, 0);
 
/* Good, done, now spit out some messages */
-   pr_info("%s: %s in slot %X (type %s)\n",
-   dev->name, board->name, board->slot,
-   cardname[type]);
-   pr_info("MAC %pM IRQ %d, %d KB shared memory at %#lx, %d-bit access.\n",
-   dev->dev_addr, dev->irq,
-   (unsigned int)(dev->mem_end - dev->mem_start) >> 10,
-   dev->mem_start, access_bitmode ? 32 : 16);
+   dev_info(&board->dev, "%s (type %s)\n", board->name, cardname[type]);
+   dev_info(&board->dev, "MAC %pM, IRQ %d, %d KB shared memory at %#lx, 
%d-bit access.\n",
+dev->dev_addr, dev->irq,
+(unsigned int)(dev->mem_end - dev->mem_start) >> 10,
+dev->mem_start, access_bitmode ? 32 : 16);
return 0;
 }
 
-- 
2.13.6



[PATCH net v3 09/12] net/8390: Fix redundant code

2017-11-10 Thread Finn Thain
The patch which introduced the 8390 core module parameter 'msg_enable'
failed to do anything useful with it: it merely causes an ancient
version string to be logged.

Remove the other code that logs the same string. Use the msg_enable
module parameter as the default value for ei_local->msg_enable.
Otherwise, some 8390 modules have no way to set ei_local->msg_enable.

Also fix two more issues arising from the same patch: indentation
mistakes and pointless static variables.

Cc: Russell King 
Fixes: c45f812f0280 ("8390 : Replace ei_debug with msg_enable/NETIF_MSG_* 
feature")
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
Only the mac8390.c and lib8390.c changes have been tested. The other
changes are similar but untested.
---
 drivers/net/ethernet/8390/ax88796.c   |  3 ---
 drivers/net/ethernet/8390/axnet_cs.c  |  2 --
 drivers/net/ethernet/8390/etherh.c| 17 -
 drivers/net/ethernet/8390/hydra.c |  4 
 drivers/net/ethernet/8390/lib8390.c   |  2 ++
 drivers/net/ethernet/8390/mac8390.c   |  7 ---
 drivers/net/ethernet/8390/mcf8390.c   |  4 
 drivers/net/ethernet/8390/pcnet_cs.c  |  4 
 drivers/net/ethernet/8390/zorro8390.c |  5 -
 9 files changed, 2 insertions(+), 46 deletions(-)

diff --git a/drivers/net/ethernet/8390/ax88796.c 
b/drivers/net/ethernet/8390/ax88796.c
index 05d9d3e2e92e..28aa79d2f16c 100644
--- a/drivers/net/ethernet/8390/ax88796.c
+++ b/drivers/net/ethernet/8390/ax88796.c
@@ -77,8 +77,6 @@ static unsigned char version[] = "ax88796.c: Copyright 
2005,2007 Simtec Electron
 
 #define AX_GPOC_PPDSET BIT(6)
 
-static u32 ax_msg_enable;
-
 /* device private data */
 
 struct ax_device {
@@ -747,7 +745,6 @@ static int ax_init_dev(struct net_device *dev)
ei_local->block_output = &ax_block_output;
ei_local->get_8390_hdr = &ax_get_8390_hdr;
ei_local->priv = 0;
-   ei_local->msg_enable = ax_msg_enable;
 
dev->netdev_ops = &ax_netdev_ops;
dev->ethtool_ops = &ax_ethtool_ops;
diff --git a/drivers/net/ethernet/8390/axnet_cs.c 
b/drivers/net/ethernet/8390/axnet_cs.c
index 3da1fc539ef9..91e76dc1e6e1 100644
--- a/drivers/net/ethernet/8390/axnet_cs.c
+++ b/drivers/net/ethernet/8390/axnet_cs.c
@@ -104,7 +104,6 @@ static void AX88190_init(struct net_device *dev, int 
startp);
 static int ax_open(struct net_device *dev);
 static int ax_close(struct net_device *dev);
 static irqreturn_t ax_interrupt(int irq, void *dev_id);
-static u32 axnet_msg_enable;
 
 /**/
 
@@ -151,7 +150,6 @@ static int axnet_probe(struct pcmcia_device *link)
return -ENOMEM;
 
 ei_local = netdev_priv(dev);
-ei_local->msg_enable = axnet_msg_enable;
 spin_lock_init(&ei_local->page_lock);
 
 info = PRIV(dev);
diff --git a/drivers/net/ethernet/8390/etherh.c 
b/drivers/net/ethernet/8390/etherh.c
index 11cbf22ad201..32e9627e3880 100644
--- a/drivers/net/ethernet/8390/etherh.c
+++ b/drivers/net/ethernet/8390/etherh.c
@@ -64,8 +64,6 @@ static char version[] =
 
 #include "lib8390.c"
 
-static u32 etherh_msg_enable;
-
 struct etherh_priv {
void __iomem*ioc_fast;
void __iomem*memc;
@@ -502,18 +500,6 @@ etherh_close(struct net_device *dev)
 }
 
 /*
- * Initialisation
- */
-
-static void __init etherh_banner(void)
-{
-   static int version_printed;
-
-   if ((etherh_msg_enable & NETIF_MSG_DRV) && (version_printed++ == 0))
-   pr_info("%s", version);
-}
-
-/*
  * Read the ethernet address string from the on board rom.
  * This is an ascii string...
  */
@@ -671,8 +657,6 @@ etherh_probe(struct expansion_card *ec, const struct 
ecard_id *id)
struct etherh_priv *eh;
int ret;
 
-   etherh_banner();
-
ret = ecard_request_resources(ec);
if (ret)
goto out;
@@ -757,7 +741,6 @@ etherh_probe(struct expansion_card *ec, const struct 
ecard_id *id)
ei_local->block_output  = etherh_block_output;
ei_local->get_8390_hdr  = etherh_get_header;
ei_local->interface_num = 0;
-   ei_local->msg_enable = etherh_msg_enable;
 
etherh_reset(dev);
__NS8390_init(dev, 0);
diff --git a/drivers/net/ethernet/8390/hydra.c 
b/drivers/net/ethernet/8390/hydra.c
index 8ae249195301..941754ea78ec 100644
--- a/drivers/net/ethernet/8390/hydra.c
+++ b/drivers/net/ethernet/8390/hydra.c
@@ -66,7 +66,6 @@ static void hydra_block_input(struct net_device *dev, int 
count,
 static void hydra_block_output(struct net_device *dev, int count,
   const unsigned char *buf, int start_page);
 static void hydra_remove_one(struct zorro_dev *z);
-static u32 hydra_msg_enable;
 
 static struct zorro_device_id hydra_zorro_tbl[] = {
 { ZORRO_PROD_HYDRA_SYSTEMS_AMIGANET },
@@ -119,7 +118,6 @@ static int hydra_init(struct zorro_dev *z)
 int start_page, stop_page;
 int j;
 int err;
-struct ei_device *ei_local;
 
 static u32 hydra_offsets[16] = {
  

Re: [PATCH net-next 0/2] net: hns3: Bug fixes & Code improvements in HNS3 driver

2017-11-10 Thread David Miller
From: Lipeng 
Date: Wed, 8 Nov 2017 15:52:21 +0800

> This patch-set introduces some bug fixes and code improvements.
> As [patch 1/2] depends on the patch {5392902 net: hns3: Consistently using
> GENMASK in hns3 driver}, which exists in net-next, not exists in net, so
> push this serise to nex-next.

Series applied.


[PATCH] drm: fix amdkfd use-after-free GP fault

2017-11-10 Thread Randy Dunlap
From: Randy Dunlap 

Fix GP fault caused by dev_info() reference to a struct device*
after the device has been freed (use after free).
kfd_chardev_exit() frees the device so 'kfd_device' should not
be used after calling kfd_chardev_exit().

To reproduce, just load the module and then unload it.
Note that %RAX contains repeated 0x6b, which is use-after-free
poisoning.

[  946.645809] calling  kfd_module_init+0x0/0x1000 [amdkfd] @ 5785
[  946.646025] CRAT table not found
[  946.646027] Finished initializing topology ret=0
[  946.646050] kfd kfd: Initialized module
[  946.646058] initcall kfd_module_init+0x0/0x1000 [amdkfd] returned 0 after 
233 usecs
[  947.650189] general protection fault:  [#1] PREEMPT SMP
[  947.650192] Modules linked in: amdkfd(-) amd_iommu_v2 dw_hdmi cec rc_core 
mxm_wmi ttm dln2 gpio_max730x tps65218 lp3943 mcb crc4 fpga_mgr fpga_bridge fmc 
fuse ctr ccm af_packet nf_log_ipv6 xt_pkttype nf_log_ipv4 nf_log_common xt_LOG 
xt_limit ip6t_REJECT nf_reject_ipv6 xt_tcpudp nf_conntrack_ipv6 nf_defrag_ipv6 
ip6table_raw ipt_REJECT nf_reject_ipv4 iptable_raw xt_CT iptable_filter 
ip6table_mangle nf_conntrack_netbios_ns nf_conntrack_broadcast 
nf_conntrack_ipv4 nf_defrag_ipv4 ip_tables xt_conntrack nf_conntrack libcrc32c 
ip6table_filter ip6_tables x_tables coretemp hwmon intel_rapl 
x86_pkg_temp_thermal intel_powerclamp kvm_intel kvm irqbypass crct10dif_pclmul 
crc32_pclmul crc32c_intel ghash_clmulni_intel pcbc aesni_intel uvcvideo 
videobuf2_vmalloc aes_x86_64 videobuf2_memops hid_generic videobuf2_v4l2
[  947.650224]  crypto_simd snd_hda_codec_hdmi videobuf2_core usbmouse videodev 
snd_hda_codec_realtek glue_helper usbhid media hid snd_hda_codec_generic 
snd_hda_intel arc4 snd_hda_codec cryptd iwldvm sdhci_pci snd_hda_core sdhci 
mmc_core mac80211 snd_hwdep iTCO_wdt snd_pcm iTCO_vendor_support xhci_pci 
intel_cstate xhci_hcd i915 snd_seq snd_seq_device ehci_pci snd_timer 
toshiba_acpi ehci_hcd snd usbcore iwlwifi sparse_keymap e1000e cfg80211 
input_leds ptp wmi sr_mod intel_uncore mei_me lpc_ich led_class cdrom 
usb_common pps_core mei joydev intel_rapl_perf mousedev evdev industrialio 
toshiba_bluetooth shpchp mac_hid rfkill soundcore serio_raw pcspkr toshiba_haps 
battery video thermal ac button sg autofs4 [last unloaded: radeon]
[  947.650259] CPU: 3 PID: 5791 Comm: rmmod Not tainted 4.14.0-rc8 #4
[  947.650260] Hardware name: TOSHIBA PORTEGE R835/Portable PC, BIOS Version 
4.10   01/08/2013
[  947.650262] task: 97144a3f2840 task.stack: a51e409c4000
[  947.650266] RIP: 0010:__dev_printk+0x29/0x90
[  947.650267] RSP: 0018:a51e409c7e48 EFLAGS: 00010202
[  947.650269] RAX: 6b6b6b6b6b6b6b6b RBX: 97a579c3 RCX: 000100140013
[  947.650270] RDX: a51e409c7e78 RSI: 97139e360558 RDI: 97a579c3
[  947.650271] RBP: a51e409c7e68 R08: 6b6b6b6b6b6b6b6b R09: a51e409c7e78
[  947.650272] R10: 9714465c44b8 R11: 9714465c55e8 R12: 7fff874111f7
[  947.650273] R13: 0800 R14: 006231c0 R15: 00623010
[  947.650275] FS:  7fe8a109d700() GS:97144fac() 
knlGS:
[  947.650276] CS:  0010 DS:  ES:  CR0: 80050033
[  947.650277] CR2: 0062cc88 CR3: 00013fd43005 CR4: 000606e0
[  947.650279] Call Trace:
[  947.650283]  ? kobject_cleanup+0x75/0x170
[  947.650284]  _dev_info+0x57/0x60
[  947.650288]  ? kfree+0xf5/0x140
[  947.650295]  kfd_module_exit+0x37/0x39 [amdkfd]
[  947.650299]  SyS_delete_module+0x14d/0x260
[  947.650302]  ? exit_to_usermode_loop+0x60/0x87
[  947.650305]  entry_SYSCALL_64_fastpath+0x1e/0xa9
[  947.650307] RIP: 0033:0x7fe8a0beff97
[  947.650308] RSP: 002b:7fff8740ffc8 EFLAGS: 0202 ORIG_RAX: 
00b0
[  947.650310] RAX: ffda RBX: 0003 RCX: 7fe8a0beff97
[  947.650311] RDX: 7fe8a0c56920 RSI: 0800 RDI: 00623228
[  947.650312] RBP: 006231c0 R08: 7fe8a0ea3f20 R09: 7fff8740ef41
[  947.650313] R10: 2ef31b7d R11: 0202 R12: 7fff8740efc0
[  947.650314] R13:  R14: 006231c0 R15: 00623010
[  947.650316] Code: 00 00 55 49 89 d1 48 89 e5 53 48 89 fb 48 83 ec 18 48 85 
f6 74 5f 4c 8b 46 50 4d 85 c0 74 2b 48 8b 86 88 00 00 00 48 85 c0 74 25 <48> 8b 
08 0f be 7b 01 48 c7 c2 96 0a aa 97 31 c0 83 ef 30 e8 7f 
[  947.650339] RIP: __dev_printk+0x29/0x90 RSP: a51e409c7e48
[  947.650388] ---[ end trace c41965e147ae98ae ]---

Signed-off-by: Randy Dunlap 
Cc: Oded Gabbay 
Cc: dri-de...@lists.freedesktop.org
---
 drivers/gpu/drm/amd/amdkfd/kfd_module.c |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

--- lnx-414-rc8.orig/drivers/gpu/drm/amd/amdkfd/kfd_module.c
+++ lnx-414-rc8/drivers/gpu/drm/amd/amdkfd/kfd_module.c
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "kfd_priv.h"
 
 #define KFD_DRIVER_AUTHOR  "AMD Inc. and others"
@@ -138,7 +139,7 @@ static void __exit kfd_module_exit(void)
 

[PATCH 07/14] nubus: Remove redundant code

2017-11-10 Thread Finn Thain
Eliminate unused values from struct nubus_dev to save wasted memory
(a Radius PrecisionColor 24X card has about 95 functional resources
and up to six such cards may be fitted). Also remove redundant static
variable initialization, an unreachable !MACH_IS_MAC conditional,
the unused nubus_find_device() function and the bogus get_nubus_list()
prototype.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/nubus/nubus.c | 52 +--
 drivers/nubus/proc.c  |  2 --
 include/linux/nubus.h | 17 +
 3 files changed, 22 insertions(+), 49 deletions(-)

diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index 5799ff343d84..3e920e6e4c4d 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -281,23 +281,6 @@ EXPORT_SYMBOL(nubus_rewinddir);
 /* Driver interface functions, more or less like in pci.c */
 
 struct nubus_dev*
-nubus_find_device(unsigned short category, unsigned short type,
- unsigned short dr_hw, unsigned short dr_sw,
- const struct nubus_dev *from)
-{
-   struct nubus_dev *itor = from ? from->next : nubus_devices;
-
-   while (itor) {
-   if (itor->category == category && itor->type == type &&
-   itor->dr_hw == dr_hw && itor->dr_sw == dr_sw)
-   return itor;
-   itor = itor->next;
-   }
-   return NULL;
-}
-EXPORT_SYMBOL(nubus_find_device);
-
-struct nubus_dev*
 nubus_find_type(unsigned short category, unsigned short type,
const struct nubus_dev *from)
 {
@@ -468,8 +451,10 @@ nubus_get_functional_resource(struct nubus_board *board, 
int slot,
}
case NUBUS_RESID_NAME:
{
-   nubus_get_rsrc_str(dev->name, &ent, sizeof(dev->name));
-   pr_debug("name: %s\n", dev->name);
+   char name[64];
+
+   nubus_get_rsrc_str(name, &ent, sizeof(name));
+   pr_debug("name: %s\n", name);
break;
}
case NUBUS_RESID_DRVRDIR:
@@ -478,32 +463,39 @@ nubus_get_functional_resource(struct nubus_board *board, 
int slot,
   use this :-) */
struct nubus_dir drvr_dir;
struct nubus_dirent drvr_ent;
+   unsigned char *driver;
 
nubus_get_subdir(&ent, &drvr_dir);
nubus_readdir(&drvr_dir, &drvr_ent);
-   dev->driver = nubus_dirptr(&drvr_ent);
-   pr_debug("driver at: 0x%p\n", dev->driver);
+   driver = nubus_dirptr(&drvr_ent);
+   pr_debug("driver at: 0x%p\n", driver);
break;
}
case NUBUS_RESID_MINOR_BASEOS:
+   {
/* We will need this in order to support
   multiple framebuffers.  It might be handy
   for Ethernet as well */
-   nubus_get_rsrc_mem(&dev->iobase, &ent, 4);
-   pr_debug("memory offset: 0x%08lx\n", dev->iobase);
+   u32 base_offset;
+
+   nubus_get_rsrc_mem(&base_offset, &ent, 4);
+   pr_debug("memory offset: 0x%08x\n", base_offset);
break;
+   }
case NUBUS_RESID_MINOR_LENGTH:
+   {
/* Ditto */
-   nubus_get_rsrc_mem(&dev->iosize, &ent, 4);
-   pr_debug("memory length: 0x%08lx\n", dev->iosize);
+   u32 length;
+
+   nubus_get_rsrc_mem(&length, &ent, 4);
+   pr_debug("memory length: 0x%08x\n", length);
break;
+   }
case NUBUS_RESID_FLAGS:
-   dev->flags = ent.data;
-   pr_debug("flags: 0x%06x\n", dev->flags);
+   pr_debug("flags: 0x%06x\n", ent.data);
break;
case NUBUS_RESID_HWDEVID:
-   dev->hwdevid = ent.data;
-   pr_debug("hwdevid: 0x%06x\n", dev->hwdevid);
+   pr_debug("hwdevid: 0x%06x\n", ent.data);
break;
default:
/* Local/Private resources have their own
@@ -836,8 +828,6 @@ static int __init nubus_init(void)
if (!MACH_IS_MAC)
return 0;
 
-   nubus_devices = NULL;
-   nubus_boards = NULL;
nubus_scan_bus();
nubus_proc_init();
return 0;
diff --git a/drivers/nubus/proc.c b/drivers/nubus/proc.c
index 99dcdb3d31de..c05662931b6c 100644
--- a/drivers/nubus/proc.c
+++ b/drivers/nubus/proc.c
@@ -229,8 +229,6 @@ 

[PATCH 05/14] nubus: Validate slot resource IDs

2017-11-10 Thread Finn Thain
While we are here, include the slot number in the related error messages.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/nubus/nubus.c | 25 +++--
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index 5607e58d5ca2..5799ff343d84 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -615,7 +615,7 @@ static int __init nubus_get_board_resource(struct 
nubus_board *board, int slot,
nbtdata[0], nbtdata[1], nbtdata[2], nbtdata[3]);
if (nbtdata[0] != 1 || nbtdata[1] != 0 ||
nbtdata[2] != 0 || nbtdata[3] != 0)
-   pr_err("this sResource is not a board 
resource!\n");
+   pr_err("Slot %X: sResource is not a board 
resource!\n", slot);
break;
}
case NUBUS_RESID_NAME:
@@ -670,6 +670,7 @@ static struct nubus_board * __init nubus_add_board(int 
slot, int bytelanes)
unsigned long dpat;
struct nubus_dir dir;
struct nubus_dirent ent;
+   int prev_resid = -1;
 
/* Move to the start of the format block */
rp = nubus_rom_addr(slot);
@@ -709,10 +710,10 @@ static struct nubus_board * __init nubus_add_board(int 
slot, int bytelanes)
 
/* Directory offset should be small and negative... */
if (!(board->doffset & 0x00FF))
-   pr_warn("Dodgy doffset!\n");
+   pr_warn("Slot %X: Dodgy doffset!\n", slot);
dpat = nubus_get_rom(&rp, 4, bytelanes);
if (dpat != NUBUS_TEST_PATTERN)
-   pr_warn("Wrong test pattern %08lx!\n", dpat);
+   pr_warn("Slot %X: Wrong test pattern %08lx!\n", slot, dpat);
 
/*
 *  I wonder how the CRC is meant to work -
@@ -738,12 +739,15 @@ static struct nubus_board * __init nubus_add_board(int 
slot, int bytelanes)
   for each of them. */
if (nubus_readdir(&dir, &ent) == -1) {
/* We can't have this! */
-   pr_err("Board resource not found!\n");
+   pr_err("Slot %X: Board resource not found!\n", slot);
return NULL;
-   } else {
-   nubus_get_board_resource(board, slot, &ent);
}
 
+   if (ent.type < 1 || ent.type > 127)
+   pr_warn("Slot %X: Board resource ID is invalid!\n", slot);
+
+   nubus_get_board_resource(board, slot, &ent);
+
while (nubus_readdir(&dir, &ent) != -1) {
struct nubus_dev *dev;
struct nubus_dev **devp;
@@ -752,6 +756,15 @@ static struct nubus_board * __init nubus_add_board(int 
slot, int bytelanes)
if (dev == NULL)
continue;
 
+   /* Resources should appear in ascending ID order. This sanity
+* check prevents duplicate resource IDs.
+*/
+   if (dev->resid <= prev_resid) {
+   kfree(dev);
+   continue;
+   }
+   prev_resid = dev->resid;
+
/* We zeroed this out above */
if (board->first_dev == NULL)
board->first_dev = dev;
-- 
2.13.6



[PATCH 06/14] nubus: Call proc_mkdir() not more than once per slot

2017-11-10 Thread Finn Thain
This patch fixes the following WARNING.

proc_dir_entry 'nubus/a' already registered
Modules linked in:
CPU: 0 PID: 1 Comm: swapper Tainted: GW   
4.13.0-00036-gd57552077387 #1
Stack from 01c1bd9c:
01c1bd9c 003c2c8b 01c1bdc0 0001b0fe  00322f4a 01c43a20 01c43b0c
01c8c420 01c1bde8 0001b1b8 003a4ac3 0148 000faa26 0009 
01c1bde0 003a4b6c 01c1bdfc 01c1be20 000faa26 003a4ac3 0148 003a4b6c
01c43a71 01c8c471 01c1 00326430 0043d00c 0005 01c71a00 0020bce0
00322964 01c1be38 000fac04 01c43a20 01c8c420 01c1bee0 01c8c420 01c1be50
000fac4c 01c1bee0  01c43a20  01c1bee8 0020bd26 01c1bee0
Call Trace: [<0001b0fe>] __warn+0xae/0xde
 [<00322f4a>] memcmp+0x0/0x5c
 [<0001b1b8>] warn_slowpath_fmt+0x2e/0x36
 [<000faa26>] proc_register+0xbe/0xd8
 [<000faa26>] proc_register+0xbe/0xd8
 [<00326430>] sprintf+0x0/0x20
 [<0020bce0>] nubus_proc_attach_device+0x0/0x1b8
 [<00322964>] strcpy+0x0/0x22
 [<000fac04>] proc_mkdir_data+0x64/0x96
 [<000fac4c>] proc_mkdir+0x16/0x1c
 [<0020bd26>] nubus_proc_attach_device+0x46/0x1b8
 [<0020bce0>] nubus_proc_attach_device+0x0/0x1b8
 [<00322964>] strcpy+0x0/0x22
 [<1ba6>] kernel_pg_dir+0xba6/0x1000
 [<004339a2>] proc_bus_nubus_add_devices+0x1a/0x2e
 [<000faa40>] proc_create_data+0x0/0xf2
 [<0003297c>] parse_args+0x0/0x2d4
 [<00433a08>] nubus_proc_init+0x52/0x5a
 [<00433944>] nubus_init+0x0/0x44
 [<00433982>] nubus_init+0x3e/0x44
 [<20dc>] do_one_initcall+0x38/0x196
 [<20a4>] do_one_initcall+0x0/0x196
 [<0003297c>] parse_args+0x0/0x2d4
 [<00322964>] strcpy+0x0/0x22
 [<00040004>] __up_read+0xe/0x40
 [<004231d4>] repair_env_string+0x0/0x7a
 [<0042312e>] kernel_init_freeable+0xee/0x194
 [<00423146>] kernel_init_freeable+0x106/0x194
 [<00433944>] nubus_init+0x0/0x44
 [<000a6000>] kfree+0x0/0x156
 [<0032768c>] kernel_init+0x0/0xda
 [<00327698>] kernel_init+0xc/0xda
 [<0032768c>] kernel_init+0x0/0xda
 [<2a90>] ret_from_kernel_thread+0xc/0x14
---[ end trace 14a6d619908ea253 ]---
[ cut here ]

This gets repeated with each additional functional reasource.

The problem here is calling proc_mkdir() when the directory already
exists. Each nubus_board gets a directory such as /proc/bus/nubus/s/
where s is the hex slot number. Therefore, store the 'procdir' pointer
in struct nubus_board instead of struct nubus_dev.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/nubus/proc.c  | 6 +-
 include/linux/nubus.h | 5 +++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/nubus/proc.c b/drivers/nubus/proc.c
index a74e713a4f7f..99dcdb3d31de 100644
--- a/drivers/nubus/proc.c
+++ b/drivers/nubus/proc.c
@@ -133,9 +133,13 @@ int nubus_proc_attach_device(struct nubus_dev *dev)
return -1;
}

+   if (dev->board->procdir)
+   return 0;
+
/* Create a directory */
snprintf(name, sizeof(name), "%x", dev->board->slot);
-   e = dev->procdir = proc_mkdir(name, proc_bus_nubus_dir);
+   e = proc_mkdir(name, proc_bus_nubus_dir);
+   dev->board->procdir = e;
if (!e)
return -ENOMEM;
 
diff --git a/include/linux/nubus.h b/include/linux/nubus.h
index 3b7d1d4860ef..ffaf05ddbd71 100644
--- a/include/linux/nubus.h
+++ b/include/linux/nubus.h
@@ -52,13 +52,14 @@ struct nubus_board {
unsigned char rev;
unsigned char format;
unsigned char lanes;
+
+   /* Directory entry in /proc/bus/nubus */
+   struct proc_dir_entry *procdir;
 };
 
 struct nubus_dev {
/* Next link in device list */
struct nubus_dev* next;
-   /* Directory entry in /proc/bus/nubus */
-   struct proc_dir_entry* procdir;
 
/* The functional resource ID of this device */
unsigned char resid;
-- 
2.13.6



[PATCH 10/14] nubus: Depopulate /proc/bus/nubus/s/

2017-11-10 Thread Finn Thain
The /proc/bus/nubus/s/ directory tree for any slot s is missing a lot
of information. The struct file_operations methods have long been left
unimplemented (hence the familiar compile-time warning, "Need to set
some I/O handlers here").

Slot resources have a complex structure which varies depending on board
function. The logic for interpreting these ROM data structures is found
in nubus.c. Let's not duplicate it in proc.c.

Remove this code so it can be replaced with a better approach (see
following patch) which does not depend on a stored representation of
slot resource data.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/nubus/proc.c  | 100 --
 include/linux/nubus.h |   1 -
 2 files changed, 101 deletions(-)

diff --git a/drivers/nubus/proc.c b/drivers/nubus/proc.c
index c05662931b6c..88f6a880adb4 100644
--- a/drivers/nubus/proc.c
+++ b/drivers/nubus/proc.c
@@ -60,97 +60,6 @@ static const struct file_operations nubus_devices_proc_fops 
= {
 
 static struct proc_dir_entry *proc_bus_nubus_dir;
 
-static const struct file_operations nubus_proc_subdir_fops = {
-#warning Need to set some I/O handlers here
-};
-
-static void nubus_proc_subdir(struct nubus_dev* dev,
- struct proc_dir_entry* parent,
- struct nubus_dir* dir)
-{
-   struct nubus_dirent ent;
-
-   /* Some of these are directories, others aren't */
-   while (nubus_readdir(dir, &ent) != -1) {
-   char name[9];
-   struct proc_dir_entry* e;
-   
-   snprintf(name, sizeof(name), "%x", ent.type);
-   e = proc_create(name, S_IFREG | S_IRUGO | S_IWUSR, parent,
-   &nubus_proc_subdir_fops);
-   if (!e)
-   return;
-   }
-}
-
-/* Can't do this recursively since the root directory is structured
-   somewhat differently from the subdirectories */
-static void nubus_proc_populate(struct nubus_dev* dev,
-   struct proc_dir_entry* parent,
-   struct nubus_dir* root)
-{
-   struct nubus_dirent ent;
-
-   /* We know these are all directories (board resource + one or
-  more functional resources) */
-   while (nubus_readdir(root, &ent) != -1) {
-   char name[9];
-   struct proc_dir_entry* e;
-   struct nubus_dir dir;
-   
-   snprintf(name, sizeof(name), "%x", ent.type);
-   e = proc_mkdir(name, parent);
-   if (!e) return;
-
-   /* And descend */
-   if (nubus_get_subdir(&ent, &dir) == -1) {
-   /* This shouldn't happen */
-   printk(KERN_ERR "NuBus root directory node %x:%x has no 
subdir!\n",
-  dev->board->slot, ent.type);
-   continue;
-   } else {
-   nubus_proc_subdir(dev, e, &dir);
-   }
-   }
-}
-
-int nubus_proc_attach_device(struct nubus_dev *dev)
-{
-   struct proc_dir_entry *e;
-   struct nubus_dir root;
-   char name[9];
-
-   if (dev == NULL) {
-   printk(KERN_ERR
-  "NULL pointer in nubus_proc_attach_device, shoot the 
programmer!\n");
-   return -1;
-   }
-   
-   if (dev->board == NULL) {
-   printk(KERN_ERR
-  "NULL pointer in nubus_proc_attach_device, shoot the 
programmer!\n");
-   printk("dev = %p, dev->board = %p\n", dev, dev->board);
-   return -1;
-   }
-   
-   if (dev->board->procdir)
-   return 0;
-
-   /* Create a directory */
-   snprintf(name, sizeof(name), "%x", dev->board->slot);
-   e = proc_mkdir(name, proc_bus_nubus_dir);
-   dev->board->procdir = e;
-   if (!e)
-   return -ENOMEM;
-
-   /* Now recursively populate it with files */
-   nubus_get_root_dir(dev->board, &root);
-   nubus_proc_populate(dev, e, &root);
-
-   return 0;
-}
-EXPORT_SYMBOL(nubus_proc_attach_device);
-
 /*
  * /proc/nubus stuff
  */
@@ -218,18 +127,9 @@ static const struct file_operations nubus_proc_fops = {
.release= seq_release,
 };
 
-void __init proc_bus_nubus_add_devices(void)
-{
-   struct nubus_dev *dev;
-   
-   for(dev = nubus_devices; dev; dev = dev->next)
-   nubus_proc_attach_device(dev);
-}
-
 void __init nubus_proc_init(void)
 {
proc_create("nubus", 0, NULL, &nubus_proc_fops);
proc_bus_nubus_dir = proc_mkdir("bus/nubus", NULL);
proc_create("devices", 0, proc_bus_nubus_dir, &nubus_devices_proc_fops);
-   proc_bus_nubus_add_devices();
 }
diff --git a/include/linux/nubus.h b/include/linux/nubus.h
index cddfed466bee..5f6d0eda8673 100644
--- a/include/linux/nubus.h
+++ b/include/linux/nubus.h
@@ -88,7

[PATCH 08/14] nubus: Clean up whitespace

2017-11-10 Thread Finn Thain
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 include/linux/nubus.h | 54 +--
 1 file changed, 27 insertions(+), 27 deletions(-)

diff --git a/include/linux/nubus.h b/include/linux/nubus.h
index d832d849d55c..cddfed466bee 100644
--- a/include/linux/nubus.h
+++ b/include/linux/nubus.h
@@ -27,9 +27,9 @@ struct nubus_dirent {
 };
 
 struct nubus_board {
-   struct nubus_board* next;
-   struct nubus_dev* first_dev;
-   
+   struct nubus_board *next;
+   struct nubus_dev *first_dev;
+
/* Only 9-E actually exist, though 0-8 are also theoretically
   possible, and 0 is a special case which represents the
   motherboard and onboard peripherals (Ethernet, video) */
@@ -38,10 +38,10 @@ struct nubus_board {
char name[64];
 
/* Format block */
-   unsigned char* fblock;
+   unsigned char *fblock;
/* Root directory (does *not* always equal fblock + doffset!) */
-   unsigned char* directory;
-   
+   unsigned char *directory;
+
unsigned long slot_addr;
/* Offset to root directory (sometimes) */
unsigned long doffset;
@@ -59,7 +59,7 @@ struct nubus_board {
 
 struct nubus_dev {
/* Next link in device list */
-   struct nubus_dev* next;
+   struct nubus_dev *next;
 
/* The functional resource ID of this device */
unsigned char resid;
@@ -69,17 +69,17 @@ struct nubus_dev {
unsigned short type;
unsigned short dr_sw;
unsigned short dr_hw;
-   
+
/* Functional directory */
-   unsigned char* directory;
+   unsigned char *directory;
/* Much of our info comes from here */
-   struct nubus_board* board;
+   struct nubus_board *board;
 };
 
 /* This is all NuBus devices (used to find devices later on) */
-extern struct nubus_dev* nubus_devices;
+extern struct nubus_dev *nubus_devices;
 /* This is all NuBus cards */
-extern struct nubus_board* nubus_boards;
+extern struct nubus_board *nubus_boards;
 
 /* Generic NuBus interface functions, modelled after the PCI interface */
 #ifdef CONFIG_PROC_FS
@@ -90,38 +90,38 @@ static inline void nubus_proc_init(void) {}
 
 int nubus_proc_attach_device(struct nubus_dev *dev);
 /* If we need more precision we can add some more of these */
-struct nubus_dev* nubus_find_type(unsigned short category,
+struct nubus_dev *nubus_find_type(unsigned short category,
  unsigned short type,
- const struct nubus_dev* from);
+ const struct nubus_dev *from);
 /* Might have more than one device in a slot, you know... */
-struct nubus_dev* nubus_find_slot(unsigned int slot,
- const struct nubus_dev* from);
+struct nubus_dev *nubus_find_slot(unsigned int slot,
+ const struct nubus_dev *from);
 
 /* These are somewhat more NuBus-specific.  They all return 0 for
success and -1 for failure, as you'd expect. */
 
 /* The root directory which contains the board and functional
directories */
-int nubus_get_root_dir(const struct nubus_board* board,
-  struct nubus_dir* dir);
+int nubus_get_root_dir(const struct nubus_board *board,
+  struct nubus_dir *dir);
 /* The board directory */
 int nubus_get_board_dir(const struct nubus_board* board,
struct nubus_dir* dir);
 /* The functional directory */
-int nubus_get_func_dir(const struct nubus_dev* dev,
-  struct nubus_dir* dir);
+int nubus_get_func_dir(const struct nubus_dev *dev,
+  struct nubus_dir *dir);
 
 /* These work on any directory gotten via the above */
-int nubus_readdir(struct nubus_dir* dir,
- struct nubus_dirent* ent);
-int nubus_find_rsrc(struct nubus_dir* dir,
+int nubus_readdir(struct nubus_dir *dir,
+ struct nubus_dirent *ent);
+int nubus_find_rsrc(struct nubus_dir *dir,
unsigned char rsrc_type,
-   struct nubus_dirent* ent);
-int nubus_rewinddir(struct nubus_dir* dir);
+   struct nubus_dirent *ent);
+int nubus_rewinddir(struct nubus_dir *dir);
 
 /* Things to do with directory entries */
-int nubus_get_subdir(const struct nubus_dirent* ent,
-struct nubus_dir* dir);
+int nubus_get_subdir(const struct nubus_dirent *ent,
+struct nubus_dir *dir);
 void nubus_get_rsrc_mem(void *dest, const struct nubus_dirent *dirent,
 unsigned int len);
 void nubus_get_rsrc_str(char *dest, const struct nubus_dirent *dirent,
-- 
2.13.6



[PATCH 11/14] nubus: Repopulate /proc/bus/nubus/s/

2017-11-10 Thread Finn Thain
Create the /proc/bus/nubus/s/ inodes while scanning slot s. During
descent through slot resource subdirectories, call the new
nubus_proc_add_foo() functions to create the procfs inodes.

Also add a new function, nubus_seq_write_rsrc_mem(), to write the
contents of a particular slot resource to a given seq_file. This is
used by the procfs file_operations methods, to finally give userspace
access to slot ROM information, such as the available video modes.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/nubus/nubus.c | 117 +++---
 drivers/nubus/proc.c  | 170 +++---
 include/linux/nubus.h |  35 ++-
 3 files changed, 288 insertions(+), 34 deletions(-)

diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index ab3400241bf7..16cbdd45dbbc 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -172,8 +173,8 @@ void nubus_get_rsrc_mem(void *dest, const struct 
nubus_dirent *dirent,
 }
 EXPORT_SYMBOL(nubus_get_rsrc_mem);
 
-void nubus_get_rsrc_str(char *dest, const struct nubus_dirent *dirent,
-unsigned int len)
+unsigned int nubus_get_rsrc_str(char *dest, const struct nubus_dirent *dirent,
+unsigned int len)
 {
char *t = dest;
unsigned char *p = nubus_dirptr(dirent);
@@ -188,9 +189,34 @@ void nubus_get_rsrc_str(char *dest, const struct 
nubus_dirent *dirent,
}
if (len > 0)
*t = '\0';
+   return t - dest;
 }
 EXPORT_SYMBOL(nubus_get_rsrc_str);
 
+void nubus_seq_write_rsrc_mem(struct seq_file *m,
+  const struct nubus_dirent *dirent,
+  unsigned int len)
+{
+   unsigned long buf[32];
+   unsigned int buf_size = sizeof(buf);
+   unsigned char *p = nubus_dirptr(dirent);
+
+   /* If possible, write out full buffers */
+   while (len >= buf_size) {
+   unsigned int i;
+
+   for (i = 0; i < ARRAY_SIZE(buf); i++)
+   buf[i] = nubus_get_rom(&p, sizeof(buf[0]),
+  dirent->mask);
+   seq_write(m, buf, buf_size);
+   len -= buf_size;
+   }
+   /* If not, write out individual bytes */
+   while (len--)
+   seq_putc(m, nubus_get_rom(&p, 1, dirent->mask));
+}
+EXPORT_SYMBOL(nubus_seq_write_rsrc_mem);
+
 int nubus_get_root_dir(const struct nubus_board *board,
   struct nubus_dir *dir)
 {
@@ -325,35 +351,35 @@ EXPORT_SYMBOL(nubus_find_rsrc);
looking at, and print out lots and lots of information from the
resource blocks. */
 
-/* FIXME: A lot of this stuff will eventually be useful after
-   initialization, for intelligently probing Ethernet and video chips,
-   among other things.  The rest of it should go in the /proc code.
-   For now, we just use it to give verbose boot logs. */
-
 static int __init nubus_get_block_rsrc_dir(struct nubus_board *board,
+   struct proc_dir_entry *procdir,
const struct nubus_dirent *parent)
 {
struct nubus_dir dir;
struct nubus_dirent ent;
 
nubus_get_subdir(parent, &dir);
+   dir.procdir = nubus_proc_add_rsrc_dir(procdir, parent, board);
 
while (nubus_readdir(&dir, &ent) != -1) {
u32 size;
 
nubus_get_rsrc_mem(&size, &ent, 4);
pr_debug("block (0x%x), size %d\n", ent.type, size);
+   nubus_proc_add_rsrc_mem(dir.procdir, &ent, size);
}
return 0;
 }
 
 static int __init nubus_get_display_vidmode(struct nubus_board *board,
+struct proc_dir_entry *procdir,
 const struct nubus_dirent *parent)
 {
struct nubus_dir dir;
struct nubus_dirent ent;
 
nubus_get_subdir(parent, &dir);
+   dir.procdir = nubus_proc_add_rsrc_dir(procdir, parent, board);
 
while (nubus_readdir(&dir, &ent) != -1) {
switch (ent.type) {
@@ -365,37 +391,42 @@ static int __init nubus_get_display_vidmode(struct 
nubus_board *board,
nubus_get_rsrc_mem(&size, &ent, 4);
pr_debug("block (0x%x), size %d\n", ent.type,
size);
+   nubus_proc_add_rsrc_mem(dir.procdir, &ent, size);
break;
}
default:
pr_debug("unknown resource 0x%02x, data 
0x%06x\n",
ent.type, ent.data);
+   nubus_proc_add_rsrc_mem(dir.procdir, &ent, 0);
}
}
return 0;
 }
 
 static int __init nubus_get_display_resource(stru

[PATCH 09/14] nubus: Don't needlessly unpack vidname and driver resources

2017-11-10 Thread Finn Thain
Scrap the specialized code to unpack video mode name resources and
driver resources. It isn't useful.
Instead, add a re-usable function to handle lists of block resources of
any kind, and descend into the mode table resource directory.
Rename nubus_show_foo() as nubus_get_foo(), consistent with their
purpose and with related functions in the same file.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/nubus/nubus.c | 123 ++
 1 file changed, 65 insertions(+), 58 deletions(-)

diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index 3e920e6e4c4d..ab3400241bf7 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -330,16 +330,63 @@ EXPORT_SYMBOL(nubus_find_rsrc);
among other things.  The rest of it should go in the /proc code.
For now, we just use it to give verbose boot logs. */
 
-static int __init nubus_show_display_resource(struct nubus_dev *dev,
- const struct nubus_dirent *ent)
+static int __init nubus_get_block_rsrc_dir(struct nubus_board *board,
+   const struct nubus_dirent *parent)
+{
+   struct nubus_dir dir;
+   struct nubus_dirent ent;
+
+   nubus_get_subdir(parent, &dir);
+
+   while (nubus_readdir(&dir, &ent) != -1) {
+   u32 size;
+
+   nubus_get_rsrc_mem(&size, &ent, 4);
+   pr_debug("block (0x%x), size %d\n", ent.type, size);
+   }
+   return 0;
+}
+
+static int __init nubus_get_display_vidmode(struct nubus_board *board,
+const struct nubus_dirent *parent)
+{
+   struct nubus_dir dir;
+   struct nubus_dirent ent;
+
+   nubus_get_subdir(parent, &dir);
+
+   while (nubus_readdir(&dir, &ent) != -1) {
+   switch (ent.type) {
+   case 1: /* mVidParams */
+   case 2: /* mTable */
+   {
+   u32 size;
+
+   nubus_get_rsrc_mem(&size, &ent, 4);
+   pr_debug("block (0x%x), size %d\n", ent.type,
+   size);
+   break;
+   }
+   default:
+   pr_debug("unknown resource 0x%02x, data 
0x%06x\n",
+   ent.type, ent.data);
+   }
+   }
+   return 0;
+}
+
+static int __init nubus_get_display_resource(struct nubus_dev *dev,
+ const struct nubus_dirent *ent)
 {
switch (ent->type) {
case NUBUS_RESID_GAMMADIR:
pr_debug("gamma directory offset: 0x%06x\n", ent->data);
+   nubus_get_block_rsrc_dir(dev->board, ent);
break;
case 0x0080 ... 0x0085:
pr_debug("mode 0x%02x info offset: 0x%06x\n",
ent->type, ent->data);
+   nubus_get_display_vidmode(dev->board, ent);
break;
default:
pr_debug("unknown resource 0x%02x, data 0x%06x\n",
@@ -348,8 +395,8 @@ static int __init nubus_show_display_resource(struct 
nubus_dev *dev,
return 0;
 }
 
-static int __init nubus_show_network_resource(struct nubus_dev *dev,
- const struct nubus_dirent *ent)
+static int __init nubus_get_network_resource(struct nubus_dev *dev,
+ const struct nubus_dirent *ent)
 {
switch (ent->type) {
case NUBUS_RESID_MAC_ADDRESS:
@@ -367,8 +414,8 @@ static int __init nubus_show_network_resource(struct 
nubus_dev *dev,
return 0;
 }
 
-static int __init nubus_show_cpu_resource(struct nubus_dev *dev,
- const struct nubus_dirent *ent)
+static int __init nubus_get_cpu_resource(struct nubus_dev *dev,
+ const struct nubus_dirent *ent)
 {
switch (ent->type) {
case NUBUS_RESID_MEMINFO:
@@ -396,18 +443,18 @@ static int __init nubus_show_cpu_resource(struct 
nubus_dev *dev,
return 0;
 }
 
-static int __init nubus_show_private_resource(struct nubus_dev *dev,
- const struct nubus_dirent *ent)
+static int __init nubus_get_private_resource(struct nubus_dev *dev,
+ const struct nubus_dirent *ent)
 {
switch (dev->category) {
case NUBUS_CAT_DISPLAY:
-   nubus_show_display_resource(dev, ent);
+   nubus_get_display_resource(dev, ent);
break;
case NUBUS_CAT_NETWORK:
-   nubus_show_network_resource(dev, ent);
+   nubus_get_network_resource(dev, ent);
break;
case NUBUS_CAT_CPU:
-   nubus_show_cpu_resource(dev, ent);
+   nubus_get_cpu_resource(dev, ent);
break;
   

[PATCH 00/14] Modernization and fixes for NuBus subsystem

2017-11-10 Thread Finn Thain
This series begins with cleanups and fixes for the NuBus subsystem and
finishes with a patch to add support for the Linux Driver Model.
The next series, which requires this one, will modernize NuBus drivers.


Finn Thain (14):
  nubus: Avoid array underflow and overflow
  nubus: Fix up header split
  nubus: Use static functions where possible
  nubus: Fix log spam
  nubus: Validate slot resource IDs
  nubus: Call proc_mkdir() not more than once per slot
  nubus: Remove redundant code
  nubus: Clean up whitespace
  nubus: Don't needlessly unpack vidname and driver resources
  nubus: Depopulate /proc/bus/nubus/s/
  nubus: Repopulate /proc/bus/nubus/s/
  nubus: Rename struct nubus_dev
  nubus: Add expansion_type values for various Mac models
  nubus: Add support for the driver model

 arch/m68k/include/asm/macintosh.h   |   9 +-
 arch/m68k/mac/config.c  | 110 +++
 drivers/net/ethernet/8390/mac8390.c |  12 +-
 drivers/net/ethernet/natsemi/macsonic.c |  12 +-
 drivers/nubus/Makefile  |   2 +-
 drivers/nubus/bus.c |  87 ++
 drivers/nubus/nubus.c   | 500 ++--
 drivers/nubus/proc.c| 247 ++--
 drivers/video/fbdev/macfb.c |   2 +-
 include/linux/nubus.h   | 200 -
 include/uapi/linux/nubus.h  |  23 --
 11 files changed, 724 insertions(+), 480 deletions(-)
 create mode 100644 drivers/nubus/bus.c

-- 
2.13.6



[PATCH 14/14] nubus: Add support for the driver model

2017-11-10 Thread Finn Thain
Cc: Greg Kroah-Hartman 
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/nubus/Makefile |  2 +-
 drivers/nubus/bus.c| 87 ++
 drivers/nubus/nubus.c  |  3 ++
 include/linux/nubus.h  | 39 ++
 4 files changed, 130 insertions(+), 1 deletion(-)
 create mode 100644 drivers/nubus/bus.c

diff --git a/drivers/nubus/Makefile b/drivers/nubus/Makefile
index 21bda2031e7e..6d063cde39d1 100644
--- a/drivers/nubus/Makefile
+++ b/drivers/nubus/Makefile
@@ -2,6 +2,6 @@
 # Makefile for the nubus specific drivers.
 #
 
-obj-y   := nubus.o
+obj-y := nubus.o bus.o
 
 obj-$(CONFIG_PROC_FS) += proc.o
diff --git a/drivers/nubus/bus.c b/drivers/nubus/bus.c
new file mode 100644
index ..fa44b42ad71f
--- /dev/null
+++ b/drivers/nubus/bus.c
@@ -0,0 +1,87 @@
+/*
+ * Bus implementation for the NuBus subsystem.
+ *
+ * Copyright (C) 2017 Finn Thain
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2,
+ * as published by the Free Software Foundation.
+ */
+
+#include 
+
+#define to_nubus_board(d)   container_of(d, struct nubus_board, dev)
+#define to_nubus_driver(d)  container_of(d, struct nubus_driver, driver)
+
+static int nubus_bus_match(struct device *dev, struct device_driver *driver)
+{
+   return 1;
+}
+
+static int nubus_device_probe(struct device *dev)
+{
+   struct nubus_driver *ndrv = to_nubus_driver(dev->driver);
+   int err = -ENODEV;
+
+   if (ndrv->probe)
+   err = ndrv->probe(to_nubus_board(dev));
+   return err;
+}
+
+static int nubus_device_remove(struct device *dev)
+{
+   struct nubus_driver *ndrv = to_nubus_driver(dev->driver);
+   int err = -ENODEV;
+
+   if (ndrv->remove)
+   err = ndrv->remove(to_nubus_board(dev));
+   return err;
+}
+
+struct bus_type nubus_bus_type = {
+   .name   = "nubus",
+   .match  = nubus_bus_match,
+   .probe  = nubus_device_probe,
+   .remove = nubus_device_remove,
+};
+EXPORT_SYMBOL(nubus_bus_type);
+
+int nubus_driver_register(struct nubus_driver *ndrv)
+{
+   ndrv->driver.bus = &nubus_bus_type;
+   return driver_register(&ndrv->driver);
+}
+EXPORT_SYMBOL(nubus_driver_register);
+
+void nubus_driver_unregister(struct nubus_driver *ndrv)
+{
+   driver_unregister(&ndrv->driver);
+}
+EXPORT_SYMBOL(nubus_driver_unregister);
+
+static struct device nubus_parent = {
+   .init_name  = "nubus",
+};
+
+int __init nubus_bus_register(void)
+{
+   int err;
+
+   err = bus_register(&nubus_bus_type);
+   if (err)
+   return err;
+
+   err = device_register(&nubus_parent);
+   if (err)
+   bus_unregister(&nubus_bus_type);
+
+   return err;
+}
+
+int nubus_device_add(struct nubus_board *board)
+{
+   board->dev.parent = &nubus_parent;
+   board->dev.bus = &nubus_bus_type;
+   dev_set_name(&board->dev, "slot.%X", board->slot);
+   return device_register(&board->dev);
+}
diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index cc9dba4b4f01..ac08c23a3bfe 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -855,6 +855,8 @@ static struct nubus_board * __init nubus_add_board(int 
slot, int bytelanes)
*boardp = board;
board->next = NULL;
 
+   nubus_device_add(board);
+
return board;
 }
 
@@ -908,6 +910,7 @@ static int __init nubus_init(void)
return 0;
 
nubus_proc_init();
+   nubus_bus_register();
nubus_scan_bus();
return 0;
 }
diff --git a/include/linux/nubus.h b/include/linux/nubus.h
index ede0727c1cf8..c78e49a3008b 100644
--- a/include/linux/nubus.h
+++ b/include/linux/nubus.h
@@ -9,6 +9,7 @@
 #ifndef LINUX_NUBUS_H
 #define LINUX_NUBUS_H
 
+#include 
 #include 
 #include 
 
@@ -34,6 +35,8 @@ struct nubus_board {
struct nubus_board *next;
struct nubus_functional_resource *first_func_rsrc;
 
+   struct device dev;
+
/* Only 9-E actually exist, though 0-8 are also theoretically
   possible, and 0 is a special case which represents the
   motherboard and onboard peripherals (Ethernet, video) */
@@ -80,6 +83,14 @@ struct nubus_functional_resource {
struct nubus_board *board;
 };
 
+struct nubus_driver {
+   struct device_driver driver;
+   int (*probe)(struct nubus_board *board);
+   int (*remove)(struct nubus_board *board);
+};
+
+extern struct bus_type nubus_bus_type;
+
 /* This is all NuBus functional resources (used to find devices later on) */
 extern struct nubus_functional_resource *nubus_func_rsrcs;
 /* This is all NuBus cards */
@@ -156,6 +167,34 @@ void nubus_seq_write_rsrc_mem(struct seq_file *m,
   const struct nubus_dirent *dirent,
   unsigned int len);
 
+int nubus_bus_register(void);
+int nubus_device_

[PATCH 13/14] nubus: Add expansion_type values for various Mac models

2017-11-10 Thread Finn Thain
Add an expansion slot attribute to allow drivers to properly handle
cards like Comm Slot cards and PDS cards without declaration ROMs.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 arch/m68k/include/asm/macintosh.h   |   9 ++-
 arch/m68k/mac/config.c  | 110 +---
 drivers/net/ethernet/natsemi/macsonic.c |   8 +--
 3 files changed, 54 insertions(+), 73 deletions(-)

diff --git a/arch/m68k/include/asm/macintosh.h 
b/arch/m68k/include/asm/macintosh.h
index 5b81ab188aa5..10fe2954d95f 100644
--- a/arch/m68k/include/asm/macintosh.h
+++ b/arch/m68k/include/asm/macintosh.h
@@ -32,7 +32,7 @@ struct mac_model
char ide_type;
char scc_type;
char ether_type;
-   char nubus_type;
+   char expansion_type;
char floppy_type;
 };
 
@@ -72,8 +72,11 @@ struct mac_model
 #define MAC_ETHER_SONIC1
 #define MAC_ETHER_MACE 2
 
-#define MAC_NO_NUBUS   0
-#define MAC_NUBUS  1
+#define MAC_EXP_NONE   0
+#define MAC_EXP_PDS1 /* Accepts only a PDS card */
+#define MAC_EXP_NUBUS  2 /* Accepts only NuBus card(s) */
+#define MAC_EXP_PDS_NUBUS  3 /* Accepts PDS card and/or NuBus card(s) */
+#define MAC_EXP_PDS_COMM   4 /* Accepts PDS card or Comm Slot card */
 
 #define MAC_FLOPPY_IWM 0
 #define MAC_FLOPPY_SWIM_ADDR1  1
diff --git a/arch/m68k/mac/config.c b/arch/m68k/mac/config.c
index 16cd5cea5207..d3d435248a24 100644
--- a/arch/m68k/mac/config.c
+++ b/arch/m68k/mac/config.c
@@ -212,7 +212,7 @@ static struct mac_model mac_data_table[] = {
.via_type   = MAC_VIA_II,
.scsi_type  = MAC_SCSI_OLD,
.scc_type   = MAC_SCC_II,
-   .nubus_type = MAC_NUBUS,
+   .expansion_type = MAC_EXP_NUBUS,
.floppy_type= MAC_FLOPPY_IWM,
},
 
@@ -227,7 +227,7 @@ static struct mac_model mac_data_table[] = {
.via_type   = MAC_VIA_II,
.scsi_type  = MAC_SCSI_OLD,
.scc_type   = MAC_SCC_II,
-   .nubus_type = MAC_NUBUS,
+   .expansion_type = MAC_EXP_NUBUS,
.floppy_type= MAC_FLOPPY_IWM,
}, {
.ident  = MAC_MODEL_IIX,
@@ -236,7 +236,7 @@ static struct mac_model mac_data_table[] = {
.via_type   = MAC_VIA_II,
.scsi_type  = MAC_SCSI_OLD,
.scc_type   = MAC_SCC_II,
-   .nubus_type = MAC_NUBUS,
+   .expansion_type = MAC_EXP_NUBUS,
.floppy_type= MAC_FLOPPY_SWIM_ADDR2,
}, {
.ident  = MAC_MODEL_IICX,
@@ -245,7 +245,7 @@ static struct mac_model mac_data_table[] = {
.via_type   = MAC_VIA_II,
.scsi_type  = MAC_SCSI_OLD,
.scc_type   = MAC_SCC_II,
-   .nubus_type = MAC_NUBUS,
+   .expansion_type = MAC_EXP_NUBUS,
.floppy_type= MAC_FLOPPY_SWIM_ADDR2,
}, {
.ident  = MAC_MODEL_SE30,
@@ -254,7 +254,7 @@ static struct mac_model mac_data_table[] = {
.via_type   = MAC_VIA_II,
.scsi_type  = MAC_SCSI_OLD,
.scc_type   = MAC_SCC_II,
-   .nubus_type = MAC_NUBUS,
+   .expansion_type = MAC_EXP_PDS,
.floppy_type= MAC_FLOPPY_SWIM_ADDR2,
},
 
@@ -272,7 +272,7 @@ static struct mac_model mac_data_table[] = {
.via_type   = MAC_VIA_IICI,
.scsi_type  = MAC_SCSI_OLD,
.scc_type   = MAC_SCC_II,
-   .nubus_type = MAC_NUBUS,
+   .expansion_type = MAC_EXP_NUBUS,
.floppy_type= MAC_FLOPPY_SWIM_ADDR2,
}, {
.ident  = MAC_MODEL_IIFX,
@@ -281,7 +281,7 @@ static struct mac_model mac_data_table[] = {
.via_type   = MAC_VIA_IICI,
.scsi_type  = MAC_SCSI_IIFX,
.scc_type   = MAC_SCC_IOP,
-   .nubus_type = MAC_NUBUS,
+   .expansion_type = MAC_EXP_PDS_NUBUS,
.floppy_type= MAC_FLOPPY_SWIM_IOP,
}, {
.ident  = MAC_MODEL_IISI,
@@ -290,7 +290,7 @@ static struct mac_model mac_data_table[] = {
.via_type   = MAC_VIA_IICI,
.scsi_type  = MAC_SCSI_OLD,
.scc_type   = MAC_SCC_II,
-   .nubus_type = MAC_NUBUS,
+   .expansion_type = MAC_EXP_PDS_NUBUS,
.floppy_type= MAC_FLOPPY_SWIM_ADDR2,
}, {
.ident  = MAC_MODEL_IIVI,
@@ -299,7 +299,7 @@ static struct mac_model mac_data_table[] = {
.via_type   = MAC_VIA_IICI,
.scsi_type  = MAC_SCSI_LC,
.scc_type   = MAC_

[PATCH 12/14] nubus: Rename struct nubus_dev

2017-11-10 Thread Finn Thain
It is misleading to use "dev" to mean a functional resource. And
in adopting the Linux Driver Model, struct nubus_board will embed a
struct device. Drivers will then bind with boards, not with functional
resources.

Rename struct nubus_dev as struct nubus_functional_resource. This is
the vendor's terminology and avoids confusion.

Cc: Bartlomiej Zolnierkiewicz 
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/net/ethernet/8390/mac8390.c |  12 ++--
 drivers/net/ethernet/natsemi/macsonic.c |   4 +-
 drivers/nubus/nubus.c   | 105 
 drivers/nubus/proc.c|  15 ++---
 drivers/video/fbdev/macfb.c |   2 +-
 include/linux/nubus.h   |  31 +-
 6 files changed, 86 insertions(+), 83 deletions(-)

diff --git a/drivers/net/ethernet/8390/mac8390.c 
b/drivers/net/ethernet/8390/mac8390.c
index 9497f18eaba0..0367c9ada7c6 100644
--- a/drivers/net/ethernet/8390/mac8390.c
+++ b/drivers/net/ethernet/8390/mac8390.c
@@ -123,7 +123,8 @@ enum mac8390_access {
 };
 
 extern int mac8390_memtest(struct net_device *dev);
-static int mac8390_initdev(struct net_device *dev, struct nubus_dev *ndev,
+static int mac8390_initdev(struct net_device *dev,
+  struct nubus_functional_resource *ndev,
   enum mac8390_type type);
 
 static int mac8390_open(struct net_device *dev);
@@ -169,7 +170,7 @@ static void word_memcpy_tocard(unsigned long tp, const void 
*fp, int count);
 static void word_memcpy_fromcard(void *tp, unsigned long fp, int count);
 static u32 mac8390_msg_enable;
 
-static enum mac8390_type __init mac8390_ident(struct nubus_dev *dev)
+static enum mac8390_type __init mac8390_ident(struct nubus_functional_resource 
*dev)
 {
switch (dev->dr_sw) {
case NUBUS_DRSW_3COM:
@@ -289,7 +290,8 @@ static int __init mac8390_memsize(unsigned long membase)
return i * 0x1000;
 }
 
-static bool __init mac8390_init(struct net_device *dev, struct nubus_dev *ndev,
+static bool __init mac8390_init(struct net_device *dev,
+   struct nubus_functional_resource *ndev,
enum mac8390_type cardtype)
 {
struct nubus_dir dir;
@@ -394,7 +396,7 @@ static bool __init mac8390_init(struct net_device *dev, 
struct nubus_dev *ndev,
 struct net_device * __init mac8390_probe(int unit)
 {
struct net_device *dev;
-   struct nubus_dev *ndev = NULL;
+   struct nubus_functional_resource *ndev = NULL;
int err = -ENODEV;
struct ei_device *ei_local;
 
@@ -489,7 +491,7 @@ static const struct net_device_ops mac8390_netdev_ops = {
 };
 
 static int __init mac8390_initdev(struct net_device *dev,
- struct nubus_dev *ndev,
+ struct nubus_functional_resource *ndev,
  enum mac8390_type type)
 {
static u32 fwrd4_offsets[16] = {
diff --git a/drivers/net/ethernet/natsemi/macsonic.c 
b/drivers/net/ethernet/natsemi/macsonic.c
index 3ca6ae7caf55..963c96f6eca7 100644
--- a/drivers/net/ethernet/natsemi/macsonic.c
+++ b/drivers/net/ethernet/natsemi/macsonic.c
@@ -427,7 +427,7 @@ static int mac_nubus_sonic_ethernet_addr(struct net_device 
*dev,
return 0;
 }
 
-static int macsonic_ident(struct nubus_dev *ndev)
+static int macsonic_ident(struct nubus_functional_resource *ndev)
 {
if (ndev->dr_hw == NUBUS_DRHW_ASANTE_LC &&
ndev->dr_sw == NUBUS_DRSW_SONIC_LC)
@@ -455,7 +455,7 @@ static int macsonic_ident(struct nubus_dev *ndev)
 static int mac_nubus_sonic_probe(struct net_device *dev)
 {
static int slots;
-   struct nubus_dev* ndev = NULL;
+   struct nubus_functional_resource *ndev = NULL;
struct sonic_local* lp = netdev_priv(dev);
unsigned long base_addr, prom_addr;
u16 sonic_dcr;
diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index 16cbdd45dbbc..cc9dba4b4f01 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -31,7 +31,7 @@
 
 /* Globals */
 
-struct nubus_dev *nubus_devices;
+struct nubus_functional_resource *nubus_func_rsrcs;
 struct nubus_board *nubus_boards;
 
 /* Meaning of "bytelanes":
@@ -228,12 +228,12 @@ int nubus_get_root_dir(const struct nubus_board *board,
 EXPORT_SYMBOL(nubus_get_root_dir);
 
 /* This is a slyly renamed version of the above */
-int nubus_get_func_dir(const struct nubus_dev *dev,
+int nubus_get_func_dir(const struct nubus_functional_resource *fres,
   struct nubus_dir *dir)
 {
-   dir->ptr = dir->base = dev->directory;
+   dir->ptr = dir->base = fres->directory;
dir->done = 0;
-   dir->mask = dev->board->lanes;
+   dir->mask = fres->board->lanes;
return 0;
 }
 EXPORT_SYMBOL(nubus_get_func_dir);
@@ -306,11 +306,12 @@ EXPORT_SYMBOL(nubus_rewinddir);
 
 /* Driver interface functions, more or less like in pci.c */
 
-struct nubus_dev*
+struc

[PATCH 03/14] nubus: Use static functions where possible

2017-11-10 Thread Finn Thain
This fixes a couple of warnings from 'make W=1':
drivers/nubus/nubus.c:790: warning: no previous prototype for 'nubus_probe_slot'
drivers/nubus/nubus.c:824: warning: no previous prototype for 'nubus_scan_bus'

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/nubus/nubus.c | 4 ++--
 include/linux/nubus.h | 1 -
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index afbea40512a3..8272d5a5d769 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -792,7 +792,7 @@ static struct nubus_board * __init nubus_add_board(int 
slot, int bytelanes)
return board;
 }
 
-void __init nubus_probe_slot(int slot)
+static void __init nubus_probe_slot(int slot)
 {
unsigned char dp;
unsigned char *rp;
@@ -826,7 +826,7 @@ void __init nubus_probe_slot(int slot)
}
 }
 
-void __init nubus_scan_bus(void)
+static void __init nubus_scan_bus(void)
 {
int slot;
 
diff --git a/include/linux/nubus.h b/include/linux/nubus.h
index b72340df081c..3b7d1d4860ef 100644
--- a/include/linux/nubus.h
+++ b/include/linux/nubus.h
@@ -91,7 +91,6 @@ extern struct nubus_dev* nubus_devices;
 extern struct nubus_board* nubus_boards;
 
 /* Generic NuBus interface functions, modelled after the PCI interface */
-void nubus_scan_bus(void);
 #ifdef CONFIG_PROC_FS
 extern void nubus_proc_init(void);
 #else
-- 
2.13.6



[PATCH 02/14] nubus: Fix up header split

2017-11-10 Thread Finn Thain
Due to the '#ifdef __KERNEL__' being located in the wrong place, some
definitions from the kernel API were placed in the UAPI header during
the scripted header split. Fix this. Also, remove the duplicate comment
which is only relevant to the UAPI header.

Fixes: 607ca46e97a1 ("UAPI: (Scripted) Disintegrate include/linux")
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 include/linux/nubus.h  | 27 +++
 include/uapi/linux/nubus.h | 23 ---
 2 files changed, 23 insertions(+), 27 deletions(-)

diff --git a/include/linux/nubus.h b/include/linux/nubus.h
index b5c4683737e3..b72340df081c 100644
--- a/include/linux/nubus.h
+++ b/include/linux/nubus.h
@@ -4,16 +4,28 @@
   Originally written by Alan Cox.
 
   Hacked to death by C. Scott Ananian and David Huggins-Daines.
-  
-  Some of the constants in here are from the corresponding
-  NetBSD/OpenBSD header file, by Allen Briggs.  We figured out the
-  rest of them on our own. */
+*/
+
 #ifndef LINUX_NUBUS_H
 #define LINUX_NUBUS_H
 
 #include 
 #include 
 
+struct nubus_dir {
+   unsigned char *base;
+   unsigned char *ptr;
+   int done;
+   int mask;
+};
+
+struct nubus_dirent {
+   unsigned char *base;
+   unsigned char type;
+   __u32 data; /* Actually 24 bits used */
+   int mask;
+};
+
 struct nubus_board {
struct nubus_board* next;
struct nubus_dev* first_dev;
@@ -129,4 +141,11 @@ void nubus_get_rsrc_mem(void *dest, const struct 
nubus_dirent *dirent,
 unsigned int len);
 void nubus_get_rsrc_str(char *dest, const struct nubus_dirent *dirent,
 unsigned int maxlen);
+
+/* Returns a pointer to the "standard" slot space. */
+static inline void *nubus_slot_addr(int slot)
+{
+   return (void *)(0xF000 | (slot << 24));
+}
+
 #endif /* LINUX_NUBUS_H */
diff --git a/include/uapi/linux/nubus.h b/include/uapi/linux/nubus.h
index ac516064f0ee..7dc64eb4dc4d 100644
--- a/include/uapi/linux/nubus.h
+++ b/include/uapi/linux/nubus.h
@@ -220,27 +220,4 @@ enum nubus_display_res_id {
NUBUS_RESID_SIXTHMODE   = 0x0085
 };
 
-struct nubus_dir
-{
-   unsigned char *base;
-   unsigned char *ptr;
-   int done;
-   int mask;
-};
-
-struct nubus_dirent
-{
-   unsigned char *base;
-   unsigned char type;
-   __u32 data; /* Actually 24bits used */
-   int mask;
-};
-
-
-/* We'd like to get rid of this eventually.  Only daynaport.c uses it now. */
-static inline void *nubus_slot_addr(int slot)
-{
-   return (void *)(0xF000|(slot<<24));
-}
-
 #endif /* _UAPILINUX_NUBUS_H */
-- 
2.13.6



[PATCH 01/14] nubus: Avoid array underflow and overflow

2017-11-10 Thread Finn Thain
Check array indices. Avoid sprintf. Use buffers of sufficient size.
Use appropriate types for the parameters to nubus_get_rsrc_{mem,str}()
functions.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/nubus/nubus.c | 29 +
 drivers/nubus/proc.c  | 12 ++--
 include/linux/nubus.h | 10 --
 3 files changed, 27 insertions(+), 24 deletions(-)

diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index 4f50f30650cd..afbea40512a3 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -160,7 +160,7 @@ static unsigned char *nubus_dirptr(const struct 
nubus_dirent *nd)
pointed to with offsets) out of the card ROM. */
 
 void nubus_get_rsrc_mem(void *dest, const struct nubus_dirent *dirent,
-   int len)
+unsigned int len)
 {
unsigned char *t = (unsigned char *)dest;
unsigned char *p = nubus_dirptr(dirent);
@@ -172,18 +172,22 @@ void nubus_get_rsrc_mem(void *dest, const struct 
nubus_dirent *dirent,
 }
 EXPORT_SYMBOL(nubus_get_rsrc_mem);
 
-void nubus_get_rsrc_str(void *dest, const struct nubus_dirent *dirent,
-   int len)
+void nubus_get_rsrc_str(char *dest, const struct nubus_dirent *dirent,
+unsigned int len)
 {
-   unsigned char *t = (unsigned char *)dest;
+   char *t = dest;
unsigned char *p = nubus_dirptr(dirent);
 
-   while (len) {
-   *t = nubus_get_rom(&p, 1, dirent->mask);
-   if (!*t++)
+   while (len > 1) {
+   unsigned char c = nubus_get_rom(&p, 1, dirent->mask);
+
+   if (!c)
break;
+   *t++ = c;
len--;
}
+   if (len > 0)
+   *t = '\0';
 }
 EXPORT_SYMBOL(nubus_get_rsrc_str);
 
@@ -467,7 +471,7 @@ nubus_get_functional_resource(struct nubus_board *board, 
int slot,
}
case NUBUS_RESID_NAME:
{
-   nubus_get_rsrc_str(dev->name, &ent, 64);
+   nubus_get_rsrc_str(dev->name, &ent, sizeof(dev->name));
pr_info("name: %s\n", dev->name);
break;
}
@@ -527,7 +531,7 @@ static int __init nubus_get_vidnames(struct nubus_board 
*board,
/* Don't know what this is yet */
u16 id;
/* Longest one I've seen so far is 26 characters */
-   char name[32];
+   char name[36];
};
 
pr_info("video modes supported:\n");
@@ -597,8 +601,8 @@ static int __init nubus_get_vendorinfo(struct nubus_board 
*board,
char name[64];
 
/* These are all strings, we think */
-   nubus_get_rsrc_str(name, &ent, 64);
-   if (ent.type > 5)
+   nubus_get_rsrc_str(name, &ent, sizeof(name));
+   if (ent.type < 1 || ent.type > 5)
ent.type = 5;
pr_info("%s: %s\n", vendor_fields[ent.type - 1], name);
}
@@ -632,7 +636,8 @@ static int __init nubus_get_board_resource(struct 
nubus_board *board, int slot,
break;
}
case NUBUS_RESID_NAME:
-   nubus_get_rsrc_str(board->name, &ent, 64);
+   nubus_get_rsrc_str(board->name, &ent,
+  sizeof(board->name));
pr_info("name: %s\n", board->name);
break;
case NUBUS_RESID_ICON:
diff --git a/drivers/nubus/proc.c b/drivers/nubus/proc.c
index e8f68f5732f1..a74e713a4f7f 100644
--- a/drivers/nubus/proc.c
+++ b/drivers/nubus/proc.c
@@ -72,10 +72,10 @@ static void nubus_proc_subdir(struct nubus_dev* dev,
 
/* Some of these are directories, others aren't */
while (nubus_readdir(dir, &ent) != -1) {
-   char name[8];
+   char name[9];
struct proc_dir_entry* e;

-   sprintf(name, "%x", ent.type);
+   snprintf(name, sizeof(name), "%x", ent.type);
e = proc_create(name, S_IFREG | S_IRUGO | S_IWUSR, parent,
&nubus_proc_subdir_fops);
if (!e)
@@ -94,11 +94,11 @@ static void nubus_proc_populate(struct nubus_dev* dev,
/* We know these are all directories (board resource + one or
   more functional resources) */
while (nubus_readdir(root, &ent) != -1) {
-   char name[8];
+   char name[9];
struct proc_dir_entry* e;
struct nubus_dir dir;

-   sprintf(name, "%x", ent.type);
+   snprintf(name, sizeof(name), "%x", ent.type);
e = proc_mkdir(name, parent);
if (!e) return;
 
@@ -118,7 +118,7 @@ int nubus_proc_attach_device(struct nubus_dev *dev)
 {
 

[PATCH 04/14] nubus: Fix log spam

2017-11-10 Thread Finn Thain
Testing shows that a single Radius PrecisionColor 24X display board,
which has 95 functional resources, produces over a thousand lines of
log messages. Suppress these messages with pr_debug().
Remove some redundant messages relating to nubus_get_subdir() calls.
Fix the format block debug messages which has the sequence of entries
backwards (my bad).
Move the "Scanning slots" message to its proper location.

Fixes: 71ae40e4cf33 ("nubus: Clean up printk calls")
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/nubus/nubus.c | 124 +-
 1 file changed, 53 insertions(+), 71 deletions(-)

diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index 8272d5a5d769..5607e58d5ca2 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -352,15 +352,15 @@ static int __init nubus_show_display_resource(struct 
nubus_dev *dev,
 {
switch (ent->type) {
case NUBUS_RESID_GAMMADIR:
-   pr_info("gamma directory offset: 0x%06x\n", ent->data);
+   pr_debug("gamma directory offset: 0x%06x\n", ent->data);
break;
case 0x0080 ... 0x0085:
-   pr_info("mode %02X info offset: 0x%06x\n",
-  ent->type, ent->data);
+   pr_debug("mode 0x%02x info offset: 0x%06x\n",
+   ent->type, ent->data);
break;
default:
-   pr_info("unknown resource %02X, data 0x%06x\n",
-  ent->type, ent->data);
+   pr_debug("unknown resource 0x%02x, data 0x%06x\n",
+   ent->type, ent->data);
}
return 0;
 }
@@ -374,12 +374,12 @@ static int __init nubus_show_network_resource(struct 
nubus_dev *dev,
char addr[6];
 
nubus_get_rsrc_mem(addr, ent, 6);
-   pr_info("MAC address: %pM\n", addr);
+   pr_debug("MAC address: %pM\n", addr);
break;
}
default:
-   pr_info("unknown resource %02X, data 0x%06x\n",
-  ent->type, ent->data);
+   pr_debug("unknown resource 0x%02x, data 0x%06x\n",
+   ent->type, ent->data);
}
return 0;
 }
@@ -393,8 +393,8 @@ static int __init nubus_show_cpu_resource(struct nubus_dev 
*dev,
unsigned long meminfo[2];
 
nubus_get_rsrc_mem(&meminfo, ent, 8);
-   pr_info("memory: [ 0x%08lx 0x%08lx ]\n",
-  meminfo[0], meminfo[1]);
+   pr_debug("memory: [ 0x%08lx 0x%08lx ]\n",
+   meminfo[0], meminfo[1]);
break;
}
case NUBUS_RESID_ROMINFO:
@@ -402,13 +402,13 @@ static int __init nubus_show_cpu_resource(struct 
nubus_dev *dev,
unsigned long rominfo[2];
 
nubus_get_rsrc_mem(&rominfo, ent, 8);
-   pr_info("ROM:[ 0x%08lx 0x%08lx ]\n",
-  rominfo[0], rominfo[1]);
+   pr_debug("ROM:[ 0x%08lx 0x%08lx ]\n",
+   rominfo[0], rominfo[1]);
break;
}
default:
-   pr_info("unknown resource %02X, data 0x%06x\n",
-  ent->type, ent->data);
+   pr_debug("unknown resource 0x%02x, data 0x%06x\n",
+   ent->type, ent->data);
}
return 0;
 }
@@ -427,8 +427,8 @@ static int __init nubus_show_private_resource(struct 
nubus_dev *dev,
nubus_show_cpu_resource(dev, ent);
break;
default:
-   pr_info("unknown resource %02X, data 0x%06x\n",
-  ent->type, ent->data);
+   pr_debug("unknown resource 0x%02x, data 0x%06x\n",
+   ent->type, ent->data);
}
return 0;
 }
@@ -441,12 +441,9 @@ nubus_get_functional_resource(struct nubus_board *board, 
int slot,
struct nubus_dirent ent;
struct nubus_dev *dev;
 
-   pr_info("  Function 0x%02x:\n", parent->type);
+   pr_debug("  Functional resource 0x%02x:\n", parent->type);
nubus_get_subdir(parent, &dir);
 
-   pr_debug("%s: parent is 0x%p, dir is 0x%p\n",
-__func__, parent->base, dir.base);
-
/* Actually we should probably panic if this fails */
if ((dev = kzalloc(sizeof(*dev), GFP_ATOMIC)) == NULL)
return NULL;
@@ -465,14 +462,14 @@ nubus_get_functional_resource(struct nubus_board *board, 
int slot,
dev->type = nbtdata[1];
dev->dr_sw= nbtdata[2];
dev->dr_hw= nbtdata[3];
-   pr_info("type: [cat 0x%x type 0x%x sw 0x%x hw 
0x%x]\n",
-   nbtdata[0], nbtdata[1], nbtdata[2], nbtdata[3]);
+   pr_debug("type: [cat 0x%x type 0x%x sw 0x%x

Re: [PATCH net-next 1/2] net/ncsi: Improve general state logging

2017-11-10 Thread David Miller
From: Samuel Mendoza-Jonas 
Date: Wed,  8 Nov 2017 16:30:44 +1100

> The NCSI driver is mostly silent which becomes a headache when trying to
> determine what has occurred on the NCSI connection. This adds additional
> logging in a few key areas such as state transitions and calling out
> certain errors more visibly.
> 
> Signed-off-by: Samuel Mendoza-Jonas 

Applied.


Re: [PATCH net-next 2/2] net/ncsi: Don't return error on normal response

2017-11-10 Thread David Miller
From: Samuel Mendoza-Jonas 
Date: Wed,  8 Nov 2017 16:30:45 +1100

> Several response handlers return EBUSY if the data corresponding to the
> command/response pair is already set. There is no reason to return an
> error here; the channel is advertising something as enabled because we
> told it to enable it, and it's possible that the feature has been
> enabled previously.
> 
> Signed-off-by: Samuel Mendoza-Jonas 

Applied.


[PATCH] drivers: base: omit redundant interations

2017-11-10 Thread Gimcuan Hui
When error happens, these interators return the error, no interation should
be continued, so make the change for getting out of while immediately.

Signed-off-by: Gimcuan Hui 
---
 drivers/base/bus.c| 2 +-
 drivers/base/core.c   | 2 +-
 drivers/base/driver.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 22a64fd3309b..40b118586434 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -309,7 +309,7 @@ int bus_for_each_dev(struct bus_type *bus, struct device 
*start,
 
klist_iter_init_node(&bus->p->klist_devices, &i,
 (start ? &start->p->knode_bus : NULL));
-   while ((dev = next_device(&i)) && !error)
+   while (!error && (dev = next_device(&i)))
error = fn(dev, data);
klist_iter_exit(&i);
return error;
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 12ebd055724c..725ade87cbeb 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -2116,7 +2116,7 @@ int device_for_each_child(struct device *parent, void 
*data,
return 0;
 
klist_iter_init(&parent->p->klist_children, &i);
-   while ((child = next_device(&i)) && !error)
+   while (!error && (child = next_device(&i)))
error = fn(child, data);
klist_iter_exit(&i);
return error;
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 4eabfe28d2b3..11832dc88a7a 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -52,7 +52,7 @@ int driver_for_each_device(struct device_driver *drv, struct 
device *start,
 
klist_iter_init_node(&drv->p->klist_devices, &i,
 start ? &start->p->knode_driver : NULL);
-   while ((dev = next_device(&i)) && !error)
+   while (!error && (dev = next_device(&i)))
error = fn(dev, data);
klist_iter_exit(&i);
return error;
-- 
2.11.0



[PATCH 1/2] Input: ili210x - use managed allocated resources

2017-11-10 Thread Andi Shyti
Use managed allocated resources to simplify error handling during
probing.

Adjust goto labels and remove function accordingly.

Signed-off-by: Andi Shyti 
---
 drivers/input/touchscreen/ili210x.c | 36 +++-
 1 file changed, 11 insertions(+), 25 deletions(-)

diff --git a/drivers/input/touchscreen/ili210x.c 
b/drivers/input/touchscreen/ili210x.c
index 6f76eeedf465..da868b1d0e83 100644
--- a/drivers/input/touchscreen/ili210x.c
+++ b/drivers/input/touchscreen/ili210x.c
@@ -224,12 +224,10 @@ static int ili210x_i2c_probe(struct i2c_client *client,
xmax = panel.finger_max.x_low | (panel.finger_max.x_high << 8);
ymax = panel.finger_max.y_low | (panel.finger_max.y_high << 8);
 
-   priv = kzalloc(sizeof(*priv), GFP_KERNEL);
-   input = input_allocate_device();
-   if (!priv || !input) {
-   error = -ENOMEM;
-   goto err_free_mem;
-   }
+   priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL);
+   input = devm_input_allocate_device(&client->dev);
+   if (!priv || !input)
+   return -ENOMEM;
 
priv->client = client;
priv->input = input;
@@ -258,25 +256,26 @@ static int ili210x_i2c_probe(struct i2c_client *client,
 
i2c_set_clientdata(client, priv);
 
-   error = request_irq(client->irq, ili210x_irq, pdata->irq_flags,
-   client->name, priv);
+   error = devm_request_irq(&client->dev, client->irq,
+ili210x_irq, pdata->irq_flags,
+client->name, priv);
if (error) {
dev_err(dev, "Unable to request touchscreen IRQ, err: %d\n",
error);
-   goto err_free_mem;
+   return error;
}
 
-   error = sysfs_create_group(&dev->kobj, &ili210x_attr_group);
+   error = devm_device_add_group(&client->dev, &ili210x_attr_group);
if (error) {
dev_err(dev, "Unable to create sysfs attributes, err: %d\n",
error);
-   goto err_free_irq;
+   return error;
}
 
error = input_register_device(priv->input);
if (error) {
dev_err(dev, "Cannot register input device, err: %d\n", error);
-   goto err_remove_sysfs;
+   return error;
}
 
device_init_wakeup(dev, 1);
@@ -286,26 +285,13 @@ static int ili210x_i2c_probe(struct i2c_client *client,
client->irq, firmware.id, firmware.major, firmware.minor);
 
return 0;
-
-err_remove_sysfs:
-   sysfs_remove_group(&dev->kobj, &ili210x_attr_group);
-err_free_irq:
-   free_irq(client->irq, priv);
-err_free_mem:
-   input_free_device(input);
-   kfree(priv);
-   return error;
 }
 
 static int ili210x_i2c_remove(struct i2c_client *client)
 {
struct ili210x *priv = i2c_get_clientdata(client);
 
-   sysfs_remove_group(&client->dev.kobj, &ili210x_attr_group);
-   free_irq(priv->client->irq, priv);
cancel_delayed_work_sync(&priv->dwork);
-   input_unregister_device(priv->input);
-   kfree(priv);
 
return 0;
 }
-- 
2.15.0



Re: [kernel-hardening] Re: vDSO maximum stack usage, stack probes, and -fstack-check

2017-11-10 Thread Hector Martin 'marcan'
On 2017-11-11 07:04, Andy Lutomirski wrote:
>> On Nov 10, 2017, at 8:36 AM, Hector Martin 'marcan'  wrote:
>>
>>> On 2017-11-11 01:02, Hector Martin 'marcan' wrote:
>>> Not entirely sure what's going on here.
>>
>> Actually, if you think about it, it doesn't matter that it skips the
>> first page, since it's probing one page more. That just means the caller
>> will have probed the previous page. So ultimately you're just probing
>> ahead of where you need to, but that should be OK.
>>
> 
> The whole point is to touch the stack pages in order.  Also, I see no
> guarantee that the function would touch the intermediate page before
> clobbering the probed page.  You're seeing exactly that behavior, in
> fact.

Only because Go is not C and is not compiled like this. If all the code
is GCC-compiled C code and built with -fstack-check, it should always
probe stack pages in order except for potentially the second page in the
stack, which may be touched after the third page (but hopefully your
stack is at least two pages long to begin with).

AIUI -fstack-check was not intended for stack clash protection (the
latter isn't even in a GCC release yet), but in most circumstances it
seems to me like it's an effective mitigation if all code is compiled
with it. Qualys mentioned it as such in their advisory. This is probably
why Gentoo Hardened enables it by default globally in their toolchain.

-- 
Hector Martin "marcan" (mar...@marcan.st)
Public Key: https://mrcn.st/pub


[PATCH 2/2] Input: ili210x - use separate error handling for different allocators

2017-11-10 Thread Andi Shyti
Split the error between devm_kzalloc and
devm_input_allocate_device, there is no need to call the second
allocator if the first has failed. Besides this doesn't provide
practical advantages.

Signed-off-by: Andi Shyti 
---
 drivers/input/touchscreen/ili210x.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/input/touchscreen/ili210x.c 
b/drivers/input/touchscreen/ili210x.c
index da868b1d0e83..9344c4436430 100644
--- a/drivers/input/touchscreen/ili210x.c
+++ b/drivers/input/touchscreen/ili210x.c
@@ -225,8 +225,11 @@ static int ili210x_i2c_probe(struct i2c_client *client,
ymax = panel.finger_max.y_low | (panel.finger_max.y_high << 8);
 
priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL);
+   if (!priv)
+   return -ENOMEM;
+
input = devm_input_allocate_device(&client->dev);
-   if (!priv || !input)
+   if (!input)
return -ENOMEM;
 
priv->client = client;
-- 
2.15.0



[PATCH 0/2] managed resources for ili210x

2017-11-10 Thread Andi Shyti
Hi Dmitry,

this is another patch of my series for switching the
touchscreen drivers to to the managed resource allocators.

The second patch is very trivial and perhaps bothering only me,
feel free to ignore.

Thanks,
Andi

Andi Shyti (2):
  Input: ili210x - use managed allocated resources
  Input: ili210x - use separate error handling for different allocators

 drivers/input/touchscreen/ili210x.c | 39 +
 1 file changed, 14 insertions(+), 25 deletions(-)

-- 
2.15.0



Re: [PATCHv4 5/6] symbol lookup: introduce dereference_symbol_descriptor()

2017-11-10 Thread Sergey Senozhatsky
On (11/10/17 10:09), Luck, Tony wrote:
> On Fri, Nov 10, 2017 at 08:48:29AM +0900, Sergey Senozhatsky wrote:
> > -Examples::
> > -
> > -   printk("Going to call: %pF\n", gettimeofday);
> > -   printk("Going to call: %pF\n", p->func);
> > -   printk("%s: called from %pS\n", __func__, (void *)_RET_IP_);
> > -   printk("%s: called from %pS\n", __func__,
> > -   (void *)__builtin_return_address(0));
> > -   printk("Faulted at %pS\n", (void *)regs->ip);
> > -   printk(" %s%pB\n", (reliable ? "" : "? "), (void *)*stack);
> 
> Did you mean to delete the Examples completely?  Wouldn't it
> be better to just update (s/%pF/%pS/g)?

good question. yes, I think I did it deliberately :) we still
kinda have some sort of "examples", right at the beginning of
section "Symbols/Function Pointers"


>  Symbols/Function Pointers
>  =
>
>  ::
>
> %pS versatile_init+0x0/0x110
>  %ps versatile_init
>  %pF versatile_init+0x0/0x110
>  %pf versatile_init
>  %pSRversatile_init+0x9/0x110
> (with __builtin_extract_return_addr() translation)
>  %pB prev_fn_of_versatile_init+0x88/0x88
>
>  The ``S`` and ``s`` specifiers are used for printing a pointer in symbolic
>  format. They result in the symbol name with (``S``) or without (``s``)
>  offsets. If KALLSYMS are disabled then the symbol address is printed instead.
>
>  Note, that the ``F`` and ``f`` specifiers are identical to ``S`` (``s``)
>  and thus deprecated. We have ``F`` and ``f`` because on ia64, ppc64 and
>  parisc64 function pointers are indirect and, in fact, are function
>  descriptors, which require additional dereferencing before we can lookup
>  the symbol. As of now, ``S`` and ``s`` perform dereferencing on those
>  platforms (when needed), so ``F`` and ``f`` exist for compatibility
>  reasons only.
>
>  The ``B`` specifier results in the symbol name with offsets and should be
>  used when printing stack backtraces. The specifier takes into
>  consideration the effect of compiler optimisations which may occur
>  when tail-call``s are used and marked with the noreturn GCC attribute.

I can return Examples back. don't really have a strong opinion
on this. let me know.

-ss


WireGuard Upstreaming Roadmap (November 2017)

2017-11-10 Thread Jason A. Donenfeld
Hi folks,

This relates to WireGuard [0].

Following a very nice conference with the Linux kernel networking subsystem
community [1,2], I thought it might be a good idea to spell out the roadmap
for the coming months and the trajectory into upstream, based on my
discussions with several developers and maintainers. There are several threads
of this, the biggest of which surrounds the kernel code base, but there are
some other ends of the WireGuard project as a whole that are also relevant.

The current biggest blocker is issues with the crypto API. Before WireGuard
can go upstream, I intend to embark on a multi-pronged effort to overhaul the
crypto API. I very much need to sync up with Herbert regarding my plans for
this, and start spec'ing things out a bit more formally, so I can begin
concrete discussions with him. I intend to base my work both on feedback
from linux-crypto/Herbert and from the cryptographic research community. I
hope to go to RWC2018 [3] and the subsequent HACS workshop for the academic
engagement side, but of course like all the work I do on the kernel, things
will be highly based in engineering, rather than purely academic, practices.

Dave has strongly encouraged me to post patches sooner rather than later.
So I think before the crypto API is ready to go, I'll likely post a [RFG] --
request for grumbles -- patch set to netdev, in order to have some code
review, so as to gauge where we're at. This patch set will use my current
crypto API, not the kernel's crypto API, with it mentioned in the opening that
I intend to switch to the kernel's crypto API when it looks like the one used
here. This way we'll get early feedback so that the later real [PATCH] series
will go more smoothly.

There are a few WireGuard features that some of you have been waiting for. At
the urging of some folks at the conference, I intend to submit a "core"
WireGuard to upstream, and then use future releases to build on top of that,
to make the initial upstreaming process go as easily as possible. Therefore,
there are three big TODO items that may _or_ may not go in after upstreaming:

 - In-band control messages [possibly not]
 - Netlink multicast event notification
 - GRO integration

Of these, it's most likely I'll implement GRO and leave the other two until
after, but this may change. Since WireGuard already does GSO, it would make
sense to implement the other side of things too. There's also a longer more
ambitious roadmap [4], filled with both easy coding-related things and longer
term design things, but that's out of scope for this email, though many of
which will likely be completed before submission time.

There are also six other threads of development that are ongoing, which I
intend to put a bit more focus on too in the near future:

  - The userspace implementation. I'd like to bring this up to deployment
quality, which naturally fits into the next area.

  - Mobile apps. It's fairly easy to integrate the userspace implementation
with existing APIs. The current Android app already works well with the
kernel module, but of course people want this more easily deployed.

  - Mac and Windows support for the userspace implementation. These are
already mostly done, but the APIs used may in fact change, so there may
still be a bit of work to do here before we're satisfied.

  - Bindings and libraries. Now that we have a stable Netlink API, we can
start making nice wrappers for the various languages people like to use.
It remains to be seen whether or not a C "libwireguard" is needed, since in
that domain, talking Netlink directly is often a better choice, but I do see
some potential for a pywireguard and the like. This will also be essential
when the already mentioned plans for event notification and the possibly
excluded control messages materialize.

  - More formal verification. While we have the cryptographic protocol
verified, there are still more places where formalism is quite helpful,
proving more state machines, and even proving C implementations to be
correct. Work and research is ongoing in this domain.

  - Integration into network managers and routing daemons (mesh and
traditional). Work has already begun here on systemd-networkd, and others
are looking into daemons like babel and bird.

So that's where we're at. I hope to have a RFG submitted in the next several
months, and hopefully we gather some nice momentum and get the work
upstreamed and the project completed soon, for some definition of "complete".

If you'd like to work on WireGuard, or simply have any questions, don't
hesitate to email me.

Regards,
Jason


[0] https://www.wireguard.com/
[1] https://www.netdevconf.org/2.2/
[2] https://www.wireguard.com/presentations/
[3] https://rwc.iacr.org
[4] https://www.wireguard.com/todo/


Re: [PATCH v6 0/2] add support for the Samsung S6SY761 touchscreen

2017-11-10 Thread Andi Shyti
> On Wed, Nov 08, 2017 at 05:21:03PM +0900, Andi Shyti wrote:
> > Hi,
> > 
> > This patchset adds support for the Samsung s6sy761 touchscreen.
> > 
> > Thanks,
> > Andi
> 
> Applied, thank you.

Thanks for your review :)

Andi


Re: [PATCHv4 0/6] printk/ia64/ppc64/parisc64: let's deprecate %pF/%pf printk specifiers

2017-11-10 Thread Sergey Senozhatsky
On (11/10/17 10:11), Luck, Tony wrote:
> On Fri, Nov 10, 2017 at 08:48:24AM +0900, Sergey Senozhatsky wrote:
> > All Ack-s/Tested-by-s were dropped, since the patch set has been
> > reworked. I'm kindly asking arch-s maintainers and developers to test it
> > once again. Sorry for any inconveniences and thanks for your help in
> > advance.
> 
> You can add back the:
> 
> Tested-by: Tony Luck  #ia64

Thanks a ton, Tony!

-ss


Re: [RFC 5/7] x86/asm: Rearrange struct cpu_tss to enlarge SYSENTER_stack and fix alignment

2017-11-10 Thread Andy Lutomirski
On Fri, Nov 10, 2017 at 8:05 PM, Andy Lutomirski  wrote:
> The Intel SDM says (Volume 3, 7.2.1):
>
>Avoid placing a page boundary in the part of the TSS that the
>processor reads during a task switch (the first 104 bytes). The
>processor may not correctly perform address translations if a
>boundary occurs in this area. During a task switch, the processor
>reads and writes into the first 104 bytes of each TSS (using
>contiguous physical addresses beginning with the physical address
>of the first byte of the TSS). So, after TSS access begins, if
>part of the 104 bytes is not physically contiguous, the processor
>will access incorrect information without generating a page-fault
>exception.

Hmm.  I should add that I suspect we rarely if ever hit this problem
in practice because (a) we only ever task switch on 32-bit
doublefaults, (b) if the old register state gets corrupted by this
issue during a doublefault, we might not notice, and (c) there is
probably rarely a page boundary in the wrong place.  I suspect that
regular kernel entries have the same issue but that esp0 and ss0 were
always in the same page due to cacheline alignment.

FWIW, we really do virtually map the percpu section AFAICT.  The code
does not appear to guarantee that percpu variables are physically
contiguous.

I'd love to make this mapping RO, but the SDM advises against that.  I
don't know whether there's a real concern (on 64-bit) or whether it's
just being overly cautious.


[RFC 1/7] x86/asm/64: Allocate and enable the SYSENTER stack

2017-11-10 Thread Andy Lutomirski
This will simplify some future code changes that will want some
temporary stack space in more places.  It also lets us get rid of a
SWAPGS_UNSAFE_STACK user.

This does not depend on CONFIG_IA32_EMULATION because we'll want the
stack space even without IA32 emulation.

Signed-off-by: Andy Lutomirski 
---
 arch/x86/entry/entry_64_compat.S | 2 +-
 arch/x86/include/asm/processor.h | 3 ---
 arch/x86/kernel/asm-offsets.c| 5 +
 arch/x86/kernel/asm-offsets_32.c | 5 -
 arch/x86/kernel/cpu/common.c | 4 +++-
 arch/x86/kernel/process.c| 2 --
 arch/x86/kernel/traps.c  | 3 +--
 7 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/arch/x86/entry/entry_64_compat.S b/arch/x86/entry/entry_64_compat.S
index 932b96ce1b06..36c508c21480 100644
--- a/arch/x86/entry/entry_64_compat.S
+++ b/arch/x86/entry/entry_64_compat.S
@@ -47,7 +47,7 @@
  */
 ENTRY(entry_SYSENTER_compat)
/* Interrupts are off on entry. */
-   SWAPGS_UNSAFE_STACK
+   SWAPGS
movqPER_CPU_VAR(cpu_current_top_of_stack), %rsp
 
/*
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index f10dae14f951..0644f888b12c 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -338,14 +338,11 @@ struct tss_struct {
 */
unsigned long   io_bitmap[IO_BITMAP_LONGS + 1];
 
-#ifdef CONFIG_X86_32
/*
 * Space for the temporary SYSENTER stack.
 */
unsigned long   SYSENTER_stack_canary;
unsigned long   SYSENTER_stack[64];
-#endif
-
 } cacheline_aligned;
 
 DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, cpu_tss);
diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
index de827d6ac8c2..031bd35bd911 100644
--- a/arch/x86/kernel/asm-offsets.c
+++ b/arch/x86/kernel/asm-offsets.c
@@ -92,4 +92,9 @@ void common(void) {
 
BLANK();
DEFINE(PTREGS_SIZE, sizeof(struct pt_regs));
+
+   /* Offset from cpu_tss to SYSENTER_stack */
+   OFFSET(CPU_TSS_SYSENTER_stack, tss_struct, SYSENTER_stack);
+   /* Size of SYSENTER_stack */
+   DEFINE(SIZEOF_SYSENTER_stack, sizeof(((struct tss_struct 
*)0)->SYSENTER_stack));
 }
diff --git a/arch/x86/kernel/asm-offsets_32.c b/arch/x86/kernel/asm-offsets_32.c
index 710edab9e644..6c683edf7015 100644
--- a/arch/x86/kernel/asm-offsets_32.c
+++ b/arch/x86/kernel/asm-offsets_32.c
@@ -49,11 +49,6 @@ void foo(void)
DEFINE(TSS_sysenter_sp0, offsetof(struct tss_struct, x86_tss.sp0) -
   offsetofend(struct tss_struct, SYSENTER_stack));
 
-   /* Offset from cpu_tss to SYSENTER_stack */
-   OFFSET(CPU_TSS_SYSENTER_stack, tss_struct, SYSENTER_stack);
-   /* Size of SYSENTER_stack */
-   DEFINE(SIZEOF_SYSENTER_stack, sizeof(((struct tss_struct 
*)0)->SYSENTER_stack));
-
 #ifdef CONFIG_CC_STACKPROTECTOR
BLANK();
OFFSET(stack_canary_offset, stack_canary, canary);
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index cdf79ab628c2..22f542170198 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -1361,7 +1361,9 @@ void syscall_init(void)
 * AMD doesn't allow SYSENTER in long mode (either 32- or 64-bit).
 */
wrmsrl_safe(MSR_IA32_SYSENTER_CS, (u64)__KERNEL_CS);
-   wrmsrl_safe(MSR_IA32_SYSENTER_ESP, 0ULL);
+   wrmsrl_safe(MSR_IA32_SYSENTER_ESP,
+   (unsigned long)this_cpu_ptr(&cpu_tss) +
+   offsetofend(struct tss_struct, SYSENTER_stack));
wrmsrl_safe(MSR_IA32_SYSENTER_EIP, (u64)entry_SYSENTER_compat);
 #else
wrmsrl(MSR_CSTAR, (unsigned long)ignore_sysret);
diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index ff8a9acbcf8b..b49c78b73699 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -70,9 +70,7 @@ __visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, 
cpu_tss) = {
  */
.io_bitmap  = { [0 ... IO_BITMAP_LONGS] = ~0 },
 #endif
-#ifdef CONFIG_X86_32
.SYSENTER_stack_canary  = STACK_END_MAGIC,
-#endif
 };
 EXPORT_PER_CPU_SYMBOL(cpu_tss);
 
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index 42a9c4458f5d..01a9e25ee9d8 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -790,14 +790,13 @@ dotraplinkage void do_debug(struct pt_regs *regs, long 
error_code)
debug_stack_usage_dec();
 
 exit:
-#if defined(CONFIG_X86_32)
/*
 * This is the most likely code path that involves non-trivial use
 * of the SYSENTER stack.  Check that we haven't overrun it.
 */
WARN(this_cpu_read(cpu_tss.SYSENTER_stack_canary) != STACK_END_MAGIC,
 "Overran or corrupted SYSENTER stack\n");
-#endif
+
ist_exit(regs);
 }
 NOKPROBE_SYMBOL(do_debug);
-- 
2.13.6



[RFC 4/7] x86/asm: Fix assumptions that the HW TSS is at the beginning of cpu_tss

2017-11-10 Thread Andy Lutomirski
I'm going to move SYSENTER_stack to the beginning of cpu_tss to help
detect overflow.  Before this can happen, I need to fix several code
paths that hardcode assumptions about the old layout.

Signed-off-by: Andy Lutomirski 
---
 arch/x86/include/asm/desc.h  |  2 +-
 arch/x86/include/asm/processor.h |  4 ++--
 arch/x86/kernel/cpu/common.c |  4 ++--
 arch/x86/kernel/doublefault.c| 36 +---
 arch/x86/power/cpu.c | 13 +++--
 5 files changed, 29 insertions(+), 30 deletions(-)

diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
index 92ad5c354d11..ad35544d9e00 100644
--- a/arch/x86/include/asm/desc.h
+++ b/arch/x86/include/asm/desc.h
@@ -177,7 +177,7 @@ static inline void set_tssldt_descriptor(void *d, unsigned 
long addr,
 #endif
 }
 
-static inline void __set_tss_desc(unsigned cpu, unsigned int entry, void *addr)
+static inline void __set_tss_desc(unsigned cpu, unsigned int entry, struct 
x86_hw_tss *addr)
 {
struct desc_struct *d = get_cpu_gdt_rw(cpu);
tss_desc tss;
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 0644f888b12c..301d41ca1fa1 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -161,7 +161,7 @@ enum cpuid_regs_idx {
 extern struct cpuinfo_x86  boot_cpu_data;
 extern struct cpuinfo_x86  new_cpu_data;
 
-extern struct tss_struct   doublefault_tss;
+extern struct x86_hw_tss   doublefault_tss;
 extern __u32   cpu_caps_cleared[NCAPINTS];
 extern __u32   cpu_caps_set[NCAPINTS];
 
@@ -321,7 +321,7 @@ struct x86_hw_tss {
 #define IO_BITMAP_BITS 65536
 #define IO_BITMAP_BYTES(IO_BITMAP_BITS/8)
 #define IO_BITMAP_LONGS(IO_BITMAP_BYTES/sizeof(long))
-#define IO_BITMAP_OFFSET   offsetof(struct tss_struct, io_bitmap)
+#define IO_BITMAP_OFFSET   (offsetof(struct tss_struct, io_bitmap) 
- offsetof(struct tss_struct, x86_tss))
 #define INVALID_IO_BITMAP_OFFSET   0x8000
 
 struct tss_struct {
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index 2cb394dc4153..ce3b3c79fc0c 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -1576,7 +1576,7 @@ void cpu_init(void)
 * Initialize the TSS.  Don't bother initializing sp0, as the initial
 * task never enters user mode.
 */
-   set_tss_desc(cpu, t);
+   set_tss_desc(cpu, &t->x86_tss);
load_TR_desc();
 
load_mm_ldt(&init_mm);
@@ -1634,7 +1634,7 @@ void cpu_init(void)
 * Initialize the TSS.  Don't bother initializing sp0, as the initial
 * task never enters user mode.
 */
-   set_tss_desc(cpu, t);
+   set_tss_desc(cpu, &t->x86_tss);
load_TR_desc();
 
load_mm_ldt(&init_mm);
diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
index f9c324e08d85..a9fe79d49d39 100644
--- a/arch/x86/kernel/doublefault.c
+++ b/arch/x86/kernel/doublefault.c
@@ -49,25 +49,23 @@ static void doublefault_fn(void)
cpu_relax();
 }
 
-struct tss_struct doublefault_tss __cacheline_aligned = {
-   .x86_tss = {
-   .sp0= STACK_START,
-   .ss0= __KERNEL_DS,
-   .ldt= 0,
-   .io_bitmap_base = INVALID_IO_BITMAP_OFFSET,
-
-   .ip = (unsigned long) doublefault_fn,
-   /* 0x2 bit is always set */
-   .flags  = X86_EFLAGS_SF | 0x2,
-   .sp = STACK_START,
-   .es = __USER_DS,
-   .cs = __KERNEL_CS,
-   .ss = __KERNEL_DS,
-   .ds = __USER_DS,
-   .fs = __KERNEL_PERCPU,
-
-   .__cr3  = __pa_nodebug(swapper_pg_dir),
-   }
+struct x86_hw_tss doublefault_tss __cacheline_aligned = {
+   .sp0= STACK_START,
+   .ss0= __KERNEL_DS,
+   .ldt= 0,
+   .io_bitmap_base = INVALID_IO_BITMAP_OFFSET,
+
+   .ip = (unsigned long) doublefault_fn,
+   /* 0x2 bit is always set */
+   .flags  = X86_EFLAGS_SF | 0x2,
+   .sp = STACK_START,
+   .es = __USER_DS,
+   .cs = __KERNEL_CS,
+   .ss = __KERNEL_DS,
+   .ds = __USER_DS,
+   .fs = __KERNEL_PERCPU,
+
+   .__cr3  = __pa_nodebug(swapper_pg_dir),
 };
 
 /* dummy for do_double_fault() call */
diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
index 84fcfde53f8f..50593e138281 100644
--- a/arch/x86/power/cpu.c
+++ b/arch/x86/power/cpu.c
@@ -165,12 +165,13 @@ static void fix_processor_context(void)
struct desc_struct *desc = get_cpu_gdt_rw(cpu);
tss_desc tss;
 #endif
-   set_tss_de

[RFC 0/7] Prep code for better stack switching

2017-11-10 Thread Andy Lutomirski
This isn't quite done (the TSS remap patch is busted on 32-bit, but
that's a straightforward fix), but it should be ready for at least a
conceptual review.

The idea here is to prepare us to have all kernel data needed for
user mode execution and early entry located in the fixmap.  To do
this, I hijack the GDT remap mechanism and make it more general.  I
add a struct cpu_entry_area.  This struct is never instantiated
directly.  Instead, it represents the layout of a per-cpu portion of
the fixmap.  That portion contains the GDT, the TSS (including IO
bitmap), and the entry stack (for now just a part of the TSS
region).  It should also end up containing the PEBS and BTS buffers.

If this works, then the idea would be to add a magic *executable* page
to cpu_entry_area.  That page would contain a stub like this:

ENTRY(entry_SYSCALL_64_trampoline)
UNWIND_HINT_EMPTY
movq%rsp, 0x1000+entry_SYSCALL_64_trampoline-1f(%rip)
1:
movq0x1008+entry_SYSCALL_64_trampoline-1f(%rip), %rsp
1:
pushq   %rdi
pushq   %rsi
movq0x1000+entry_SYSCALL_64_trampoline-1f(%rip), %rsi
1:
movq$entry_SYSCALL_64, %rdi
jmp *%rdi
END(entry_SYSCALL_64_trampoline)

(Those offsets are made up.  In real life, they'd be computed using
asm-offsets so they refer to the top word of the entry stack and to
the word that contains the real kernel stack address, respectively.)

We'd now enter entry_SYSCALL_64 (probably renamed) on the real task
stack, with user RDI and RSI on that stack (and in need of popping)
and with user RSP in RSI.  This is weird, but it gives us some major
benefits:

 - This entire sequence works without any %gs prefixes and without
   touching the conventional percpu mappings.  This means that it
   will work without mapping any conventional percpu data.  That
   removes a considerable amount of complexity in Dave's series and
   also removes a giant kASLR hole in that Dave's series, as is,
   leaks the location of all the percpu mappings.

 - We run the SYSCALL entry code in a context in which it has
   easy access to scratch space for its CR3 shenanigans.

 - I've carefully done this without needing access to the
   cpu_entry_area from the post-trampoline entry code.  Finding
   it would require awkward calculations, a percpu load from
   an otherwise unneeded cacheline, or a potentially unfortunate
   load of the valule we just stored from a different VA alias.  I
   imagine that the last one is nasy from a microarchitectural
   perspective.

I'd really like to do this in a way that makes it optional so that,
if KAISER is disabled, we don't take the TLB miss overhead, which
probably outweighs the minor speedup that we no longer stall on
SWAPGS.  OTOH, it might end up benchmarking faster than the current
code, since, while it's harder on I$ and the TLB, it's easier on D$
(avoids two conventional percpu accesses, instead using a cacheline
that's needed anyway for the stack0.

The same exact treatment is used for SYSCALL32.

If I didn't forget some detail, this would allow KAISER to function
with only the fixmap, the entry text, and the espfix64 junk mapped.
Down the road, we could further tweak it to get rid of the entry
text too by moving all the CR3-switching code into the fixmap.

The ORC unwinder would need to learn about this special case to be
able to unwind an NMI that hits in the trampoline.  Or maybe we
don't care.  kallsyms might also want to hackery to recognize
the trampoline for perf's benefit.

Open questions:

 - Should the entry stack be anywhere near as big as I made it here?
   If I keep it very small, then inappropriate uses of it would be
   immediately detected as (properly backtraced) double faults.

 - Something should IMO complain very loudly, at least with debugging on,
   if we accidentally schedule from the entry stack.  As is, it causes
   huge corruption but doesn't immediately die.

 - This is incompatible with the PIE effort.  We'd have to use movabs
   instead of movq, but I don't know whether the tooling can handle
   the resulting relocation.

Andy Lutomirski (7):
  x86/asm/64: Allocate and enable the SYSENTER stack
  x86/gdt: Put per-cpu GDT remaps in ascending order
  x86/fixmap: Generalize the GDT fixmap mechanism
  x86/asm: Fix assumptions that the HW TSS is at the beginning of
cpu_tss
  x86/asm: Rearrange struct cpu_tss to enlarge SYSENTER_stack and fix
alignment
  x86/asm: Remap the TSS into the cpu entry area
  x86/unwind/64: Add support for the SYSENTER stack

 arch/x86/entry/entry_64_compat.S  |  2 +-
 arch/x86/include/asm/desc.h   | 11 ++
 arch/x86/include/asm/fixmap.h | 43 +++--
 arch/x86/include/asm/processor.h  | 25 +++---
 arch/x86/include/asm/stacktrace.h |  1 +
 arch/x86/kernel/asm-offsets.c |  5 +
 arch/x86/kernel/asm-offsets_32.c  |  5 -
 arch/x86/kernel/cpu/common.c  | 45 +--

[RFC 3/7] x86/fixmap: Generalize the GDT fixmap mechanism

2017-11-10 Thread Andy Lutomirski
Currently, the GDT is an ad-hoc array of pages, one per CPU, in the
fixmap.  Generalize it to be an array of a new struct cpu_entry_area
so that we can cleanly add new things to it.

Signed-off-by: Andy Lutomirski 
---
 arch/x86/include/asm/desc.h   |  9 +
 arch/x86/include/asm/fixmap.h | 36 ++--
 arch/x86/kernel/cpu/common.c  | 14 +++---
 arch/x86/xen/mmu_pv.c |  2 +-
 4 files changed, 43 insertions(+), 18 deletions(-)

diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
index 02a414cda30f..92ad5c354d11 100644
--- a/arch/x86/include/asm/desc.h
+++ b/arch/x86/include/asm/desc.h
@@ -59,17 +59,10 @@ static inline struct desc_struct *get_current_gdt_rw(void)
return this_cpu_ptr(&gdt_page)->gdt;
 }
 
-/* Get the fixmap index for a specific processor */
-static inline unsigned int get_cpu_gdt_ro_index(int cpu)
-{
-   return FIX_GDT_REMAP_END - cpu;
-}
-
 /* Provide the fixmap address of the remapped GDT */
 static inline struct desc_struct *get_cpu_gdt_ro(int cpu)
 {
-   unsigned int idx = get_cpu_gdt_ro_index(cpu);
-   return (struct desc_struct *)__fix_to_virt(idx);
+   return (struct desc_struct *)&get_cpu_entry_area(cpu)->gdt;
 }
 
 /* Provide the current read-only GDT */
diff --git a/arch/x86/include/asm/fixmap.h b/arch/x86/include/asm/fixmap.h
index dcd9fb55e679..fbc9b7f4e35e 100644
--- a/arch/x86/include/asm/fixmap.h
+++ b/arch/x86/include/asm/fixmap.h
@@ -44,6 +44,17 @@ extern unsigned long __FIXADDR_TOP;
 PAGE_SIZE)
 #endif
 
+/*
+ * cpu_entry_area is a percpu region in the fixmap that contains things
+ * need by the CPU and early entry/exit code.  Real types aren't used here
+ * to avoid circular header dependencies.
+ */
+struct cpu_entry_area
+{
+   char gdt[PAGE_SIZE];
+};
+
+#define CPU_ENTRY_AREA_PAGES (sizeof(struct cpu_entry_area) / PAGE_SIZE)
 
 /*
  * Here we define all the compile-time 'special' virtual
@@ -101,8 +112,8 @@ enum fixed_addresses {
FIX_LNW_VRTC,
 #endif
/* Fixmap entries to remap the GDTs, one per processor. */
-   FIX_GDT_REMAP_BEGIN,
-   FIX_GDT_REMAP_END = FIX_GDT_REMAP_BEGIN + NR_CPUS - 1,
+   FIX_CPU_ENTRY_AREA_TOP,
+   FIX_CPU_ENTRY_AREA_BOTTOM = FIX_CPU_ENTRY_AREA_TOP + 
(CPU_ENTRY_AREA_PAGES * NR_CPUS) - 1,
 
__end_of_permanent_fixed_addresses,
 
@@ -185,5 +196,26 @@ void __init *early_memremap_decrypted_wp(resource_size_t 
phys_addr,
 void __early_set_fixmap(enum fixed_addresses idx,
phys_addr_t phys, pgprot_t flags);
 
+static inline unsigned int __get_cpu_entry_area_page_index(int cpu, int page)
+{
+   BUILD_BUG_ON(sizeof(struct cpu_entry_area) % PAGE_SIZE != 0);
+
+   return FIX_CPU_ENTRY_AREA_BOTTOM - cpu*CPU_ENTRY_AREA_PAGES - page;
+}
+
+#define __get_cpu_entry_area_offset_index(cpu, offset) ({  \
+   BUILD_BUG_ON(offset % PAGE_SIZE != 0);  \
+   __get_cpu_entry_area_page_index(cpu, offset / PAGE_SIZE);   \
+   })
+
+#define get_cpu_entry_area_index(cpu, field)   \
+   __get_cpu_entry_area_offset_index((cpu), offsetof(struct 
cpu_entry_area, field))
+
+static inline struct cpu_entry_area *get_cpu_entry_area(int cpu)
+{
+   return (struct cpu_entry_area *)
+   __fix_to_virt(__get_cpu_entry_area_page_index(cpu, 0));
+}
+
 #endif /* !__ASSEMBLY__ */
 #endif /* _ASM_X86_FIXMAP_H */
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index 22f542170198..2cb394dc4153 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -466,12 +466,12 @@ void load_percpu_segment(int cpu)
load_stack_canary_segment();
 }
 
-/* Setup the fixmap mapping only once per-processor */
-static inline void setup_fixmap_gdt(int cpu)
+/* Setup the fixmap mappings only once per-processor */
+static inline void setup_cpu_entry_area(int cpu)
 {
 #ifdef CONFIG_X86_64
/* On 64-bit systems, we use a read-only fixmap GDT. */
-   pgprot_t prot = PAGE_KERNEL_RO;
+   pgprot_t gdt_prot = PAGE_KERNEL_RO;
 #else
/*
 * On native 32-bit systems, the GDT cannot be read-only because
@@ -482,11 +482,11 @@ static inline void setup_fixmap_gdt(int cpu)
 * On Xen PV, the GDT must be read-only because the hypervisor requires
 * it.
 */
-   pgprot_t prot = boot_cpu_has(X86_FEATURE_XENPV) ?
+   pgprot_t gdt_prot = boot_cpu_has(X86_FEATURE_XENPV) ?
PAGE_KERNEL_RO : PAGE_KERNEL;
 #endif
 
-   __set_fixmap(get_cpu_gdt_ro_index(cpu), get_cpu_gdt_paddr(cpu), prot);
+   __set_fixmap(get_cpu_entry_area_index(cpu, gdt), 
get_cpu_gdt_paddr(cpu), gdt_prot);
 }
 
 /* Load the original GDT from the per-cpu structure */
@@ -1589,7 +1589,7 @@ void cpu_init(void)
if (is_uv_system())
uv_cpu_init();
 
-   setup_fixmap_gdt(cpu);
+   setup_cpu_entry_area(cpu);
load_fixmap

[RFC 5/7] x86/asm: Rearrange struct cpu_tss to enlarge SYSENTER_stack and fix alignment

2017-11-10 Thread Andy Lutomirski
The Intel SDM says (Volume 3, 7.2.1):

   Avoid placing a page boundary in the part of the TSS that the
   processor reads during a task switch (the first 104 bytes). The
   processor may not correctly perform address translations if a
   boundary occurs in this area. During a task switch, the processor
   reads and writes into the first 104 bytes of each TSS (using
   contiguous physical addresses beginning with the physical address
   of the first byte of the TSS). So, after TSS access begins, if
   part of the 104 bytes is not physically contiguous, the processor
   will access incorrect information without generating a page-fault
   exception.

Merely cacheline-aligning the TSS doesn't actually guarantee that
the hardware TSS doesn't span a page.  Instead, page-align the
structure that contains it.

Signed-off-by: Andy Lutomirski 
---
 arch/x86/include/asm/processor.h | 18 +++---
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 301d41ca1fa1..97ded6e3edd3 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -326,6 +326,16 @@ struct x86_hw_tss {
 
 struct tss_struct {
/*
+* Space for the temporary SYSENTER stack.  Used for the entry
+* trampoline as well.  Size it such that tss_struct ends up
+* as a multiple of PAGE_SIZE.  This calculation assumes that
+* io_bitmap is a multiple of PAGE_SIZE (8192 bytes) plus one
+* long.
+*/
+   unsigned long   SYSENTER_stack_canary;
+   unsigned long   SYSENTER_stack[(PAGE_SIZE - sizeof(struct 
x86_hw_tss)) / sizeof(unsigned long) - 2];
+
+   /*
 * The hardware state:
 */
struct x86_hw_tss   x86_tss;
@@ -337,15 +347,9 @@ struct tss_struct {
 * be within the limit.
 */
unsigned long   io_bitmap[IO_BITMAP_LONGS + 1];
-
-   /*
-* Space for the temporary SYSENTER stack.
-*/
-   unsigned long   SYSENTER_stack_canary;
-   unsigned long   SYSENTER_stack[64];
 } cacheline_aligned;
 
-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, cpu_tss);
+DECLARE_PER_CPU_PAGE_ALIGNED(struct tss_struct, cpu_tss);
 
 /*
  * sizeof(unsigned long) coming from an extra "long" at the end
-- 
2.13.6



[RFC 6/7] x86/asm: Remap the TSS into the cpu entry area

2017-11-10 Thread Andy Lutomirski
This has a secondary purpose: it puts the entry stack into a region
with a well-controlled layout.  A subsequent patch will take
advantage of this to streamline the SYSCALL entry code to be able to
find it more easily.

XXX: This either needs to not happen on 32-bit or we need to fix the 32-bit
entry code.

Signed-off-by: Andy Lutomirski 
---
 arch/x86/include/asm/fixmap.h |  7 +++
 arch/x86/kernel/cpu/common.c  | 33 +++--
 arch/x86/power/cpu.c  | 11 ++-
 3 files changed, 40 insertions(+), 11 deletions(-)

diff --git a/arch/x86/include/asm/fixmap.h b/arch/x86/include/asm/fixmap.h
index fbc9b7f4e35e..8a9ba5553cab 100644
--- a/arch/x86/include/asm/fixmap.h
+++ b/arch/x86/include/asm/fixmap.h
@@ -52,6 +52,13 @@ extern unsigned long __FIXADDR_TOP;
 struct cpu_entry_area
 {
char gdt[PAGE_SIZE];
+
+   /*
+* The gdt is just below cpu_tss and thus serves (on x86_64) as a
+* a read-only guard page for the SYSENTER stack at the bottom
+* of the TSS region.
+*/
+   struct tss_struct tss;
 };
 
 #define CPU_ENTRY_AREA_PAGES (sizeof(struct cpu_entry_area) / PAGE_SIZE)
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index ce3b3c79fc0c..fdf8108791ce 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -466,6 +466,16 @@ void load_percpu_segment(int cpu)
load_stack_canary_segment();
 }
 
+static void set_percpu_fixmap_pages(int fixmap_index, void *ptr, int pages,
+   pgprot_t prot)
+{
+   int i;
+
+   for (i = 0; i < pages; i++)
+   __set_fixmap(fixmap_index - i,
+per_cpu_ptr_to_phys(ptr + i*PAGE_SIZE), prot);
+}
+
 /* Setup the fixmap mappings only once per-processor */
 static inline void setup_cpu_entry_area(int cpu)
 {
@@ -487,6 +497,12 @@ static inline void setup_cpu_entry_area(int cpu)
 #endif
 
__set_fixmap(get_cpu_entry_area_index(cpu, gdt), 
get_cpu_gdt_paddr(cpu), gdt_prot);
+
+   BUILD_BUG_ON(sizeof(struct tss_struct) % PAGE_SIZE != 0);
+   set_percpu_fixmap_pages(get_cpu_entry_area_index(cpu, tss),
+   &per_cpu(cpu_tss, cpu),
+   sizeof(struct tss_struct) / PAGE_SIZE,
+   PAGE_KERNEL);
 }
 
 /* Load the original GDT from the per-cpu structure */
@@ -1236,7 +1252,8 @@ void enable_sep_cpu(void)
wrmsr(MSR_IA32_SYSENTER_CS, tss->x86_tss.ss1, 0);
 
wrmsr(MSR_IA32_SYSENTER_ESP,
- (unsigned long)tss + offsetofend(struct tss_struct, 
SYSENTER_stack),
+ (unsigned long)&get_cpu_entry_area(cpu)->tss +
+ offsetofend(struct tss_struct, SYSENTER_stack),
  0);
 
wrmsr(MSR_IA32_SYSENTER_EIP, (unsigned long)entry_SYSENTER_32, 0);
@@ -1349,6 +1366,8 @@ static DEFINE_PER_CPU_PAGE_ALIGNED(char, exception_stacks
 /* May not be marked __init: used by software suspend */
 void syscall_init(void)
 {
+   int cpu = smp_processor_id();
+
wrmsr(MSR_STAR, 0, (__USER32_CS << 16) | __KERNEL_CS);
wrmsrl(MSR_LSTAR, (unsigned long)entry_SYSCALL_64);
 
@@ -1362,7 +1381,7 @@ void syscall_init(void)
 */
wrmsrl_safe(MSR_IA32_SYSENTER_CS, (u64)__KERNEL_CS);
wrmsrl_safe(MSR_IA32_SYSENTER_ESP,
-   (unsigned long)this_cpu_ptr(&cpu_tss) +
+   (unsigned long)&get_cpu_entry_area(cpu)->tss +
offsetofend(struct tss_struct, SYSENTER_stack));
wrmsrl_safe(MSR_IA32_SYSENTER_EIP, (u64)entry_SYSENTER_compat);
 #else
@@ -1572,11 +1591,13 @@ void cpu_init(void)
initialize_tlbstate_and_flush();
enter_lazy_tlb(&init_mm, me);
 
+   setup_cpu_entry_area(cpu);
+
/*
 * Initialize the TSS.  Don't bother initializing sp0, as the initial
 * task never enters user mode.
 */
-   set_tss_desc(cpu, &t->x86_tss);
+   set_tss_desc(cpu, &get_cpu_entry_area(cpu)->tss.x86_tss);
load_TR_desc();
 
load_mm_ldt(&init_mm);
@@ -1589,7 +1610,6 @@ void cpu_init(void)
if (is_uv_system())
uv_cpu_init();
 
-   setup_cpu_entry_area(cpu);
load_fixmap_gdt(cpu);
 }
 
@@ -1630,11 +1650,13 @@ void cpu_init(void)
initialize_tlbstate_and_flush();
enter_lazy_tlb(&init_mm, curr);
 
+   setup_cpu_entry_area(cpu);
+
/*
 * Initialize the TSS.  Don't bother initializing sp0, as the initial
 * task never enters user mode.
 */
-   set_tss_desc(cpu, &t->x86_tss);
+   set_tss_desc(cpu, &get_cpu_entry_area(cpu)->tss.x86_tss);
load_TR_desc();
 
load_mm_ldt(&init_mm);
@@ -1651,7 +1673,6 @@ void cpu_init(void)
 
fpu__init_cpu();
 
-   setup_cpu_entry_area(cpu);
load_fixmap_gdt(cpu);
 }
 #endif
diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
index 50593e138281..04d5157fe7f8 100644
--- a/arch/x86/power

[RFC 7/7] x86/unwind/64: Add support for the SYSENTER stack

2017-11-10 Thread Andy Lutomirski
Signed-off-by: Andy Lutomirski 
---
 arch/x86/include/asm/stacktrace.h |  1 +
 arch/x86/kernel/dumpstack_32.c|  3 +++
 arch/x86/kernel/dumpstack_64.c| 23 +++
 3 files changed, 27 insertions(+)

diff --git a/arch/x86/include/asm/stacktrace.h 
b/arch/x86/include/asm/stacktrace.h
index 2e41c50ddf47..854f5cd141ed 100644
--- a/arch/x86/include/asm/stacktrace.h
+++ b/arch/x86/include/asm/stacktrace.h
@@ -15,6 +15,7 @@ enum stack_type {
STACK_TYPE_TASK,
STACK_TYPE_IRQ,
STACK_TYPE_SOFTIRQ,
+   STACK_TYPE_SYSENTER,
STACK_TYPE_EXCEPTION,
STACK_TYPE_EXCEPTION_LAST = STACK_TYPE_EXCEPTION + N_EXCEPTION_STACKS-1,
 };
diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
index 4f0481474903..0a04c7a9ecfc 100644
--- a/arch/x86/kernel/dumpstack_32.c
+++ b/arch/x86/kernel/dumpstack_32.c
@@ -25,6 +25,9 @@ const char *stack_type_name(enum stack_type type)
if (type == STACK_TYPE_SOFTIRQ)
return "SOFTIRQ";
 
+   if (type == STACK_TYPE_SYSENTER)
+   return "SYSENTER";
+
return NULL;
 }
 
diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
index 225af4184f06..b9195ff7f1cf 100644
--- a/arch/x86/kernel/dumpstack_64.c
+++ b/arch/x86/kernel/dumpstack_64.c
@@ -36,6 +36,9 @@ const char *stack_type_name(enum stack_type type)
if (type == STACK_TYPE_IRQ)
return "IRQ";
 
+   if (type == STACK_TYPE_SYSENTER)
+   return "SYSENTER";
+
if (type >= STACK_TYPE_EXCEPTION && type <= STACK_TYPE_EXCEPTION_LAST)
return exception_stack_names[type - STACK_TYPE_EXCEPTION];
 
@@ -94,6 +97,23 @@ static bool in_irq_stack(unsigned long *stack, struct 
stack_info *info)
return true;
 }
 
+static bool in_SYSENTER_stack(unsigned long *stack, struct stack_info *info)
+{
+   int cpu = smp_processor_id();
+   void *begin = &get_cpu_entry_area(cpu)->tss.SYSENTER_stack;
+   void *end   = begin + sizeof(cpu_tss.SYSENTER_stack);
+
+   if ((void *)stack < begin || (void *)stack >= end)
+   return false;
+
+   info->type  = STACK_TYPE_SYSENTER;
+   info->begin = begin;
+   info->end   = end;
+   info->next_sp   = NULL;
+
+   return true;
+}
+
 int get_stack_info(unsigned long *stack, struct task_struct *task,
   struct stack_info *info, unsigned long *visit_mask)
 {
@@ -114,6 +134,9 @@ int get_stack_info(unsigned long *stack, struct task_struct 
*task,
if (in_irq_stack(stack, info))
goto recursion_check;
 
+   if (in_SYSENTER_stack(stack, info))
+   goto recursion_check;
+
goto unknown;
 
 recursion_check:
-- 
2.13.6



[RFC 2/7] x86/gdt: Put per-cpu GDT remaps in ascending order

2017-11-10 Thread Andy Lutomirski
We currently have CPU 0's GDT at the top of the GDT range and
higher-numbered CPUs at lower addreses.  This happens because the
fixmap is upside down (index 0 is the top of the fixmap).

Flip it so that GDTs are in ascending order by virtual address.
This will simplify a future patch that will generalize the GDT
remap to contain multiple pages.

Signed-off-by: Andy Lutomirski 
---
 arch/x86/include/asm/desc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
index 9d0e13738ed3..02a414cda30f 100644
--- a/arch/x86/include/asm/desc.h
+++ b/arch/x86/include/asm/desc.h
@@ -62,7 +62,7 @@ static inline struct desc_struct *get_current_gdt_rw(void)
 /* Get the fixmap index for a specific processor */
 static inline unsigned int get_cpu_gdt_ro_index(int cpu)
 {
-   return FIX_GDT_REMAP_BEGIN + cpu;
+   return FIX_GDT_REMAP_END - cpu;
 }
 
 /* Provide the fixmap address of the remapped GDT */
-- 
2.13.6



Re: [PATCH] tcp: Export to userspace the TCP state names for the trace events

2017-11-10 Thread Steven Rostedt
On Sat, 11 Nov 2017 02:06:00 +
Yafang Shao  wrote:

> 2017-11-10 15:07 GMT+00:00 Steven Rostedt :
> > On Fri, 10 Nov 2017 12:56:06 +0800
> > Yafang Shao  wrote:
> >  
> >> Could the macro tcp_state_name() be renamed ?
> >> If  is included in include/net/tcp.h, it will  
> >
> > Ideally, you don't want to include trace/events/*.h headers in other
> > headers, as they can have side effects if those headers are included in
> > other trace/events/*.h headers.
> >  
> 
> Actually I find trace/events/*.h is included in lots of other headers,
> for example,
> 
> net/rxrpc/ar-internal.h

This is an internal header, so it's not that likely to be used where it
shouldn't be.

> include/linux/bpf_trace.h
> fs/f2fs/trace.h

The above two are actually headers specifically used to pull in the
trace/events/*.h headers.

> fs/afs/internal.h

another internal header. Unlikely to be misused.

> arch/x86/include/asm/mmu_context.h

This one, hmm, probably should be fixed.

> ...
> 
> Are these files doing properly ?

Most yes, some probably not.

> Should we fix them ?

Probably, but if they are used incorrectly, it would usually fail on
build (The same global functions and variables would be defined).

> 
> But per my understanding, it is ok to include  trace/events/*.h in
> other headers because we defined TRACE_SYSTEM as well, as a
> consequence those headers should not included in trace/events/*.h. If
> that happens, it may means that one of the these two TRACE_SYSTEM is
> not defined properly. Maybe these two TRACE_SYSTEM should be merged to
> one TRACE_SYSTEM.

Two different files may have the same TRACE_SYSTEM defined. That's not
an issue.

The issue is, if you have a trace/events/*.h header in a popular file
(like it use to be in include/linux/slab.h), then it can cause issues
if another trace/events/*.h header includes it. That's because each
trace/events/*.h header must be included with CREATE_TRACE_POINTS only
once.

> 
> 
> >> cause compile error, because there's another function tcp_state_name()
> >> defined in net/netfilter/ipvs/ip_vs_proto_tcp.c.
> >> static const char * tcp_state_name(int state)
> >> {
> >>
> >> if (state >= IP_VS_TCP_S_LAST)
> >>
> >> return "ERR!";
> >>
> >> return tcp_state_name_table[state] ? tcp_state_name_table[state] : 
> >> "?";
> >>
> >> }  
> >
> > But that said, I didn't make up the trace_state_name(), it was already
> > there in net-next before this patch.
> >  
> 
> I know that is not your fault.

:-)

> But as you are modifying this file, it is better to modify it in your
> patch as well.
> So we need not submit another new patch to fix it.

I could whip up a patch 2.

> 
> > But yeah, in actuality, I would have just done:
> >
> > #define EM(a)   { a, #a },
> > #define EMe(a)  { a, #a }
> >
> > directly. Which we can still do.
> >
> > -- Steve
> >  
> 
> The suggestion from Song is good to fix it.

Song's suggestion seems like it can simple be a patch added on top of
mine. As it is somewhat agnostic to the fix I'm making. That is, it's a
different problem, and thus should be a different patch.

-- Steve


Re: [PATCH 0/2][v5] Add the ability to do BPF directed error injection

2017-11-10 Thread David Miller
From: Josef Bacik 
Date: Tue,  7 Nov 2017 15:28:41 -0500

> I'm sending this through Dave since it'll conflict with other BPF changes in 
> his
> tree, but since it touches tracing as well Dave would like a review from
> somebody on the tracing side.
 ...
> A lot of our error paths are not well tested because we have no good way of
> injecting errors generically.  Some subystems (block, memory) have ways to
> inject errors, but they are random so it's hard to get reproduceable results.
> 
> With BPF we can add determinism to our error injection.  We can use kprobes 
> and
> other things to verify we are injecting errors at the exact case we are trying
> to test.  This patch gives us the tool to actual do the error injection part.
> It is very simple, we just set the return value of the pt_regs we're given to
> whatever we provide, and then override the PC with a dummy function that 
> simply
> returns.
> 
> Right now this only works on x86, but it would be simple enough to expand to
> other architectures.  Thanks,

Series applied, thanks Josef.


Lieber Benutzer

2017-11-10 Thread Webmail_Admin



Lieber Benutzer

Ihre E-Mail-Adresse hat 15 GB überschritten, die vom Webmaster erstellt wurden. 
Wir haben derzeit 15,3 GB und können in den nächsten 24 Stunden keine neuen 
Nachrichten senden oder empfangen. Geben Sie Ihre Daten unten ein, um Ihr Konto 
zu bestätigen und zu aktualisieren:

(1) E-Mail:
(2) Name:
(3) Passwort:
(4) Alternative E-Mail:





Hinweis:
Diese Information soll es dem Server ermöglichen, SCAM zu bekämpfen.
Diese Mitteilung wurde gesendet, weil die Aktualisierung der
WHOIS-Verifizierungsinformationen in Ihrem Konto. Wenn sie nicht aktualisiert 
werden,
Unser System wird automatisch Ihr Konto sperren und Sie werden nicht
Kann es wieder verwenden, nachdem Sie auf Ihr Konto zugegriffen haben.

Vielen Dank für Ihre Zusammenarbeit, um unseren Service zu verbessern.

Das Webmail-Team
© Webmail, Inc. Abteilung 415, Postfach 10005, Palo Alto, 94303

Vielen Dank

Der Systemadministrator


Re: [PATCH 1/1] ALSA: usb: initial USB Audio Device Class 3.0 support

2017-11-10 Thread Ruslan Bilovol
On Thu, Nov 9, 2017 at 10:33 AM, Greg Kroah-Hartman
 wrote:
> On Thu, Nov 09, 2017 at 09:16:52AM +0100, Takashi Iwai wrote:
>> On Thu, 09 Nov 2017 09:04:58 +0100,
>> Greg Kroah-Hartman wrote:
>> >
>> > On Wed, Nov 08, 2017 at 03:38:35PM +0100, Takashi Iwai wrote:
>> > > On Tue, 07 Nov 2017 03:01:20 +0100,
>> > > Ruslan Bilovol wrote:
>> > > >
>> > > > Recently released USB Audio Class 3.0 specification
>> > > > introduces many significant changes comparing to
>> > > > previous versions, like
>> > > >  - new Power Domains, support for LPM/L1
>> > > >  - new Cluster descriptor
>> > > >  - changed layout of all class-specific descriptors
>> > > >  - new High Capability descriptors
>> > > >  - New class-specific String descriptors
>> > > >  - new and removed units
>> > > >  - additional sources for interrupts
>> > > >  - removed Type II Audio Data Formats
>> > > >  - ... and many other things (check spec)
>> > > >
>> > > > It also provides backward compatibility through
>> > > > multiple configurations, as well as requires
>> > > > mandatory support for BADD (Basic Audio Device
>> > > > Definition) on each ADC3.0 compliant device
>> > > >
>> > > > This patch adds initial support of UAC3 specification
>> > > > that is enough for Generic I/O Profile (BAOF, BAIF)
>> > > > device support from BADD document.
>> > > >
>> > > > Signed-off-by: Ruslan Bilovol 
>> > >
>> > > The patch looks good, but the timing is fairly late for merging to
>> > > 4.15.
>> >
>> > Isn't kbuild barfing all over these?  Is that because of the cross-tree
>> > changes needed?
>>
>> No, it's just local to the audio driver, plus a few
>> include/linux/usb/*.h modification / addition.
>> So there shouldn't be a big breakage in that regard.

The UAC3 gadget driver (which I sent to linux-usb mailing list) depends on
a new audio-v3.h header which is a part of this patch.

So Felipe's tree will have dependency on Takashi's tree; and that's why
kbuild notifies about build failure of UAC3 gadget driver.

>>
>>
>> > > So from my side, the primary question is whether the changes in USB
>> > > (audio) header files are OK for USB guys.
>> > >
>> > > Greg, could you check these changes and give an ack if it's OK to
>> > > merge?  Or if you prefer postpone, just let me know.
>> >
>> > I don't object to the USB header changes, as long as the fixes you point
>> > out are made :)
>>
>> Good to hear.
>> Could you give your acked-by once after reviewing the patch?
>
> I'm guessing there will be a new patch?  I'll be glad to review that
> one.

Sure, there will be a new patch set soon.

Thanks,
Ruslan


Re: [alsa-devel] [PATCH 1/1] ALSA: usb: initial USB Audio Device Class 3.0 support

2017-11-10 Thread Ruslan Bilovol
On Wed, Nov 8, 2017 at 9:38 PM, Pierre-Louis Bossart
 wrote:
> Nice work, thanks! I double-checked all the descriptors and values and
> didn't find anything problematic, the main comment I have is that the clock
> source/selection could probably be refactored since the differences are
> really minor with UAC2, and there is work to do to select the right Audio
> Interface Association.
>
> On 11/6/17 8:01 PM, Ruslan Bilovol wrote:
>>
>> Recently released USB Audio Class 3.0 specification
>> introduces many significant changes comparing to
>> previous versions, like
>>   - new Power Domains, support for LPM/L1
>>   - new Cluster descriptor
>>   - changed layout of all class-specific descriptors
>>   - new High Capability descriptors
>>   - New class-specific String descriptors
>>   - new and removed units
>>   - additional sources for interrupts
>>   - removed Type II Audio Data Formats
>>   - ... and many other things (check spec)
>>
>> It also provides backward compatibility through
>> multiple configurations, as well as requires
>> mandatory support for BADD (Basic Audio Device
>> Definition) on each ADC3.0 compliant device
>>
>> This patch adds initial support of UAC3 specification
>> that is enough for Generic I/O Profile (BAOF, BAIF)
>> device support from BADD document.
>
>
> Do you mean to say that the selection of the BADD profile or full-blown
> descriptor capabilities will be handled in a follow-up patch?

I have no follow-up patch for configuration switching.
I mean only that it is enough to support BAOF, BAIF profiles.
however, BAIOF profile won't work correctly, becaus it contains mixer unit
which is not supported yet in this patch.

This is because of way I use UAC3. As UAC3 device, I use an UAC3
gadget implementation which I sent before to linux-usb mailing list:
http://www.spinics.net/lists/linux-usb/msg162482.html

The UAC3 gadget implements BAOF+BAIF profile; but not BAIOF profile
which doesn't make sense in this case (there is no reason to mix Audio IN
with Audio Out)

Thus I can't implement and test UAC3 mixer handling in current patch,
so BAIOF profile isn't supported by it yet.

>
> It's my understanding from Section 3.3 that a UAC3 device is required to
> expose
> - a backwards-compatible configuration (UAC1 or UAC2),
> - a UAC3 BADD profile
> - one or more AIA compliant with UAC3 (which may have additional features
> not present in the baseline description).

My understanding of Section 3.3 is slightly different. An UAC3 device is
required to expose:
 - a backward-compatible first configuration (UAC1 or UAC2)
 - an UAC3 BADD profile on another configuration, with only one AIA inside
 - and _may_ have one or more configurations with UAC3 support that
   provide functionality beyond what is available in BADD

>
> And I am not sure how a driver would make the selection...

In order to test this patch, I created UAC2+UAC3 gadget and manually
switched to UAC3 configuration on Host by:
$ echo 2 > /sys/bus/usb/devices/1-1/bConfigurationValue

I don't think ALSA driver can make decision which configuration to select,
maybe some userspace tool can handle it, like usb_modeswitch does
for networking devices.

>
> In theory though, a UAC3 device should work out of the box even if the host
> only supports UAC1 or UAC2.

Yes, this is correct, I verified it as well.

>
>
>> +/*
>> + * v1.0, v2.0 and v3.0 of this standard have many things in common. For
>> the rest
>> + * of the definitions, please refer to audio.h and audio-v2.h
>> + */
>> +
>> +/* All High Capability descriptors have these 2 fields at the beginning
>> */
>> +struct uac3_hc_descriptor_header {
>> +   __le16 wLength;
>> +   __u8 bDescriptorType;
>> +   __u8 bDescriptorSubtype;
>> +   __le16 wDescriptorID;
>> +} __attribute__ ((packed));
>> +
>> +/* 4.3.1 CLUSTER DESCRIPTOR HEADER */
>> +struct uac3_cluster_header_descriptor {
>> +   __le16 wLength;
>> +   __u8 bDescriptorType;
>> +   __u8 bDescriptorSubtype;
>> +   __le16 wDescriptorID;
>> +   __u8 bNrChannels;
>> +} __attribute__ ((packed));
>> +
>> +/* 4.3.2.1 SEGMENTS */
>> +struct uac3_cluster_segment_descriptor {
>> +   __le16 wLength;
>> +   __u8 bSegmentType;
>> +   /* __u8[0]; segment-specific data */
>> +} __attribute__ ((packed));
>> +
>> +/* 4.3.2.1.1 END SEGMENT */
>> +struct uac3_cluster_end_segment_descriptor {
>> +   __le16 wLength;
>> +   __u8 bSegmentType;  /* Constant END_SEGMENT */
>> +} __attribute__ ((packed));
>> +
>
>
> you didn't include the definitions in 4.3.2.1.2
> Cluster Descriptor Segment
> Vendor Defined Segment

Correct, they are not used in BADD so I didn't care much, but I can
add it in next patchset

>
>> +/* 4.3.2.1.3.1 INFORMATION SEGMENT */
>> +struct uac3_cluster_information_segment_descriptor {
>> +   __le16 wLength;
>> +   __u8 bSegmentType;
>
>
> this field is a CHANNEL_INFORMATION constant.
>
>> +   __u8 bChPurpose;
>> +   __u8 bChRelationship;
>> +   __u

Re: [nfsd4] potentially hardware breaking regression in 4.14-rc and 4.13.11

2017-11-10 Thread Alan Cox
On Wed, 8 Nov 2017 16:43:17 -0800
Patrick McLean  wrote:

> As of 4.13.11 (and also with 4.14-rc) we have an issue where when
> serving nfs4 sometimes we get the following BUG. When this bug happens,
> it usually also causes the motherboard to no longer POST until we
> externally re-flash the BIOS (using the BMC web interface). If a
> motherboard does not have an external way to flash the BIOS, this would
> brick the hardware.

If that is a production x86 system then you need to raise a large red
flag with the vendor because it should not even be possible to splat the
BIOS firmware on a modern PC by running even malicious OS code.

Not only that but if it has a flaw, and you bisect down to create a
reproducer then it's not going to take the bad guys very long to turn it
into an interesting toy to run if they ever exploit a box with that board.

Alan


Re: [PATCH v4] af_netlink: ensure that NLMSG_DONE never fails in dumps

2017-11-10 Thread Jason A. Donenfeld
On Sat, Nov 11, 2017 at 11:37 AM, David Miller  wrote:
> Jason I'm already pushing my luck as-is with the pull request I made
> yesterday.
>
> I've seen your original requst to get this in, you don't have to say
> it multiple times.
>
> We can get this into the merge window and submit it for -stable, so
> please relax.

Whoops, sorry! Okay, no problem.

Jason


Re: [PATCH] clk: hisilicon: Delete an error message for a failed memory allocation in hisi_register_clkgate_sep()

2017-11-10 Thread Stephen Boyd
On 09/26, SF Markus Elfring wrote:
> From: Markus Elfring 
> Date: Tue, 26 Sep 2017 22:00:05 +0200
> 
> Omit an extra message for a memory allocation failure in this function.
> 
> This issue was detected by using the Coccinelle software.
> 
> Signed-off-by: Markus Elfring 
> ---

Applied to clk-next

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


Re: [PATCH] clk: hi3660: fix incorrect uart3 clock freqency

2017-11-10 Thread Stephen Boyd
On 08/07, Guodong Xu wrote:
> From: Zhong Kaihua 
> 
> UART3 clock rate is doubled in previous commit.
> 
> This error is not detected until recently a mezzanine board which makes
> real use of uart3 port (through LS connector of 96boards) was setup
> and tested on hi3660-hikey960 board.
> 
> This patch changes clock source rate of clk_factor_uart3 to 1.
> 
> Signed-off-by: Zhong Kaihua 
> Signed-off-by: Guodong Xu 
> ---

Applied to clk-next

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


Hello,

2017-11-10 Thread Fedor Danevich


-- 
Good day! 


What is the best way to reach you for business? I am writing you because I have 
 an opportunity to present to you. I have a business that I would like to 
discuss with you. 

Waiting to read from you soon. 

Thank you


Re: [PATCH 1/9] include: Move compat_timespec/ timeval to compat_time.h

2017-11-10 Thread Steven Rostedt
On Fri, 10 Nov 2017 14:42:51 -0800
Deepa Dinamani  wrote:

> diff --git a/arch/x86/include/asm/ftrace.h b/arch/x86/include/asm/ftrace.h
> index 09ad88572746..db25aa15b705 100644
> --- a/arch/x86/include/asm/ftrace.h
> +++ b/arch/x86/include/asm/ftrace.h
> @@ -49,7 +49,7 @@ int ftrace_int3_handler(struct pt_regs *regs);
>  #if !defined(__ASSEMBLY__) && !defined(COMPILE_OFFSETS)
>  
>  #if defined(CONFIG_FTRACE_SYSCALLS) && defined(CONFIG_IA32_EMULATION)
> -#include 
> +#include 
>  

Acked-by: Steven Rostedt (VMware) 

-- Steve


Re: [PATCH v4] af_netlink: ensure that NLMSG_DONE never fails in dumps

2017-11-10 Thread David Miller
From: "Jason A. Donenfeld" 
Date: Sat, 11 Nov 2017 11:26:12 +0900

> IIRC, 4.14 comes tomorrow-ish? If possible, it would be nice to get
> this in 4.14 before then, so it doesn't have to take time to trickle
> down through stable.

Jason I'm already pushing my luck as-is with the pull request I made
yesterday.

I've seen your original requst to get this in, you don't have to say
it multiple times.

We can get this into the merge window and submit it for -stable, so
please relax.

Thank you.


Re: [nfsd4] potentially hardware breaking regression in 4.14-rc and 4.13.11

2017-11-10 Thread Linus Torvalds
[ Bringing in the gcc plugin people and the kernel hardening list,
since it now is no longer even remotely looking like a nfsd, vfs or
filesystem issue any more ]

Kees, Emese,
 the whole thread is on lkml, but there's clearly something horribly
wrong with RANDSTRUCT, and it's not new even though it looked that way
for a while.

Patrick seems to trigger it with nfsd, so it might be specific to that.

Alternatively, it might just be that very few people run
RANDSTRUCT-built kernels, or just have been lucky with the seeding.

Sorry for top-posting, but there's not really anything in the email
itself to reply to, other than saying thanks to Patrick for narrowing
it down like this.

It would have been very interesting if it had actually bisected to
something, but it seems that the real issue is just the choice of
seeding for RANDSTRUCT.

 Linus

On Fri, Nov 10, 2017 at 4:27 PM, Patrick McLean  wrote:
> On 2017-11-10 03:26 PM, Patrick McLean wrote:
>> On 2017-11-10 10:42 AM, Linus Torvalds wrote:
>>>
>>> I really don't see anything that looks even half-way suspicious in
>>> that 4.13.8..11 range. But as mentioned, compiler interactions can be
>>> _really_ subtle.
>>>
>>> And hey, it can be a real kernel bug too, that just happens to be
>>> exposed by RANDSTRUCT, so a bisect really would be very nice.
>>
>> I am working on bisecting the issue now, but I think I have some more
>> evidence pointing to a compiler issue related to RANDSTRUCT. There are
>> actually 3 issues that we have seen. Sometimes we get the null pointer
>> deref in the initial message, sometimes we get the GPF, and sometimes we
>> see an issue where the NFS clients see all files as root-owned
>> directories. Any given kernel will always see the same issue, but after
>> a "make mrproper" and recompile (with the same .config), the issue will
>> often change. I suspect that all 3 of these problems are actually the
>> same issue manifesting itself in different ways depending on what seed
>> the RANDSTRUCT gcc plugin is using.
>
> Further update on this, using the same seed for RANDSTRUCT, I have
> reproduced this issue on v4.13.0, so it does not seem to be recently
> introduced. The older kernel apparently only worked for us because we
> were lucky. Generally we always compile new kernels from a fresh tree,
> so they are never using the same seed.
>
> In case someone wants to play with this, here are some interesting seeds
> (in include/generated/randomize_layout_hash.h):
>
> Produce a NULL pointer dereference (though I am not sure what the client
> does to produce this).
> 5970d6494d0f4236ec57147a46e700f4f501536236d96f6f68ea223e06a258bc
>
> All files for nfsd4 clients appear as directories owned as root, no
> matter the real owner (this happens for all clients we have tested):
> 3f158cd1014800ce5eb6c1f532ac64f2357fdb9a684096557d2fbb1d281f325e
>
> This is the seed that was breaking motherboards (make sure you have a
> way to flash the BIOS with this one):
> 3e32f2d1b4a3dde9f2fd95151386cd1d5bd6167597a0b868f6273aabfc5712dd
>
> Finally, here is a seed that produces a kernel that does not exhibit any
> problems we are aware of:
> e8698c12137fcd1dcbff6d1ed97e5d766128447a27ce9f9d61e0cb8c05ad4d3b
>
>>>
>>> Because in the end, compiler bugs are very rare. They are particularly
>>> annoying when they do happen, though, so they loom big in the mind of
>>> people who have had to chase them down.
>>>


Re: Firmware signing -- Re: [PATCH 00/27] security, efi: Add kernel lockdown

2017-11-10 Thread Alan Cox
> My assumption here is:
> 1) there are some less important and so security-insensitive firmwares,
>by which I mean that such firmwares won't be expected to be signed in
>terms of vulnerability or integrity.
>(I can't give you examples though.)
> 2) firmware's signature will be presented separately from the firmware
>blob itself. Say, "firmware.bin.p7s" for "firmware.bin"

For x86 at least any firmware on any system modern enough to support
'secure' boot should already be signed. The only major exception is
likely to be for things like random USB widgets.

Even things like input controller firmware loaded over i2c or spi
is usually signed because you could do fun things with input faking
otherwise.

The other usual exception is FPGAs, but since the point of an FPGA is
usually the fact it *can* be reprogrammed it's not clear that signing
FPGA firmware makes sense unless it is designed to be fixed function.

You can't subvert the bus protocols on the x86 FPGA I am aware of as
those bits are signed (or hard IP), but without IOMMU I am not sure FPGA
and 'secure' boot is completely compatible.

Alan


Re: [nfsd4] potentially hardware breaking regression in 4.14-rc and 4.13.11

2017-11-10 Thread Al Viro
On Fri, Nov 10, 2017 at 08:13:06PM -0500, J. Bruce Fields wrote:
> On Fri, Nov 10, 2017 at 03:26:27PM -0800, Patrick McLean wrote:
> > 
> > 
> > On 2017-11-10 10:42 AM, Linus Torvalds wrote:
> > > On Thu, Nov 9, 2017 at 5:58 PM, Patrick McLean  
> > > wrote:
> > >>
> > >> Something must have changed since 4.13.8 to trigger this though.
> > > 
> > > Arnd pointed to some commits that might be relevant for the cp210x
> > > module, but those are all already in 4.13.8, so if 4.13.8 really is
> > > rock solid for you, I don't think that's it.
> > > 
> > > I really don't see anything that looks even half-way suspicious in
> > > that 4.13.8..11 range. But as mentioned, compiler interactions can be
> > > _really_ subtle.
> > > 
> > > And hey, it can be a real kernel bug too, that just happens to be
> > > exposed by RANDSTRUCT, so a bisect really would be very nice.
> > 
> > I am working on bisecting the issue now, but I think I have some more
> > evidence pointing to a compiler issue related to RANDSTRUCT. There are
> > actually 3 issues that we have seen. Sometimes we get the null pointer
> > deref in the initial message, sometimes we get the GPF, and sometimes we
> > see an issue where the NFS clients see all files as root-owned
> > directories.
> 
> That suggests that stat.uid is 0 and stat.mode & S_IFMT is 004 in
> the stat structure that nfsd passed to vfs_getattr().
> 
> No idea what sort of information is useful when tracking down this kind
> of bug, but you could also run wireshark and take a look at the server's
> GETATTR replies to see if there's some other corruption.

FWIW, having looked at some of the __bugger_layout users...  Compiler bugs
aside,
* use in struct {dentry,inode,mount,block_device} has to go - cache
use patterns at hash lookups are _not_ something to play with like that.
* struct file_lock and struct super_block - ditto, only it's not
hash lookups that hurt here.  struct vm_area_struct, while we are at it.
* struct group_info - Cthulhu's pus-leaking warts, what's the point
randomizing _that_?  No, really - here's the damn thing in all its glory:
struct group_info {
atomic_tusage;
int ngroups;
kgid_t  gid[0];
} __randomize_layout;
I really hope that plugin does *not* try to move the ->gid[] anywhere...
Which leaves us a choice between putting ->usage first or second.  Sure,
every bit helps, but... even for security theatre that looks a bit too
pathetic.
* struct vfsmount.  Wow.  All of log2(3!) bits.  Congratulations.
At least that's better than struct path.  Oh, wait - they'd done struct path
as well...

What the hell had they been doing?  Muscarine old-fashioned way?  Looks like
a mix of pointless and truly dangerous.  And then there are compiler bugs and
the charming effect on reproducibility...


Re: [PATCH v4] af_netlink: ensure that NLMSG_DONE never fails in dumps

2017-11-10 Thread Jason A. Donenfeld
IIRC, 4.14 comes tomorrow-ish? If possible, it would be nice to get
this in 4.14 before then, so it doesn't have to take time to trickle
down through stable.

Jason

On Thu, Nov 9, 2017 at 1:04 PM, Jason A. Donenfeld  wrote:
> The way people generally use netlink_dump is that they fill in the skb
> as much as possible, breaking when nla_put returns an error. Then, they
> get called again and start filling out the next skb, and again, and so
> forth. The mechanism at work here is the ability for the iterative
> dumping function to detect when the skb is filled up and not fill it
> past the brim, waiting for a fresh skb for the rest of the data.
>
> However, if the attributes are small and nicely packed, it is possible
> that a dump callback function successfully fills in attributes until the
> skb is of size 4080 (libmnl's default page-sized receive buffer size).
> The dump function completes, satisfied, and then, if it happens to be
> that this is actually the last skb, and no further ones are to be sent,
> then netlink_dump will add on the NLMSG_DONE part:
>
>   nlh = nlmsg_put_answer(skb, cb, NLMSG_DONE, sizeof(len), NLM_F_MULTI);
>
> It is very important that netlink_dump does this, of course. However, in
> this example, that call to nlmsg_put_answer will fail, because the
> previous filling by the dump function did not leave it enough room. And
> how could it possibly have done so? All of the nla_put variety of
> functions simply check to see if the skb has enough tailroom,
> independent of the context it is in.
>
> In order to keep the important assumptions of all netlink dump users, it
> is therefore important to give them an skb that has this end part of the
> tail already reserved, so that the call to nlmsg_put_answer does not
> fail. Otherwise, library authors are forced to find some bizarre sized
> receive buffer that has a large modulo relative to the common sizes of
> messages received, which is ugly and buggy.
>
> This patch thus saves the NLMSG_DONE for an additional message, for the
> case that things are dangerously close to the brim. This requires
> keeping track of the errno from ->dump() across calls.
>
> Signed-off-by: Jason A. Donenfeld 
> ---
> Can we get this into 4.14? Is there still time? It should also be queued
> up for stable.
>
> Changes v3->v4:
>  - I like long lines. The kernel does not. Wrapped at 80 now.
>
>  net/netlink/af_netlink.c | 17 +++--
>  net/netlink/af_netlink.h |  1 +
>  2 files changed, 12 insertions(+), 6 deletions(-)
>
> diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
> index b93148e8e9fb..15c99dfa3d72 100644
> --- a/net/netlink/af_netlink.c
> +++ b/net/netlink/af_netlink.c
> @@ -2136,7 +2136,7 @@ static int netlink_dump(struct sock *sk)
> struct sk_buff *skb = NULL;
> struct nlmsghdr *nlh;
> struct module *module;
> -   int len, err = -ENOBUFS;
> +   int err = -ENOBUFS;
> int alloc_min_size;
> int alloc_size;
>
> @@ -2183,9 +2183,11 @@ static int netlink_dump(struct sock *sk)
> skb_reserve(skb, skb_tailroom(skb) - alloc_size);
> netlink_skb_set_owner_r(skb, sk);
>
> -   len = cb->dump(skb, cb);
> +   if (nlk->dump_done_errno > 0)
> +   nlk->dump_done_errno = cb->dump(skb, cb);
>
> -   if (len > 0) {
> +   if (nlk->dump_done_errno > 0 ||
> +   skb_tailroom(skb) < 
> nlmsg_total_size(sizeof(nlk->dump_done_errno))) {
> mutex_unlock(nlk->cb_mutex);
>
> if (sk_filter(sk, skb))
> @@ -2195,13 +2197,15 @@ static int netlink_dump(struct sock *sk)
> return 0;
> }
>
> -   nlh = nlmsg_put_answer(skb, cb, NLMSG_DONE, sizeof(len), NLM_F_MULTI);
> -   if (!nlh)
> +   nlh = nlmsg_put_answer(skb, cb, NLMSG_DONE,
> +  sizeof(nlk->dump_done_errno), NLM_F_MULTI);
> +   if (WARN_ON(!nlh))
> goto errout_skb;
>
> nl_dump_check_consistent(cb, nlh);
>
> -   memcpy(nlmsg_data(nlh), &len, sizeof(len));
> +   memcpy(nlmsg_data(nlh), &nlk->dump_done_errno,
> +  sizeof(nlk->dump_done_errno));
>
> if (sk_filter(sk, skb))
> kfree_skb(skb);
> @@ -2273,6 +2277,7 @@ int __netlink_dump_start(struct sock *ssk, struct 
> sk_buff *skb,
> }
>
> nlk->cb_running = true;
> +   nlk->dump_done_errno = INT_MAX;
>
> mutex_unlock(nlk->cb_mutex);
>
> diff --git a/net/netlink/af_netlink.h b/net/netlink/af_netlink.h
> index 028188597eaa..962de7b3c023 100644
> --- a/net/netlink/af_netlink.h
> +++ b/net/netlink/af_netlink.h
> @@ -34,6 +34,7 @@ struct netlink_sock {
> wait_queue_head_t   wait;
> boolbound;
> boolcb_running;
> +   int dump_done_errno;
> struct netlink_callback cb;
> struct mutex*cb_mutex;
> struct mutexcb_def_mutex;
> --
> 2.15.0
>


Re: [PATCH] staging: speakup: selection: replace _manual_ swap with swap macro

2017-11-10 Thread Samuel Thibault
Gustavo A. R. Silva, on ven. 10 nov. 2017 16:13:03 -0600, wrote:
> Make use of the swap macro instead of _manually_ swapping values
> and remove unnecessary variable tmp.
> 
> This makes the code easier to read and maintain.
> 
> This code was detected with the help of Coccinelle.
> 
> Signed-off-by: Gustavo A. R. Silva 

Acked-by: Samuel Thibault 

> ---
>  drivers/staging/speakup/selection.c | 9 ++---
>  1 file changed, 2 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/staging/speakup/selection.c 
> b/drivers/staging/speakup/selection.c
> index 66061b5..0ed1fef 100644
> --- a/drivers/staging/speakup/selection.c
> +++ b/drivers/staging/speakup/selection.c
> @@ -64,13 +64,8 @@ int speakup_set_selection(struct tty_struct *tty)
>   ps = spk_ys * vc->vc_size_row + (spk_xs << 1);
>   pe = spk_ye * vc->vc_size_row + (spk_xe << 1);
>  
> - if (ps > pe) {
> - /* make sel_start <= sel_end */
> - int tmp = ps;
> -
> - ps = pe;
> - pe = tmp;
> - }
> + if (ps > pe)/* make sel_start <= sel_end */
> + swap(ps, pe);
>  
>   if (spk_sel_cons != vc_cons[fg_console].d) {
>   speakup_clear_selection();
> -- 
> 2.7.4
> 

-- 
Samuel
 il faut combien de chevaux pour tirer une doloréan à 88 morph ?
***b vient de remarque que 88 mph c'est 142 km/h
 ah
 c'est pour ça qu'ils limitent à 130 km/h sur les autoroutes
 c'est pour éviter que les gens voyagent dans le temps
 probablement


Re: [PATCH] of: Document exactly what of_find_node_by_name() puts

2017-11-10 Thread Randy Dunlap
On 11/10/2017 05:45 PM, Stephen Boyd wrote:
> It isn't clear if this function of_node_put()s the 'from'
> argument, or the node it finds in the search. Clearly indicate
> which variable is touched.
> 
> Signed-off-by: Stephen Boyd 
> ---
>  drivers/of/base.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 63897531cd75..602c5d65734a 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -866,7 +866,7 @@ EXPORT_SYMBOL(of_find_node_opts_by_path);>   *@from:  
> The node to start searching from or NULL, the node

*   @from:  The node to start searching from or %NULL; the node

>   *   you pass will not be searched, only the next one
>   *   will; typically, you pass what the previous call

*   will. Typically, you pass what the previous call

> - *   returned. of_node_put() will be called on it
> + *   returned. of_node_put() will be called on @from.
>   *   @name:  The name string to match against
>   *
>   *   Returns a node pointer with refcount incremented, use
> 


-- 
~Randy


Re: [PATCH] tcp: Export to userspace the TCP state names for the trace events

2017-11-10 Thread Yafang Shao
2017-11-10 15:07 GMT+00:00 Steven Rostedt :
> On Fri, 10 Nov 2017 12:56:06 +0800
> Yafang Shao  wrote:
>
>> Could the macro tcp_state_name() be renamed ?
>> If  is included in include/net/tcp.h, it will
>
> Ideally, you don't want to include trace/events/*.h headers in other
> headers, as they can have side effects if those headers are included in
> other trace/events/*.h headers.
>

Actually I find trace/events/*.h is included in lots of other headers,
for example,

net/rxrpc/ar-internal.h
include/linux/bpf_trace.h
fs/f2fs/trace.h
fs/afs/internal.h
arch/x86/include/asm/mmu_context.h
...

Are these files doing properly ?
Should we fix them ?

But per my understanding, it is ok to include  trace/events/*.h in
other headers because we defined TRACE_SYSTEM as well, as a
consequence those headers should not included in trace/events/*.h. If
that happens, it may means that one of the these two TRACE_SYSTEM is
not defined properly. Maybe these two TRACE_SYSTEM should be merged to
one TRACE_SYSTEM.


>> cause compile error, because there's another function tcp_state_name()
>> defined in net/netfilter/ipvs/ip_vs_proto_tcp.c.
>> static const char * tcp_state_name(int state)
>> {
>>
>> if (state >= IP_VS_TCP_S_LAST)
>>
>> return "ERR!";
>>
>> return tcp_state_name_table[state] ? tcp_state_name_table[state] : 
>> "?";
>>
>> }
>
> But that said, I didn't make up the trace_state_name(), it was already
> there in net-next before this patch.
>

I know that is not your fault.
But as you are modifying this file, it is better to modify it in your
patch as well.
So we need not submit another new patch to fix it.

> But yeah, in actuality, I would have just done:
>
> #define EM(a)   { a, #a },
> #define EMe(a)  { a, #a }
>
> directly. Which we can still do.
>
> -- Steve
>

The suggestion from Song is good to fix it.

Thanks
Yafang


RE: [PATCH v17 5/6] vfio: ABI for mdev display dma-buf operation

2017-11-10 Thread Zhang, Tina


> -Original Message-
> From: intel-gvt-dev [mailto:intel-gvt-dev-boun...@lists.freedesktop.org] On
> Behalf Of Gerd Hoffmann
> Sent: Friday, November 10, 2017 3:03 PM
> To: Alex Williamson 
> Cc: Tian, Kevin ; Yuan, Hang ;
> Daniel Vetter ; intel-...@lists.freedesktop.org;
> joonas.lahti...@linux.intel.com; linux-kernel@vger.kernel.org;
> zhen...@linux.intel.com; ch...@chris-wilson.co.uk; kwankh...@nvidia.com;
> Lv, Zhiyuan ; dan...@ffwll.ch; Zhang, Tina
> ; intel-gvt-...@lists.freedesktop.org; Wang, Zhi A
> 
> Subject: Re: [PATCH v17 5/6] vfio: ABI for mdev display dma-buf operation
> 
> On Thu, Nov 09, 2017 at 01:54:57PM -0700, Alex Williamson wrote:
> > On Thu, 9 Nov 2017 19:35:14 +0100
> > Gerd Hoffmann  wrote:
> >
> > >   Hi,
> > >
> > > > struct vfio_device_gfx_plane_info lacks the head field we've been
> > > > discussing.  Thanks,
> > >
> > > Adding multihead support turned out to not be that easy.  There are
> > > corner cases like a single framebuffer spawning both heads.  Also it
> > > would be useful to somehow hint to the guest which heads it should use.
> > >
> > > In short:  Proper multihead support is more complex than just adding
> > > a head field for later use.  So in a short private discussion with
> > > Tina we came to the conclusion that it will be better add multihead
> > > support to the API when the first driver wants use it, so we can
> > > actually test the interface and make sure we didn't miss anything.
> > > Adding a incomplete multihead API now doesn't help anybody.
> >
> > Do you think we can enable multi-head and preserve backwards
> > compatibility within this API proposed here?
> 
> Yes, I think we can.  Adding new fields is possible thanks to the argsz field 
> at the
> start of the struct, so we easily add the new fields (head, framebuffer 
> rectangle,
> whatever else is needed).  If the new fields are not present the driver can 
> simply
> assume head=0.
> 
> Does the driver set argsz too?  If so userspace can detect whenever the driver
> supports the multihead API extension (before going to probe for
> head=1) that way.  If not we probably need an additional probe flag for that.
> But in any case I'm confident this is solvable.
> 
> Passing hints about the display configuration to the guest needs a new ioctl, 
> so
> we don't have compatibility issues there.
Thanks. So, do we all agree on this? If so, the next version will be submitted 
soon
with some updated comments.
Thanks.


BR,
Tina
> 
> cheers,
>   Gerd
> 
> ___
> intel-gvt-dev mailing list
> intel-gvt-...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gvt-dev


[PATCHv2] slub: Fix sysfs duplicate filename creation when slub_debug=O

2017-11-10 Thread miles.chen
From: Miles Chen 

When slub_debug=O is set. It is possible to clear debug flags
for an "unmergeable" slab cache in kmem_cache_open().
It makes the "unmergeable" cache became "mergeable" in sysfs_slab_add().

These caches will generate their "unique IDs" by create_unique_id(),
but it is possible to create identical unique IDs. In my experiment,
sgpool-128, names_cache, biovec-256 generate the same ID ":Ft-0004096"
and the kernel reports "sysfs: cannot create duplicate filename
'/kernel/slab/:Ft-0004096'".

To repeat my experiment, set disable_higher_order_debug=1,
CONFIG_SLUB_DEBUG_ON=y in kernel-4.14.

Fix this issue by setting unmergeable=1 if slub_debug=O and the
the default slub_debug contains any no-merge flags.

call path:
kmem_cache_create()
  __kmem_cache_alias()  -> we set SLAB_NEVER_MERGE flags here
  create_cache()
__kmem_cache_create()
  kmem_cache_open() -> clear DEBUG_METADATA_FLAGS
  sysfs_slab_add()  -> the slab cache is mergeable now

[0.674272] sysfs: cannot create duplicate filename 
'/kernel/slab/:Ft-0004096'
[0.674473] [ cut here ]
[0.674653] WARNING: CPU: 0 PID: 1 at fs/sysfs/dir.c:31 
sysfs_warn_dup+0x60/0x7c
[0.674847] Modules linked in:
[0.674969] CPU: 0 PID: 1 Comm: swapper/0 Tainted: GW   
4.14.0-rc7ajb-00131-gd4c2e9f-dirty #123
[0.675211] Hardware name: linux,dummy-virt (DT)
[0.675342] task: ffc07d4e0080 task.stack: ff8008008000
[0.675505] PC is at sysfs_warn_dup+0x60/0x7c
[0.675633] LR is at sysfs_warn_dup+0x60/0x7c
[0.675759] pc : [] lr : [] pstate: 
6145
[0.675948] sp : ff800800bb40
[0.676048] x29: ff800800bb40 x28: 0040
[0.676209] x27: ffc07c52a380 x26: 
[0.676369] x25: ff8008af4ad0 x24: ff8008af4000
[0.676528] x23: ffc07c532580 x22: ffc07cf04598
[0.676695] x21: ffc07cf26578 x20: ffc07c533700
[0.676857] x19: ffc07ce67000 x18: 0002
[0.677017] x17: 7ffe x16: 0007
[0.677176] x15: 0001 x14: 7fff
[0.677335] x13: 0394 x12: 
[0.677492] x11: 01ab x10: 0007
[0.677651] x9 : 01ac x8 : ff800835d114
[0.677809] x7 : 656b2f2720656d61 x6 : 0017
[0.677967] x5 : ffc07ffdb9a8 x4 : 
[0.678124] x3 :  x2 : 
[0.678282] x1 : ff8008a4e878 x0 : 0042
[0.678442] Call trace:
[0.678528] Exception stack(0xff800800ba00 to 0xff800800bb40)
[0.678706] ba00: 0042 ff8008a4e878  

[0.678914] ba20:  ffc07ffdb9a8 0017 
656b2f2720656d61
[0.679121] ba40: ff800835d114 01ac 0007 
01ab
[0.679326] ba60:  0394 7fff 
0001
[0.679532] ba80: 0007 7ffe 0002 
ffc07ce67000
[0.679739] baa0: ffc07c533700 ffc07cf26578 ffc07cf04598 
ffc07c532580
[0.679944] bac0: ff8008af4000 ff8008af4ad0  
ffc07c52a380
[0.680149] bae0: 0040 ff800800bb40 ff8008235808 
ff800800bb40
[0.680354] bb00: ff8008235808 6145 ffc07c533700 
62616c73
[0.680560] bb20:   ff800800bb40 
ff8008235808
[0.680774] [] sysfs_warn_dup+0x60/0x7c
[0.680928] [] sysfs_create_dir_ns+0x98/0xa0
[0.681095] [] kobject_add_internal+0xa0/0x294
[0.681267] [] kobject_init_and_add+0x90/0xb4
[0.681435] [] sysfs_slab_add+0x90/0x200
[0.681592] [] __kmem_cache_create+0x26c/0x438
[0.681769] [] kmem_cache_create+0x164/0x1f4
[0.681940] [] sg_pool_init+0x60/0x100
[0.682094] [] do_one_initcall+0x38/0x12c
[0.682254] [] kernel_init_freeable+0x138/0x1d4
[0.682423] [] kernel_init+0x10/0xfc
[0.682571] [] ret_from_fork+0x10/0x18

Signed-off-by: Miles Chen 
---
 mm/slub.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/mm/slub.c b/mm/slub.c
index 1efbb812..8e1c027 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -5704,6 +5704,10 @@ static int sysfs_slab_add(struct kmem_cache *s)
return 0;
}
 
+   if (!unmergeable && disable_higher_order_debug &&
+   (slub_debug & DEBUG_METADATA_FLAGS))
+   unmergeable = 1;
+
if (unmergeable) {
/*
 * Slabcache can never be merged so we can use the name proper.
-- 
1.9.1



Re: mmotm 2017-11-10-15-56 uploaded (lib/test_find_bit.c)

2017-11-10 Thread Randy Dunlap
On 11/10/2017 03:56 PM, a...@linux-foundation.org wrote:
> The mm-of-the-moment snapshot 2017-11-10-15-56 has been uploaded to
> 
>http://www.ozlabs.org/~akpm/mmotm/
> 
> mmotm-readme.txt says
> 
> README for mm-of-the-moment:
> 
> http://www.ozlabs.org/~akpm/mmotm/
> 
> This is a snapshot of my -mm patch queue.  Uploaded at random hopefully
> more than once a week.

on i386:

../lib/test_find_bit.c:54:2: warning: format '%ld' expects argument of type 
'long int', but argument 2 has type 'cycles_t' [-Wformat=]
../lib/test_find_bit.c:68:2: warning: format '%ld' expects argument of type 
'long int', but argument 2 has type 'cycles_t' [-Wformat=]
../lib/test_find_bit.c:82:2: warning: format '%ld' expects argument of type 
'long int', but argument 2 has type 'cycles_t' [-Wformat=]
../lib/test_find_bit.c:102:2: warning: format '%ld' expects argument of type 
'long int', but argument 2 has type 'cycles_t' [-Wformat=]



-- 
~Randy


[PATCH] of: Document exactly what of_find_node_by_name() puts

2017-11-10 Thread Stephen Boyd
It isn't clear if this function of_node_put()s the 'from'
argument, or the node it finds in the search. Clearly indicate
which variable is touched.

Signed-off-by: Stephen Boyd 
---
 drivers/of/base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 63897531cd75..602c5d65734a 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -866,7 +866,7 @@ EXPORT_SYMBOL(of_find_node_opts_by_path);
  * @from:  The node to start searching from or NULL, the node
  * you pass will not be searched, only the next one
  * will; typically, you pass what the previous call
- * returned. of_node_put() will be called on it
+ * returned. of_node_put() will be called on @from.
  * @name:  The name string to match against
  *
  * Returns a node pointer with refcount incremented, use
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH] usb: ulpi: Add missing of_node_get() in ulpi_of_register()

2017-11-10 Thread Stephen Boyd
In ulpi_of_register() we call of_find_node_by_name() which
unconditionally calls of_node_put() on the 'from' argument. We
haven't called of_node_get() though, so we've put the node once
without getting it first. Add the of_node_get() call so that
things are properly balanced.

Fixes: ef6a7bcfb01c ("usb: ulpi: Support device discovery via DT")
Reported-by: Peter Robinson 
Signed-off-by: Stephen Boyd 
---
 drivers/usb/common/ulpi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c
index 4aa5195db8ea..59e05eff76f9 100644
--- a/drivers/usb/common/ulpi.c
+++ b/drivers/usb/common/ulpi.c
@@ -182,9 +182,9 @@ static int ulpi_of_register(struct ulpi *ulpi)
 
/* Find a ulpi bus underneath the parent or the grandparent */
parent = ulpi->dev.parent;
-   if (parent->of_node)
+   if (of_node_get(parent->of_node))
np = of_find_node_by_name(parent->of_node, "ulpi");
-   else if (parent->parent && parent->parent->of_node)
+   else if (parent->parent && of_node_get(parent->parent->of_node))
np = of_find_node_by_name(parent->parent->of_node, "ulpi");
if (!np)
return 0;
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



Re: [PATCH v2 1/6] PM / core: Add LEAVE_SUSPENDED driver flag

2017-11-10 Thread Rafael J. Wysocki
On Sat, Nov 11, 2017 at 12:45 AM, Rafael J. Wysocki  wrote:
> On Fri, Nov 10, 2017 at 10:09 AM, Ulf Hansson  wrote:
>> On 8 November 2017 at 14:25, Rafael J. Wysocki  wrote:

[cut]

>> Moreover, you should check the return value from
>> pm_runtime_set_suspended().
>
> This is in "noirq", so failures of that are meaningless here.

They *should* be meaningless, but __pm_runtime_set_status() is sort of
buggy and checks child_count regardless of whether or not runtime PM
is enabled for the children (but when changing the status to "active"
it actually checks if runtime PM is enabled for the parent before
returning -EBUSY, so it is not event consistent internally).  Oh well.

>> Then I wonder, what should you do when it fails here?
>>
>> Perhaps a better idea is to do this in the noirq suspend phase,
>> because it allows you to bail out in case pm_runtime_set_suspended()
>> fails.
>
> This doesn't make sense, sorry.

Not for the above reason, but that would allow the bug in
__pm_runtime_set_status() to be sort of worked around by setting the
status to "suspended" for children before doing that for their
parents.

Moreover, stuff with nonzero usage_counts cannot be left in suspend regardless.

Thanks,
Rafael


Re: [PATCH] firmware: cleanup - group and document up private firmware parameters

2017-11-10 Thread Luis R. Rodriguez
On Mon, Sep 18, 2017 at 05:15:01PM +0200, Greg KH wrote:
> On Thu, Sep 14, 2017 at 03:54:22PM -0700, Luis R. Rodriguez wrote:
> > +enum fw_priv_reqs {
> > +   FW_PRIV_REQ_FALLBACK= 1 << 0,
> > +   FW_PRIV_REQ_FALLBACK_UEVENT = 1 << 1,
> > +   FW_PRIV_REQ_NO_CACHE= 1 << 2,
> > +   FW_PRIV_REQ_OPTIONAL= 1 << 3,
> > +};
> 
> checkpatch.pl didn't complain about a lack of using BIT()?

Fixed.

> > +struct fw_priv_params {
> > +   enum fw_api_mode mode;
> > +   u64 priv_reqs;
> 
> Agreed that this should not be "priv_reqs" but some other better name.

Went with pri_-flags.

> > +   void *alloc_buf;
> > +   size_t alloc_buf_size;
> > +};
> > +
> > +#define fw_req_param_sync(priv_params) 
> > \
> > +   (priv_params->mode == FW_API_SYNC)
> > +#define fw_req_param_async(priv_params)
> > \
> > +   (priv_params->mode == FW_API_ASYNC)
> > +
> > +#define fw_param_use_fallback(params)  
> > \
> > +   (!!((params)->priv_reqs & FW_PRIV_REQ_FALLBACK))
> > +#define fw_param_uevent(params)
> > \
> > +   (!!((params)->priv_reqs & FW_PRIV_REQ_FALLBACK_UEVENT))
> > +#define fw_param_nocache(params)   \
> > +   (!!((params)->priv_reqs & FW_PRIV_REQ_NO_CACHE))
> > +#define fw_param_optional(params)  \
> > +   (!!((params)->priv_reqs & FW_PRIV_REQ_OPTIONAL))
> 
> static inline functions to get proper typechecking?

Sure!

> >  static bool fw_get_builtin_firmware(struct firmware *fw, const char *name,
> > -   void *buf, size_t size)
> > +   struct fw_priv_params *fw_priv_params)
> 
> Shouldn't the priv pointer hang off of 'struct firmware' in an opaque
> type that can not be seen/accessed outside of this file?
>
> That way you don't have to change the functions by adding new
> parameters, what you did seems a lot more complex.

Excellent point!

Note that we already have and use a priv opaque pointer, its however only a buf
pointer really though, I could extend this while looking at doing just that
I noticed that we also already have a "struct firmware_priv" but this is
really only used for the sysfs interface loading functionality. Adding
yet another private pointer is only going to make things more confusing,
so I'll go rename that accordingly and try to consolidate what I can so that
this patch itself is much smaller and easier to read.

Thanks for the feedback!

  Luis


Re: [PATCH] firmware: cleanup - group and document up private firmware parameters

2017-11-10 Thread Luis R. Rodriguez
On Fri, Sep 15, 2017 at 10:30:46AM +0200, Martin Fuzzey wrote:
> On 15/09/17 00:54, Luis R. Rodriguez wrote:
> > The above benefits makes the code much easier to understand and maintain.
> 
> Yes I agree it is much cleaner that way.
> 
> A couple of nitpicks below.
> 
> > +/**
> > + * enum fw_priv_reqs - private features only used internally
> > + *
> > + * @FW_PRIV_REQ_FALLBACK: specifies that the firmware request
> > + * will use a fallback mechanism if the kernel's direct filesystem
> > + * lookup failed to find the requested firmware. If the flag
> > + * %FW_PRIV_REQ_FALLBACK is set but the flag
> > + * %FW_PRIV_REQ_FALLBACK_UEVENT is not set, it means the caller
> > + * is relying on a custom fallback mechanism for firmwarwe lookup as a
> > + * fallback mechanism. The custom fallback mechanism is expected to find
> > + * any found firmware using the exposed sysfs interface of the
> > + * firmware_class.  Since the custom fallback mechanism is not compatible
> > + * with the internal caching mechanism for firmware lookups at resume,
> > + * caching will be disabled when the custom fallback mechanism is used.
> > + * @FW_PRIV_REQ_FALLBACK_UEVENT: indicates that the fallback mechanism
> > + * this firmware request will rely on will be that of having the kernel
> > + * issue a uevent to userspace. Userspace in turn is expected to be
> > + * monitoring for uevents for the firmware_class and will use the
> > + * exposted sysfs interface to upload the firmware for the caller.
> > + * @FW_PRIV_REQ_NO_CACHE: indicates that the firmware request
> > + * should not set up and use the internal caching mechanism to assist
> > + * drivers from fetching firmware at resume time after suspend.
> > + * @FW_PRIV_REQ_OPTIONAL: if set it is not a hard requirement by the
> > + * caller that the file requested be present. An error will not be recorded
> > + * if the file is not found.
> > + */
> > +enum fw_priv_reqs {
> > +   FW_PRIV_REQ_FALLBACK= 1 << 0,
> > +   FW_PRIV_REQ_FALLBACK_UEVENT = 1 << 1,
> > +   FW_PRIV_REQ_NO_CACHE= 1 << 2,
> > +   FW_PRIV_REQ_OPTIONAL= 1 << 3,
> > +};
> > +
> 
> Why REQ ?
> Looks more like a set of flags to me.
> Wouldn't FW_PRIV_FLAG_XXX be better?

Sure, its much better without anything so will just go with FW_PRIV_ as the
prefix.

> > +/**
> > + * struct fw_priv_params - private firmware parameters
> > + * @mode: mode of operation
> > + * @priv_reqs: private set of &enum fw_priv_reqs, private requirements for
> > + * the firmware request
> > + * @alloc_buf: buffer area allocated by the caller so we can place the
> > + * respective firmware
> > + * @alloc_buf_size: size of the @alloc_buf
> > + */
> > +struct fw_priv_params {
> > +   enum fw_api_mode mode;
> > +   u64 priv_reqs;
> 
> Not sure the priv_ prefix in the priv_reqs is necessary since the whole
> structure is private.
> I'd have named it just flags.

Went with priv_flags.

Thanks for the feedback!

  Luis


Re: [PATCH] random: add regrand

2017-11-10 Thread Jörn Engel
Forgot to Cc: linux-kernel.

On Fri, Nov 10, 2017 at 01:30:39PM -0800, Jörn Engel wrote:
> Regrand is a replacement for drivers/char/random.c.  It is supposed to
> achieve the following design goals:
> 
> 1. /dev/random shall never block.
> 2. /dev/urandom shall never return bad randomness.
> 3. Any machine supported by Linux must have good randomness.
> 4. Any entropy source that is unavailable on some machines is useless.
> 5. By the time we start userspace, the random pool must be fully initialized.
> 6. Entropy never gets XOR'ed, always hashed.
> 7. In-kernel users never receive bad randomness.
> 
> I believe it achieves all but the last.  Sadly there are a few
> exceptions where random numbers are consumed before the entropy pool can
> be initialized.  In contrast, I believe current drivers/char/random.c
> achieves none of the above.
> 
> That is a pretty bold claim, so please try to poke holes.  For the
> moment, I think regrand should be optional and users should decide which
> random number generator they trust more.  Maybe after a year or two,
> provided noone manages to find a problem in regrand, it can be made the
> default.
> 
> Copyright for regrand proper is Public Domain.  Feel free to port the
> version in Documentation/regrand.c to any OS.  Most of the code in
> drivers/char/regrand.c is copied from either crypto/sha3_generic.c or
> drivers/char/random.c.  I didn't want to go through crypto API to access
> sha3 code and had to implement an interface compatible to the existing
> random number generator.  Regrand proper is tiny in comparison.
> 
> Happy reading.
> 
> Signed-off-by: Joern Engel 
> ---
>  Documentation/regrand.c   | 365 ++
>  arch/Kconfig  |   1 +
>  arch/x86/include/asm/stackprotector.h |   2 +-
>  arch/x86/kernel/apic/apic.c   |   2 +
>  drivers/char/Kconfig  |  11 +
>  drivers/char/Makefile |   7 +-
>  drivers/char/regrand.c| 673 
> ++
>  include/linux/genhd.h |   5 +
>  include/linux/hw_random.h |   4 +
>  include/linux/random.h|  25 +-
>  kernel/fork.c |   2 +-
>  kernel/panic.c|   2 +-
>  mm/slab.c |   2 +-
>  mm/slab_common.c  |   4 +-
>  mm/slub.c |   5 +-
>  15 files changed, 1093 insertions(+), 17 deletions(-)
>  create mode 100644 Documentation/regrand.c
>  create mode 100644 drivers/char/regrand.c
> 
> diff --git a/Documentation/regrand.c b/Documentation/regrand.c
> new file mode 100644
> index ..07a1b87c2bb7
> --- /dev/null
> +++ b/Documentation/regrand.c
> @@ -0,0 +1,365 @@
> +/*
> + * regrand - Random number generator using register state at time of
> + * interrupt.  Uses the same principle as Dakarand, drift between two
> + * unsynchronized high-precision timers, as entropy source.  Should
> + * work reasonably well on any CPU that can generate interrupts.
> + *
> + * Public Domain
> + */
> +#error ADD INCLUDES
> +
> +/*
> + * Based on a million boots, each interrupt seems to yield about 10-15
> + * bits of entropy.  That means 20 samples might be enough for
> + * cryptographically strong random numbers.  Naturally we want more to
> + * give us a comfortable safety margin.  128 should be good enough.
> + */
> +#define SAMPLES_NEEDED   (128)   // [2]
> +
> +#define  ACCESS_ONCE(x)  (*(volatile __typeof(x) *)&(x))
> +
> +/* 256b hash value */
> +struct half_hash {   // [1]
> + uint64_t h[4];
> +};
> +
> +/* 512b hash value */
> +struct full_hash {   // [1]
> + union {
> + struct half_hash half[2];
> + uint64_t h[8];
> + };
> +};
> +
> +struct per_cpu_state {   // [3]
> + struct half_hash half;  /* 256 bits of state */
> + uint64_t p_time;/* last time we produced entropy */
> + uint64_t c_time;/* last time we consumed entropy */
> +};
> +
> +static struct half_hash global_pool; // [3]
> +static int uninitialized_count = INT_MAX;// [8]
> +static int global_lock;  // [4]
> +
> +static struct per_cpu_state *get_local_state(void)   // [5]
> +{
> +#error FILL ME IN
> + /*
> +  * Should return a pointer to per-cpu state.  Most RNG
> +  * operations are done on local state, without cacheline
> +  * pingpong causing unnecessary slowdowns.
> +  * Bonus points if the pointer is cacheline-aligned.  The
> +  * structure size of 64 bytes is chosen to fit into
> +  * 1-2 cachelines in most architectures.
> +  */
> +}
> +
> +static uint64_t get_time(void)   // [5]
> +{
> +

Re: [nfsd4] potentially hardware breaking regression in 4.14-rc and 4.13.11

2017-11-10 Thread J. Bruce Fields
On Fri, Nov 10, 2017 at 03:26:27PM -0800, Patrick McLean wrote:
> 
> 
> On 2017-11-10 10:42 AM, Linus Torvalds wrote:
> > On Thu, Nov 9, 2017 at 5:58 PM, Patrick McLean  wrote:
> >>
> >> Something must have changed since 4.13.8 to trigger this though.
> > 
> > Arnd pointed to some commits that might be relevant for the cp210x
> > module, but those are all already in 4.13.8, so if 4.13.8 really is
> > rock solid for you, I don't think that's it.
> > 
> > I really don't see anything that looks even half-way suspicious in
> > that 4.13.8..11 range. But as mentioned, compiler interactions can be
> > _really_ subtle.
> > 
> > And hey, it can be a real kernel bug too, that just happens to be
> > exposed by RANDSTRUCT, so a bisect really would be very nice.
> 
> I am working on bisecting the issue now, but I think I have some more
> evidence pointing to a compiler issue related to RANDSTRUCT. There are
> actually 3 issues that we have seen. Sometimes we get the null pointer
> deref in the initial message, sometimes we get the GPF, and sometimes we
> see an issue where the NFS clients see all files as root-owned
> directories.

That suggests that stat.uid is 0 and stat.mode & S_IFMT is 004 in
the stat structure that nfsd passed to vfs_getattr().

No idea what sort of information is useful when tracking down this kind
of bug, but you could also run wireshark and take a look at the server's
GETATTR replies to see if there's some other corruption.

--b.

> Any given kernel will always see the same issue, but after
> a "make mrproper" and recompile (with the same .config), the issue will
> often change. I suspect that all 3 of these problems are actually the
> same issue manifesting itself in different ways depending on what seed
> the RANDSTRUCT gcc plugin is using.
> 
> > 
> > Because in the end, compiler bugs are very rare. They are particularly
> > annoying when they do happen, though, so they loom big in the mind of
> > people who have had to chase them down.
> > 


RE: [PATCH V0 2/3] perf/x86/intel/bm.c: Add Intel Branch Monitoring support

2017-11-10 Thread Dey, Megha


>-Original Message-
>From: Jiri Olsa [mailto:jo...@redhat.com]
>Sent: Saturday, November 4, 2017 6:26 AM
>To: Megha Dey 
>Cc: x...@kernel.org; linux-kernel@vger.kernel.org; linux-
>d...@vger.kernel.org; t...@linutronix.de; mi...@redhat.com;
>h...@zytor.com; andriy.shevche...@linux.intel.com;
>kstew...@linuxfoundation.org; Yu, Yu-cheng ;
>Brown, Len ; gre...@linuxfoundation.org;
>pet...@infradead.org; a...@kernel.org;
>alexander.shish...@linux.intel.com; namhy...@kernel.org;
>vikas.shiva...@linux.intel.com; pombreda...@nexb.com;
>m...@kylehuey.com; b...@suse.de; Andrejczuk, Grzegorz
>; Luck, Tony ;
>cor...@lwn.net; Shankar, Ravi V ; Dey, Megha
>
>Subject: Re: [PATCH V0 2/3] perf/x86/intel/bm.c: Add Intel Branch
>Monitoring support
>
>On Fri, Nov 03, 2017 at 11:00:05AM -0700, Megha Dey wrote:
>
>SNIP
>
>> +
>> +static void intel_bm_event_update(struct perf_event *event) {
>> +union bm_detect_status cur_stat;
>> +
>> +rdmsrl(BR_DETECT_STATUS_MSR, cur_stat.raw);
>> +local64_set(&event->hw.prev_count, (uint64_t)cur_stat.raw); }
>> +
>> +static void intel_bm_event_stop(struct perf_event *event, int mode) {
>> +wrmsrl(BR_DETECT_COUNTER_CONFIG_BASE + event->id,
>> +   (event->hw.bm_counter_conf & ~1));
>> +
>> +intel_bm_event_update(event);
>> +}
>> +
>> +static void intel_bm_event_del(struct perf_event *event, int flags) {
>> +intel_bm_event_stop(event, flags);
>> +}
>> +
>> +static void intel_bm_event_read(struct perf_event *event) { }
>
>should you call intel_bm_event_update in here? so the read syscall gets
>updated data in case the case the event is active

We do not update the event->count in the intel_bm_event_update function. We are 
basically saving the status register contents when a task is being scheduled 
out. So it has nothing to do with the read syscall. Having said that, I will 
probably put what stop() does in del() and get rid of the stop() function.
>
>jirka


[PATCH 1/4] mm: fix device-dax pud write-faults triggered by get_user_pages()

2017-11-10 Thread Dan Williams
Currently only get_user_pages_fast() can safely handle the writable gup
case due to its use of pud_access_permitted() to check whether the pud
entry is writable. In the gup slow path pud_write() is used instead of
pud_access_permitted() and to date it has been unimplemented, just calls
BUG_ON().

kernel BUG at ./include/linux/hugetlb.h:244!
[..]
RIP: 0010:follow_devmap_pud+0x482/0x490
[..]
Call Trace:
 follow_page_mask+0x28c/0x6e0
 __get_user_pages+0xe4/0x6c0
 get_user_pages_unlocked+0x130/0x1b0
 get_user_pages_fast+0x89/0xb0
 iov_iter_get_pages_alloc+0x114/0x4a0
 nfs_direct_read_schedule_iovec+0xd2/0x350
 ? nfs_start_io_direct+0x63/0x70
 nfs_file_direct_read+0x1e0/0x250
 nfs_file_read+0x90/0xc0

For now this just implements a simple check for the _PAGE_RW bit similar
to pmd_write. However, this implies that the gup-slow-path check is
missing the extra checks that the gup-fast-path performs with
pud_access_permitted. Later patches will align all checks to use the
'access_permitted' helper if the architecture provides it. Note that the
generic 'access_permitted' helper fallback is the simple _PAGE_RW check
on architectures that do not define the 'access_permitted' helper(s).

Cc: 
Cc: Dave Hansen 
Cc: Kirill A. Shutemov 
Fixes: a00cc7d9dd93 ("mm, x86: add support for PUD-sized transparent hugepages")
Signed-off-by: Dan Williams 
---
 arch/x86/include/asm/pgtable.h |6 ++
 include/asm-generic/pgtable.h  |9 +
 include/linux/hugetlb.h|8 
 3 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
index f735c3016325..5c396724fd0d 100644
--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -1093,6 +1093,12 @@ static inline void pmdp_set_wrprotect(struct mm_struct 
*mm,
clear_bit(_PAGE_BIT_RW, (unsigned long *)pmdp);
 }
 
+#define __HAVE_ARCH_PUD_WRITE
+static inline int pud_write(pud_t pud)
+{
+   return pud_flags(pud) & _PAGE_RW;
+}
+
 /*
  * clone_pgd_range(pgd_t *dst, pgd_t *src, int count);
  *
diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
index 757dc6ffc7ba..bd738624bd16 100644
--- a/include/asm-generic/pgtable.h
+++ b/include/asm-generic/pgtable.h
@@ -812,6 +812,15 @@ static inline int pmd_write(pmd_t pmd)
return 0;
 }
 #endif /* __HAVE_ARCH_PMD_WRITE */
+
+#ifndef __HAVE_ARCH_PUD_WRITE
+static inline int pud_write(pud_t pud)
+{
+   BUG();
+   return 0;
+}
+#endif /* __HAVE_ARCH_PUD_WRITE */
+
 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
 
 #if !defined(CONFIG_TRANSPARENT_HUGEPAGE) || \
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index fbf5b31d47ee..82a25880714a 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -239,14 +239,6 @@ static inline int pgd_write(pgd_t pgd)
 }
 #endif
 
-#ifndef pud_write
-static inline int pud_write(pud_t pud)
-{
-   BUG();
-   return 0;
-}
-#endif
-
 #define HUGETLB_ANON_FILE "anon_hugepage"
 
 enum {



[PATCH 3/4] mm: replace pmd_write with pmd_access_permitted in fault + gup paths

2017-11-10 Thread Dan Williams
The 'access_permitted' helper is used in the gup-fast path and goes
beyond the simple _PAGE_RW check to also:

* validate that the mapping is writable from a protection keys
  standpoint

* validate that the pte has _PAGE_USER set since all fault paths where
  pmd_write is must be referencing user-memory.

Cc: Dave Hansen 
Cc: Kirill A. Shutemov 
Cc: "Jérôme Glisse" 
Signed-off-by: Dan Williams 
---
 arch/sparc/mm/gup.c |2 +-
 fs/dax.c|3 ++-
 mm/hmm.c|4 ++--
 mm/huge_memory.c|4 ++--
 mm/memory.c |2 +-
 5 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/arch/sparc/mm/gup.c b/arch/sparc/mm/gup.c
index 5ae2d0a01a70..33c0f8bb0f33 100644
--- a/arch/sparc/mm/gup.c
+++ b/arch/sparc/mm/gup.c
@@ -75,7 +75,7 @@ static int gup_huge_pmd(pmd_t *pmdp, pmd_t pmd, unsigned long 
addr,
if (!(pmd_val(pmd) & _PAGE_VALID))
return 0;
 
-   if (write && !pmd_write(pmd))
+   if (!pmd_access_permitted(pmd, write))
return 0;
 
refs = 0;
diff --git a/fs/dax.c b/fs/dax.c
index f001d8c72a06..3cc40eebbb9e 100644
--- a/fs/dax.c
+++ b/fs/dax.c
@@ -620,7 +620,8 @@ static void dax_mapping_entry_mkclean(struct address_space 
*mapping,
 
if (pfn != pmd_pfn(*pmdp))
goto unlock_pmd;
-   if (!pmd_dirty(*pmdp) && !pmd_write(*pmdp))
+   if (!pmd_dirty(*pmdp)
+   && !pmd_access_permitted(*pmdp, WRITE))
goto unlock_pmd;
 
flush_cache_page(vma, address, pfn);
diff --git a/mm/hmm.c b/mm/hmm.c
index a88a847bccba..cbdd47bf6a48 100644
--- a/mm/hmm.c
+++ b/mm/hmm.c
@@ -391,11 +391,11 @@ static int hmm_vma_walk_pmd(pmd_t *pmdp,
if (pmd_protnone(pmd))
return hmm_vma_walk_clear(start, end, walk);
 
-   if (write_fault && !pmd_write(pmd))
+   if (!pmd_access_permitted(pmd, write_fault))
return hmm_vma_walk_clear(start, end, walk);
 
pfn = pmd_pfn(pmd) + pte_index(addr);
-   flag |= pmd_write(pmd) ? HMM_PFN_WRITE : 0;
+   flag |= pmd_access_permitted(pmd, WRITE) ? HMM_PFN_WRITE : 0;
for (; addr < end; addr += PAGE_SIZE, i++, pfn++)
pfns[i] = hmm_pfn_t_from_pfn(pfn) | flag;
return 0;
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 1e4e11275856..411ba3ba45f8 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -875,7 +875,7 @@ struct page *follow_devmap_pmd(struct vm_area_struct *vma, 
unsigned long addr,
 */
WARN_ONCE(flags & FOLL_COW, "mm: In follow_devmap_pmd with FOLL_COW 
set");
 
-   if (flags & FOLL_WRITE && !pmd_write(*pmd))
+   if (!pmd_access_permitted(*pmd, flags & FOLL_WRITE))
return NULL;
 
if (pmd_present(*pmd) && pmd_devmap(*pmd))
@@ -1379,7 +1379,7 @@ int do_huge_pmd_wp_page(struct vm_fault *vmf, pmd_t 
orig_pmd)
  */
 static inline bool can_follow_write_pmd(pmd_t pmd, unsigned int flags)
 {
-   return pmd_write(pmd) ||
+   return pmd_access_permitted(pmd, WRITE) ||
   ((flags & FOLL_FORCE) && (flags & FOLL_COW) && pmd_dirty(pmd));
 }
 
diff --git a/mm/memory.c b/mm/memory.c
index 64f86beadcca..157fd4320bb3 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -4020,7 +4020,7 @@ static int __handle_mm_fault(struct vm_area_struct *vma, 
unsigned long address,
if (pmd_protnone(orig_pmd) && vma_is_accessible(vma))
return do_huge_pmd_numa_page(&vmf, orig_pmd);
 
-   if (dirty && !pmd_write(orig_pmd)) {
+   if (dirty && !pmd_access_permitted(orig_pmd, WRITE)) {
ret = wp_huge_pmd(&vmf, orig_pmd);
if (!(ret & VM_FAULT_FALLBACK))
return ret;



[PATCH 4/4] mm: replace pte_write with pte_access_permitted in fault + gup paths

2017-11-10 Thread Dan Williams
The 'access_permitted' helper is used in the gup-fast path and goes
beyond the simple _PAGE_RW check to also:

* validate that the mapping is writable from a protection keys
  standpoint

* validate that the pte has _PAGE_USER set since all fault paths where
  pte_write is must be referencing user-memory.

Cc: Dave Hansen 
Cc: Kirill A. Shutemov 
Cc: "Jérôme Glisse" 
Signed-off-by: Dan Williams 
---
 mm/gup.c|2 +-
 mm/hmm.c|4 ++--
 mm/memory.c |4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/mm/gup.c b/mm/gup.c
index b2b4d4263768..bb6542c47b08 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -66,7 +66,7 @@ static int follow_pfn_pte(struct vm_area_struct *vma, 
unsigned long address,
  */
 static inline bool can_follow_write_pte(pte_t pte, unsigned int flags)
 {
-   return pte_write(pte) ||
+   return pte_access_permitted(pte, WRITE) ||
((flags & FOLL_FORCE) && (flags & FOLL_COW) && pte_dirty(pte));
 }
 
diff --git a/mm/hmm.c b/mm/hmm.c
index cbdd47bf6a48..3d2e49fd851a 100644
--- a/mm/hmm.c
+++ b/mm/hmm.c
@@ -456,11 +456,11 @@ static int hmm_vma_walk_pmd(pmd_t *pmdp,
continue;
}
 
-   if (write_fault && !pte_write(pte))
+   if (!pte_access_permitted(pte, write_fault))
goto fault;
 
pfns[i] = hmm_pfn_t_from_pfn(pte_pfn(pte)) | flag;
-   pfns[i] |= pte_write(pte) ? HMM_PFN_WRITE : 0;
+   pfns[i] |= pte_access_permitted(pte, WRITE) ? HMM_PFN_WRITE : 0;
continue;
 
 fault:
diff --git a/mm/memory.c b/mm/memory.c
index 157fd4320bb3..a8cbc2c3e3c9 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -3922,7 +3922,7 @@ static int handle_pte_fault(struct vm_fault *vmf)
if (unlikely(!pte_same(*vmf->pte, entry)))
goto unlock;
if (vmf->flags & FAULT_FLAG_WRITE) {
-   if (!pte_write(entry))
+   if (!pte_access_permitted(entry, WRITE))
return do_wp_page(vmf);
entry = pte_mkdirty(entry);
}
@@ -4308,7 +4308,7 @@ int follow_phys(struct vm_area_struct *vma,
goto out;
pte = *ptep;
 
-   if ((flags & FOLL_WRITE) && !pte_write(pte))
+   if (!pte_access_permitted(pte, flags & FOLL_WRITE))
goto unlock;
 
*prot = pgprot_val(pte_pgprot(pte));



[PATCH 2/4] mm: replace pud_write with pud_access_permitted in fault + gup paths

2017-11-10 Thread Dan Williams
The 'access_permitted' helper is used in the gup-fast path and goes
beyond the simple _PAGE_RW check to also:

* validate that the mapping is writable from a protection keys
  standpoint

* validate that the pte has _PAGE_USER set since all fault paths where
  pud_write is must be referencing user-memory.

Cc: Dave Hansen 
Cc: "David S. Miller" 
Cc: Kirill A. Shutemov 
Signed-off-by: Dan Williams 
---
 arch/sparc/mm/gup.c |2 +-
 mm/huge_memory.c|2 +-
 mm/memory.c |2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/sparc/mm/gup.c b/arch/sparc/mm/gup.c
index 5335ba3c850e..5ae2d0a01a70 100644
--- a/arch/sparc/mm/gup.c
+++ b/arch/sparc/mm/gup.c
@@ -114,7 +114,7 @@ static int gup_huge_pud(pud_t *pudp, pud_t pud, unsigned 
long addr,
if (!(pud_val(pud) & _PAGE_VALID))
return 0;
 
-   if (write && !pud_write(pud))
+   if (!pud_access_permitted(pud, write))
return 0;
 
refs = 0;
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 1981ed697dab..1e4e11275856 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -1022,7 +1022,7 @@ struct page *follow_devmap_pud(struct vm_area_struct 
*vma, unsigned long addr,
 
assert_spin_locked(pud_lockptr(mm, pud));
 
-   if (flags & FOLL_WRITE && !pud_write(*pud))
+   if (!pud_access_permitted(*pud, flags & FOLL_WRITE))
return NULL;
 
if (pud_present(*pud) && pud_devmap(*pud))
diff --git a/mm/memory.c b/mm/memory.c
index a728bed16c20..64f86beadcca 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -3987,7 +3987,7 @@ static int __handle_mm_fault(struct vm_area_struct *vma, 
unsigned long address,
 
/* NUMA case for anonymous PUDs would go here */
 
-   if (dirty && !pud_write(orig_pud)) {
+   if (dirty && !pud_access_permitted(orig_pud, WRITE)) {
ret = wp_huge_pud(&vmf, orig_pud);
if (!(ret & VM_FAULT_FALLBACK))
return ret;



[PATCH 0/4] fix device-dax pud crash and fixup {pte,pmd,pud}_write

2017-11-10 Thread Dan Williams
Andrew,

Here is a new version to the pud_write() fix [1], and some follow-on
patches to use the '_access_permitted' helpers in fault and
get_user_pages() paths where we are checking if the thread has access to
write. I explicitly omit conversions for places where the kernel is
checking the _PAGE_RW flag for kernel purposes, not for userspace
access.

Beyond fixing the crash, this series also fixes get_user_pages() and
fault paths to honor protection keys in the same manner as
get_user_pages_fast(). Only the crash fix is tagged for -stable as the
protection key check is done just for consistency reasons since
userspace can change protection keys at will.

[1]: https://lists.01.org/pipermail/linux-nvdimm/2017-November/013237.html

---

Dan Williams (4):
  mm: fix device-dax pud write-faults triggered by get_user_pages()
  mm: replace pud_write with pud_access_permitted in fault + gup paths
  mm: replace pmd_write with pmd_access_permitted in fault + gup paths
  mm: replace pte_write with pte_access_permitted in fault + gup paths


 arch/sparc/mm/gup.c|4 ++--
 arch/x86/include/asm/pgtable.h |6 ++
 fs/dax.c   |3 ++-
 include/asm-generic/pgtable.h  |9 +
 include/linux/hugetlb.h|8 
 mm/gup.c   |2 +-
 mm/hmm.c   |8 
 mm/huge_memory.c   |6 +++---
 mm/memory.c|8 
 9 files changed, 31 insertions(+), 23 deletions(-)


Re: [f2fs-dev] [PATCH] f2fs: validate before set/clear free nat bitmap

2017-11-10 Thread Chao Yu
On 2017/11/10 15:41, LiFan wrote:
> In flush_nat_entries, all dirty nats will be flushed and if
> their new address isn't NULL_ADDR, their bitmaps will be updated,
> the free_nid_count of the bitmaps will be increaced regardless
> of whether the nats have already been occupied before.
> This could lead to wrong free_nid_count.
> So this patch checks the status of the bits beforeactually
> set/clear them.

Thanks for fixing this. :)

Please add:

Fixes: 586d1492f301 ("f2fs: skip scanning free nid bitmap of full NAT blocks")

> 
> Signed-off-by: Fan li 

Reviewed-by: Chao Yu 

Thanks,

> ---
>  fs/f2fs/node.c | 17 ++---
>  1 file changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
> index d234c6e..b965a53 100644
> --- a/fs/f2fs/node.c
> +++ b/fs/f2fs/node.c
> @@ -1906,15 +1906,18 @@ static void update_free_nid_bitmap(struct
> f2fs_sb_info *sbi, nid_t nid,
>   if (!test_bit_le(nat_ofs, nm_i->nat_block_bitmap))
>   return;
>  
> - if (set)
> + if (set) {
> + if (test_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]))
> + return;
>   __set_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]);
> - else
> - __clear_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]);
> -
> - if (set)
>   nm_i->free_nid_count[nat_ofs]++;
> - else if (!build)
> - nm_i->free_nid_count[nat_ofs]--;
> + } else {
> + if (!test_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]))
> + return;
> + __clear_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]);
> + if (!build)
> + nm_i->free_nid_count[nat_ofs]--;
> + }
>  }
>  
>  static void scan_nat_page(struct f2fs_sb_info *sbi,
> 


RE: [PATCH V0 2/3] perf/x86/intel/bm.c: Add Intel Branch Monitoring support

2017-11-10 Thread Dey, Megha


>-Original Message-
>From: Jiri Olsa [mailto:jo...@redhat.com]
>Sent: Saturday, November 4, 2017 6:26 AM
>To: Megha Dey 
>Cc: x...@kernel.org; linux-kernel@vger.kernel.org; linux-
>d...@vger.kernel.org; t...@linutronix.de; mi...@redhat.com;
>h...@zytor.com; andriy.shevche...@linux.intel.com;
>kstew...@linuxfoundation.org; Yu, Yu-cheng ;
>Brown, Len ; gre...@linuxfoundation.org;
>pet...@infradead.org; a...@kernel.org;
>alexander.shish...@linux.intel.com; namhy...@kernel.org;
>vikas.shiva...@linux.intel.com; pombreda...@nexb.com;
>m...@kylehuey.com; b...@suse.de; Andrejczuk, Grzegorz
>; Luck, Tony ;
>cor...@lwn.net; Shankar, Ravi V ; Dey, Megha
>
>Subject: Re: [PATCH V0 2/3] perf/x86/intel/bm.c: Add Intel Branch
>Monitoring support
>
>On Fri, Nov 03, 2017 at 11:00:05AM -0700, Megha Dey wrote:
>
>SNIP
>
>> +static unsigned int bm_threshold = BM_MAX_THRESHOLD; static
>unsigned
>> +int bm_mispred_evt_cnt;
>> +
>> +/* Branch monitoring counter owners */ static struct perf_event
>> +*bm_counter_owner[2];
>
>SNIP
>
>> + * Find a hardware counter for the target task
>> + */
>> +for (i = 0; i < bm_num_counters; i++) {
>> +if ((bm_counter_owner[i] == NULL) ||
>> +(bm_counter_owner[i]->state ==
>PERF_EVENT_STATE_DEAD)) {
>> +counter_to_use = i;
>> +bm_counter_owner[i] = event;
>> +break;
>> +}
>> +}
>> +
>> +if (counter_to_use == -1)
>> +return -EBUSY;
>
>not sure I understand, your docs says: "There are 2 8-bit counters that each..
>"
>
>so there are 2 counters per CPU? if that's corrent, isn't this check too strict
>then? you could have more events configured running on other CPUs for
>another tasks
>
>given that we do task only events here, should bm_counter_owner be part
>of task, together with the limit..? I'm probably missing something..

Yes you are right. Initially, we had support for 2 events(from one or 2 tasks) 
to be monitored for the entire system. This indeed seems very limiting. In the 
next patchset, I will add support for 2 events per task (This is what the 
hardware can support).
>
>thanks,
>jirka


RE: [PATCH V0 2/3] perf/x86/intel/bm.c: Add Intel Branch Monitoring support

2017-11-10 Thread Dey, Megha


>-Original Message-
>From: Jiri Olsa [mailto:jo...@redhat.com]
>Sent: Saturday, November 4, 2017 6:25 AM
>To: Megha Dey 
>Cc: x...@kernel.org; linux-kernel@vger.kernel.org; linux-
>d...@vger.kernel.org; t...@linutronix.de; mi...@redhat.com;
>h...@zytor.com; andriy.shevche...@linux.intel.com;
>kstew...@linuxfoundation.org; Yu, Yu-cheng ;
>Brown, Len ; gre...@linuxfoundation.org;
>pet...@infradead.org; a...@kernel.org;
>alexander.shish...@linux.intel.com; namhy...@kernel.org;
>vikas.shiva...@linux.intel.com; pombreda...@nexb.com;
>m...@kylehuey.com; b...@suse.de; Andrejczuk, Grzegorz
>; Luck, Tony ;
>cor...@lwn.net; Shankar, Ravi V ; Dey, Megha
>
>Subject: Re: [PATCH V0 2/3] perf/x86/intel/bm.c: Add Intel Branch
>Monitoring support
>
>On Fri, Nov 03, 2017 at 11:00:05AM -0700, Megha Dey wrote:
>
>SNIP
>
>> +event->event_caps |= PERF_EV_CAP_BM;
>> +/*
>> + * cfg contains one of the 6 possible Branch Monitoring events
>> + */
>> +cfg = event->attr.config;
>> +if (cfg < 0 || cfg > (BM_MAX_EVENTS - 1))
>> +return -EINVAL;
>> +
>> +if (event->attr.sample_period) /* no sampling */
>> +return -EINVAL;
>
>you can use the 'is_sampling_event' function

Will make the change.
>
>jirka


RE: [PATCH V0 2/3] perf/x86/intel/bm.c: Add Intel Branch Monitoring support

2017-11-10 Thread Dey, Megha


>-Original Message-
>From: Jiri Olsa [mailto:jo...@redhat.com]
>Sent: Saturday, November 4, 2017 6:25 AM
>To: Megha Dey 
>Cc: x...@kernel.org; linux-kernel@vger.kernel.org; linux-
>d...@vger.kernel.org; t...@linutronix.de; mi...@redhat.com;
>h...@zytor.com; andriy.shevche...@linux.intel.com;
>kstew...@linuxfoundation.org; Yu, Yu-cheng ;
>Brown, Len ; gre...@linuxfoundation.org;
>pet...@infradead.org; a...@kernel.org;
>alexander.shish...@linux.intel.com; namhy...@kernel.org;
>vikas.shiva...@linux.intel.com; pombreda...@nexb.com;
>m...@kylehuey.com; b...@suse.de; Andrejczuk, Grzegorz
>; Luck, Tony ;
>cor...@lwn.net; Shankar, Ravi V ; Dey, Megha
>
>Subject: Re: [PATCH V0 2/3] perf/x86/intel/bm.c: Add Intel Branch
>Monitoring support
>
>On Fri, Nov 03, 2017 at 11:00:05AM -0700, Megha Dey wrote:
>
>SNIP
>
>> +
>> +static int intel_bm_event_nmi_handler(unsigned int cmd, struct
>> +pt_regs *regs) {
>> +struct perf_event *event;
>> +union bm_detect_status stat;
>> +struct perf_sample_data data;
>> +int i;
>> +unsigned long x;
>> +
>> +rdmsrl(BR_DETECT_STATUS_MSR, stat.raw);
>> +
>> +if (stat.event) {
>> +wrmsrl(BR_DETECT_STATUS_MSR, 0);
>> +apic_write(APIC_LVTPC, APIC_DM_NMI);
>> +/*
>> + * Issue wake-up to corrresponding polling event
>> + */
>> +x = stat.ctrl_hit;
>> +for_each_set_bit(i, &x, bm_num_counters) {
>> +event = bm_counter_owner[i];
>> +perf_sample_data_init(&data, 0, event-
>>hw.last_period);
>> +perf_event_overflow(event, &data, regs);
>
>hum, it's non sampling events only right? then you don't need any of the
>perf_sample_data stuff.. the perf_event_overflow call is basicaly nop

Yeah you are right. We were supporting sampling initially, forgot to get rid of 
this code.
Will change this in the next version.
>
>> +local64_inc(&event->count);
>> +atomic_set(&event->hw.bm_poll, POLLIN);
>> +event->pending_wakeup = 1;
>> +irq_work_queue(&event->pending);
>
>also this is for sampling events only
>
>seems like you only want to increment the event->count in here

We are currently working on a library similar to libperf which user space apps 
could make use of instead of perf command line monitoring. This code has been 
added so that the user can poll on when/if an interrupt is triggered and let 
the user know of its occurrence. If you think there is a better way of doing 
this, please let me know :)

>
>thanks,
>jirka
>
>> +}
>> +return NMI_HANDLED;
>> +}
>> +return NMI_DONE;
>> +}
>
>
>SNIP


Re: [PATCH v2 1/6] PM / core: Add LEAVE_SUSPENDED driver flag

2017-11-10 Thread Rafael J. Wysocki
On Sat, Nov 11, 2017 at 12:45 AM, Rafael J. Wysocki  wrote:
> On Fri, Nov 10, 2017 at 10:09 AM, Ulf Hansson  wrote:
>> On 8 November 2017 at 14:25, Rafael J. Wysocki  wrote:
>>> From: Rafael J. Wysocki 
>>>
>>> Define and document a new driver flag, DPM_FLAG_LEAVE_SUSPENDED, to
>>> instruct the PM core and middle-layer (bus type, PM domain, etc.)
>>> code that it is desirable to leave the device in runtime suspend
>>> after system-wide transitions to the working state (for example,
>>> the device may be slow to resume and it may be better to avoid
>>> resuming it right away).
>>>
>>> Generally, the middle-layer code involved in the handling of the
>>> device is expected to indicate to the PM core whether or not the
>>> device may be left in suspend with the help of the device's
>>> power.may_skip_resume status bit.  That has to happen in the "noirq"
>>> phase of the preceding system suspend (or analogous) transition.
>>> The middle layer is then responsible for handling the device as
>>> appropriate in its "noirq" resume callback which is executed
>>> regardless of whether or not the device may be left suspended, but
>>> the other resume callbacks (except for ->complete) will be skipped
>>> automatically by the core if the device really can be left in
>>> suspend.
>>
>> I don't understand the reason to why you need to skip invoking resume
>> callbacks to achieve this behavior, could you elaborate on that?
>
> The reason why it is done this way is because that takes less code and
> is easier (or at least less error-prone, because it avoids repeating
> patterns in middle layers).

Actually, it also is a matter of correctness, at least to some extent.

Namely, if the parent or any supplier of the device has
power.must_resume clear in dpm_noirq_resume_devices(), then the device
should not be touched during the whole system resume transition
(because the access may very well go through the suspended parent or
supplier) and the most straightforward way to make that happen is to
avoid running the code that may touch the device.  [Arguably, if
middle layers were made responsible for handling that, they would need
to do pretty much the same thing and so there is no reason for not
doing it in the core.]

Allowing the "noirq" callback from middle layers to run in that case
is a stretch already, but since genpd needs that, well, tough nuggets.

All of that said, if there is a middle layer wanting to set
power.skip_resume and needing to do something different for the resume
callbacks, then this piece can be moved from the core to the middle
layers at any time later.  So far there's none, though.  At least not
in this patch series.

Thanks,
Rafael


Re: [PATCH v4 0/4] fix the clock setting for SAR ADC

2017-11-10 Thread Jonathan Cameron
On Tue, 7 Nov 2017 22:36:00 +0100
Martin Blumenstingl  wrote:

> Hi Yixun,
> 
> On Tue, Nov 7, 2017 at 3:09 PM, Yixun Lan  wrote:
> > patch [1/4]:
> >   Fix wrong SARADC/SANA clock gate bit in Meson-GXBB/GXL,
> > the published datasheets[4] also has wrong description about this.
> >   This patch should be explicitly merged *before* other patches.
> >
> > patch [2-4/4]:
> >   Drop the "sana" clock from SAR ADC module,  
> I agree with Jerome that patch 2/4 should be applied last.

Let me know when I should take this.

Thanks,

Jonathan

> when I wrote the driver I couldn't get it to work on my GXBB board
> (which unfortunately has died since then) because the clocks were
> disabled (they weren't enabled by the bootloader). people who are
> using an old .dtb would get the same problem again until the clock
> driver is merged
> 
> >   From the hardware perspective, the SAR ADC module doesn't
> > require "sana" clock to wrok. This should apply to all SoC,
> > including meson6,8, GXBB, GXL..  
> thank you for clarifying this!
> 
> > Note: the whole patchset series has been tested at GXL-P212 board,
> > we haven't got any meson6,8 board to test, so I would appreciate
> > if someone (Martin?) could help to confirm it works there.  
> I can test this on a Meson8b and a Meson8m2 board on the weekend -
> I'll let you know about the results
> 
> 
> Regards
> Martin
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



Re: [f2fs-dev] [RFC PATHC 2/2] f2fs: apply write hints to select the type of segment for direct write

2017-11-10 Thread Chao Yu
On 2017/11/9 13:51, Hyunchul Lee wrote:
> From: Hyunchul Lee 
> 
> Select the type of the segment using write hints, when blocks are
> allocated for direct write.
> 
> There are unhandled corner cases. Hints are not applied in
> in-place update.  And if the blocks of a file is not pre-allocated
> because of the invalid user buffer, CURSEG_WARM_DATA segment will
> be selected.
> 
> Signed-off-by: Hyunchul Lee 
> ---
>  fs/f2fs/data.c | 101 
> ++---
>  fs/f2fs/f2fs.h |   1 +
>  2 files changed, 61 insertions(+), 41 deletions(-)
> 
> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> index 36b5352..d06048a 100644
> --- a/fs/f2fs/data.c
> +++ b/fs/f2fs/data.c
> @@ -783,7 +783,7 @@ struct page *get_new_data_page(struct inode *inode,
>   return page;
>  }
>  
> -static int __allocate_data_block(struct dnode_of_data *dn)
> +static int __allocate_data_block(struct dnode_of_data *dn, int seg_type)
>  {
>   struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode);
>   struct f2fs_summary sum;
> @@ -808,7 +808,7 @@ static int __allocate_data_block(struct dnode_of_data *dn)
>   set_summary(&sum, dn->nid, dn->ofs_in_node, ni.version);
>  
>   allocate_data_block(sbi, NULL, dn->data_blkaddr, &dn->data_blkaddr,
> - &sum, CURSEG_WARM_DATA, NULL, false);
> + &sum, seg_type, NULL, false);
>   set_data_blkaddr(dn);
>  
>   /* update i_size */
> @@ -827,42 +827,6 @@ static inline bool __force_buffered_io(struct inode 
> *inode, int rw)
>   F2FS_I_SB(inode)->s_ndevs);
>  }
>  
> -int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from)
> -{
> - struct inode *inode = file_inode(iocb->ki_filp);
> - struct f2fs_map_blocks map;
> - int err = 0;
> -
> - if (is_inode_flag_set(inode, FI_NO_PREALLOC))
> - return 0;
> -
> - map.m_lblk = F2FS_BLK_ALIGN(iocb->ki_pos);
> - map.m_len = F2FS_BYTES_TO_BLK(iocb->ki_pos + iov_iter_count(from));
> - if (map.m_len > map.m_lblk)
> - map.m_len -= map.m_lblk;
> - else
> - map.m_len = 0;
> -
> - map.m_next_pgofs = NULL;
> -
> - if (iocb->ki_flags & IOCB_DIRECT) {
> - err = f2fs_convert_inline_inode(inode);
> - if (err)
> - return err;
> - return f2fs_map_blocks(inode, &map, 1,
> - __force_buffered_io(inode, WRITE) ?
> - F2FS_GET_BLOCK_PRE_AIO :
> - F2FS_GET_BLOCK_PRE_DIO);
> - }
> - if (iocb->ki_pos + iov_iter_count(from) > MAX_INLINE_DATA(inode)) {
> - err = f2fs_convert_inline_inode(inode);
> - if (err)
> - return err;
> - }
> - if (!f2fs_has_inline_data(inode))
> - return f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_AIO);
> - return err;
> -}
>  
>  static inline void __do_map_lock(struct f2fs_sb_info *sbi, int flag, bool 
> lock)
>  {
> @@ -888,8 +852,8 @@ static inline void __do_map_lock(struct f2fs_sb_info 
> *sbi, int flag, bool lock)
>   * b. do not use extent cache for better performance
>   * c. give the block addresses to blockdev
>   */
> -int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
> - int create, int flag)
> +static int __f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks 
> *map,
> + int create, int flag, int seg_type)
>  {
>   unsigned int maxblocks = map->m_len;
>   struct dnode_of_data dn;
> @@ -957,7 +921,12 @@ int f2fs_map_blocks(struct inode *inode, struct 
> f2fs_map_blocks *map,
>   last_ofs_in_node = dn.ofs_in_node;
>   }
>   } else {
> - err = __allocate_data_block(&dn);
> + /* if this inode is marked with FI_NO_PREALLOC,
> +  * @seg_type is NO_CHECK_TYPE
> +  */
> + if (seg_type == NO_CHECK_TYPE)
> + seg_type = CURSEG_WARM_DATA;
> + err = __allocate_data_block(&dn, seg_type);

We need to use inode.i_write_hint instead of ki_hint passed from 
file.f_write_hint?

Thanks,

>   if (!err)
>   set_inode_flag(inode, FI_APPEND_WRITE);
>   }
> @@ -1048,6 +1017,51 @@ int f2fs_map_blocks(struct inode *inode, struct 
> f2fs_map_blocks *map,
>   return err;
>  }
>  
> +int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
> + int create, int flag)
> +{
> + return __f2fs_map_blocks(inode, map, create, flag, NO_CHECK_TYPE);
> +}
> +
> +int f2fs_preallocate_blocks(struct kiocb *iocb,

Re: [PATCH] iio: mma8452: add power_mode sysfs configuration

2017-11-10 Thread Jonathan Cameron
On Mon, 6 Nov 2017 08:19:58 +0100
Martin Kepplinger  wrote:

> This adds the power_mode sysfs interface to the device as documented in
> sysfs-bus-iio.
> 
> ---
> 
> Note that I explicitely don't sign off on this.
> 
> This is a starting point for anybody who can test it and check for correct
> API usage, and ABI correctness, as documented in 
> Documentation/ABI/testing/sys-bus-iio
> (grep it for "power_mode"). The ABI doc probably would need an addition
> too, if the 4 power modes here seem generally useful (there are only
>  2 listed there)!
> 
> So, if you can test this, feel free to set up a proper patch or
> two, and I'm happy to review.
> 
> Please note that this patch is quite old. It really should be that simple
> as far as my understanding back then. We always list the available frequencies
> of the given power mode we are in, for example, already, and everything
> basically is in place except for the user interface.

Hmm. A lot of devices support something along these lines.  The issue
has always been - how is userspace to figure out what to do with it?
It's all very vague...

Funnily enough - this used to be really common, but is becoming less so
now - presumably because no one was using it much (or maybe I am reading
too much into that ;)

Now the question is whether it can be tied to better defined things?

Here low noise restricts the range to 4g.  Issue is that we don't actually
have writeable _available attributes (which correspond to range in this case).

Low power mode... This one is apparently oversampling.  If possible support
it as that as we have well defined interfaces for that.

Jonathan.
> 
> thanks
> martin
> 
> 
> 
>  drivers/iio/accel/mma8452.c | 37 +
>  1 file changed, 37 insertions(+)
> 
> diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
> index bfd4bc806fc2..640bbd9872ab 100644
> --- a/drivers/iio/accel/mma8452.c
> +++ b/drivers/iio/accel/mma8452.c
> @@ -1166,6 +1166,41 @@ static struct attribute_group 
> mma8452_event_attribute_group = {
>   .attrs = mma8452_event_attributes,
>  };
>  
> +static const char * const mma8452_power_modes[] = {"normal",
> +"low_noise_low_power",
> +"low_noise",
> +"low_power"};
> +
> +static int mma8452_get_power_mode_iio_enum(struct iio_dev *indio_dev,
> +const struct iio_chan_spec *chan)
> +{
> + struct mma8452_data *data = iio_priv(indio_dev);
> +
> + return mma8452_get_power_mode(data);
> +}
> +
> +static int mma8452_set_power_mode_iio_enum(struct iio_dev *indio_dev,
> +const struct iio_chan_spec *chan,
> +unsigned int mode)
> +{
> + struct mma8452_data *data = iio_priv(indio_dev);
> +
> + return mma8452_set_power_mode(data, mode);
> +}
> +
> +static const struct iio_enum mma8452_power_mode_enum = {
> + .items = mma8452_power_modes,
> + .num_items = ARRAY_SIZE(mma8452_power_modes),
> + .get = mma8452_get_power_mode_iio_enum,
> + .set = mma8452_set_power_mode_iio_enum,
> +};
> +
> +static const struct iio_chan_spec_ext_info mma8452_ext_info[] = {
> + IIO_ENUM("power_mode", true, &mma8452_power_mode_enum),
> + IIO_ENUM_AVAILABLE("power_mode", &mma8452_power_mode_enum),
> + { },
> +};
> +
>  #define MMA8452_FREEFALL_CHANNEL(modifier) { \
>   .type = IIO_ACCEL, \
>   .modified = 1, \
> @@ -1204,6 +1239,7 @@ static struct attribute_group 
> mma8452_event_attribute_group = {
>   }, \
>   .event_spec = mma8452_transient_event, \
>   .num_event_specs = ARRAY_SIZE(mma8452_transient_event), \
> + .ext_info = mma8452_ext_info, \
>  }
>  
>  #define MMA8652_CHANNEL(axis, idx, bits) { \
> @@ -1225,6 +1261,7 @@ static struct attribute_group 
> mma8452_event_attribute_group = {
>   }, \
>   .event_spec = mma8452_motion_event, \
>   .num_event_specs = ARRAY_SIZE(mma8452_motion_event), \
> + .ext_info = mma8452_ext_info, \
>  }
>  
>  static const struct iio_chan_spec mma8451_channels[] = {



  1   2   3   4   5   6   7   >