Re: [PATCH V2 1/6] powerpc/powernv: don't enable SRIOV when VF BAR contains non M64 BAR

2015-08-07 Thread Alexey Kardashevskiy

On 08/07/2015 12:24 PM, Wei Yang wrote:

On Fri, Aug 07, 2015 at 11:20:10AM +1000, Gavin Shan wrote:

On Thu, Aug 06, 2015 at 10:10:10PM +0800, Wei Yang wrote:

On Thu, Aug 06, 2015 at 02:35:57PM +1000, Gavin Shan wrote:

On Wed, Aug 05, 2015 at 09:24:58AM +0800, Wei Yang wrote:

On PHB_IODA2, we enable SRIOV devices by mapping IOV BAR with M64 BARs. If
a SRIOV device's BAR is not 64-bit prefetchable, this is not assigned from
M64 windwo, which means M64 BAR can't work on it.



s/PHB_IODA2/PHB3
s/windwo/window


This patch makes this explicit.

Signed-off-by: Wei Yang 


The idea sounds right, but there is one question as below.


---
arch/powerpc/platforms/powernv/pci-ioda.c |   25 +
1 file changed, 9 insertions(+), 16 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c 
b/arch/powerpc/platforms/powernv/pci-ioda.c
index 5738d31..9b41dba 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -908,9 +908,6 @@ static int pnv_pci_vf_resource_shift(struct pci_dev *dev, 
int offset)
if (!res->flags || !res->parent)
continue;

-   if (!pnv_pci_is_mem_pref_64(res->flags))
-   continue;
-
/*
 * The actual IOV BAR range is determined by the start address
 * and the actual size for num_vfs VFs BAR.  This check is to
@@ -939,9 +936,6 @@ static int pnv_pci_vf_resource_shift(struct pci_dev *dev, 
int offset)
if (!res->flags || !res->parent)
continue;

-   if (!pnv_pci_is_mem_pref_64(res->flags))
-   continue;
-
size = pci_iov_resource_size(dev, i + PCI_IOV_RESOURCES);
res2 = *res;
res->start += size * offset;
@@ -1221,9 +1215,6 @@ static int pnv_pci_vf_assign_m64(struct pci_dev *pdev, 
u16 num_vfs)
if (!res->flags || !res->parent)
continue;

-   if (!pnv_pci_is_mem_pref_64(res->flags))
-   continue;
-
for (j = 0; j < vf_groups; j++) {
do {
win = 
find_next_zero_bit(&phb->ioda.m64_bar_alloc,
@@ -1510,6 +1501,12 @@ int pnv_pci_sriov_enable(struct pci_dev *pdev, u16 
num_vfs)
pdn = pci_get_pdn(pdev);

if (phb->type == PNV_PHB_IODA2) {
+   if (!pdn->vfs_expanded) {
+   dev_info(&pdev->dev, "don't support this SRIOV device"
+   " with non M64 VF BAR\n");
+   return -EBUSY;
+   }
+


It would be -ENOSPC since -EBUSY indicates the devices (VFs) are temparily
unavailable. For this case, the VFs are permanently unavailable because of
running out of space to accomodate M64 and non-M64 VF BARs.

The error message could be printed with dev_warn() and it would be precise
as below or something else you prefer:

dev_warn(&pdev->dev, "SRIOV not supported because of non-M64 VF BAR\n");



Thanks for the comment, will change accordingly.




/* Calculate available PE for required VFs */
mutex_lock(&phb->ioda.pe_alloc_mutex);
pdn->offset = bitmap_find_next_zero_area(
@@ -2774,9 +2771,10 @@ static void pnv_pci_ioda_fixup_iov_resources(struct 
pci_dev *pdev)
if (!res->flags || res->parent)
continue;
if (!pnv_pci_is_mem_pref_64(res->flags)) {
-   dev_warn(&pdev->dev, " non M64 VF BAR%d: %pR\n",
+   dev_warn(&pdev->dev, "Don't support SR-IOV with"
+   " non M64 VF BAR%d: %pR. \n",
 i, res);
-   continue;
+   return;
}

size = pci_iov_resource_size(pdev, i + PCI_IOV_RESOURCES);
@@ -2795,11 +2793,6 @@ static void pnv_pci_ioda_fixup_iov_resources(struct 
pci_dev *pdev)
res = &pdev->resource[i + PCI_IOV_RESOURCES];
if (!res->flags || res->parent)
continue;
-   if (!pnv_pci_is_mem_pref_64(res->flags)) {
-   dev_warn(&pdev->dev, "Skipping expanding VF BAR%d: 
%pR\n",
-i, res);
-   continue;
-   }


When any one IOV BAR on the PF is non-M64, none of the VFs can be enabled.
Will we still allocate/assign M64 or M32 resources for the IOV BARs? If so,
I think it can be avoided.



Don't get your point. You mean to avoid this function?

Or clear the IOV BAR when we found one of it is non-M64?



I mean to clear all IOV BARs in case any more of them are IO or M32. In this
case, the SRIOV capability won't be enabled. Otherwise, the resources for
all IOV BARs are assigned and allocated by PCI subsystem, but they won't
be used. Does it make sense 

[PATCH] powerpc/fsl_book3e: fix the relocatable bug in debug interrupt handler

2015-08-07 Thread Yuanjie Huang
PowerPC Book3E processor features hardware-supported single instruction
execution, and it is used for ptrace(PTRACE_SINGLESTEP, ...). When a debugger
loads a debuggee, it typically sets the CPU to yield debug interrupt on first
instruction complete or branch taken. However, the newly-forked child process
could run into instruction TLB miss exception handler when switched to, and
causes a debug interrupt in the exception entry sequence. This is not expected
by caller of ptrace(PTRACE_SINGLESTEP, ...), so the next instruction address
saved in DSRR0 is checked against the boundary of exception entry sequence, to
ensure the kernel only process the interrupt as a normal exception if the
address does not fall in the exception entry sequence.  Failure in obtaining
the correct boundary leads to such debug exception handled as from privileged
mode, and causes kernel oops.

The LOAD_REG_IMMEDIATE can't be used to load the boundary addresses when
relocatable enabled, so this patch replace them with LOAD_REG_ADDR_PIC. LR is
backed up and restored before and after calling LOAD_REG_ADDR_PIC, because
LOAD_REG_ADDR_PIC clobbers it.

Signed-off-by: Yuanjie Huang 
---
 arch/powerpc/kernel/exceptions-64e.S | 24 
 1 file changed, 24 insertions(+)

diff --git a/arch/powerpc/kernel/exceptions-64e.S 
b/arch/powerpc/kernel/exceptions-64e.S
index 3e68d1c..c475f569 100644
--- a/arch/powerpc/kernel/exceptions-64e.S
+++ b/arch/powerpc/kernel/exceptions-64e.S
@@ -735,12 +735,24 @@ END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
andis.  r15,r14,(DBSR_IC|DBSR_BT)@h
beq+1f
 
+#ifdef CONFIG_RELOCATABLE
+   mflrr14
+   LOAD_REG_ADDR_PIC(r15,interrupt_base_book3e)
+   mtlrr14
+   cmpld   cr0,r10,r15
+   blt+cr0,1f
+   LOAD_REG_ADDR_PIC(r15,interrupt_end_book3e)
+   mtlrr14
+   cmpld   cr0,r10,r15
+   bge+cr0,1f
+#else
LOAD_REG_IMMEDIATE(r14,interrupt_base_book3e)
LOAD_REG_IMMEDIATE(r15,interrupt_end_book3e)
cmpld   cr0,r10,r14
cmpld   cr1,r10,r15
blt+cr0,1f
bge+cr1,1f
+#endif
 
/* here it looks like we got an inappropriate debug exception. */
lis r14,(DBSR_IC|DBSR_BT)@h /* clear the event */
@@ -799,12 +811,24 @@ kernel_dbg_exc:
andis.  r15,r14,(DBSR_IC|DBSR_BT)@h
beq+1f
 
+#ifdef CONFIG_RELOCATABLE
+   mflrr14
+   LOAD_REG_ADDR_PIC(r15,interrupt_base_book3e)
+   mtlrr14
+   cmpld   cr0,r10,r15
+   blt+cr0,1f
+   LOAD_REG_ADDR_PIC(r15,interrupt_end_book3e)
+   mtlrr14
+   cmpld   cr0,r10,r15
+   bge+cr0,1f
+#else
LOAD_REG_IMMEDIATE(r14,interrupt_base_book3e)
LOAD_REG_IMMEDIATE(r15,interrupt_end_book3e)
cmpld   cr0,r10,r14
cmpld   cr1,r10,r15
blt+cr0,1f
bge+cr1,1f
+#endif
 
/* here it looks like we got an inappropriate debug exception. */
lis r14,(DBSR_IC|DBSR_BT)@h /* clear the event */
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 05/31] arch/powerpc/nvram: use kmemdup rather than duplicating its implementation

2015-08-07 Thread Andrzej Hajda
The patch was generated using fixed coccinelle semantic patch
scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

Signed-off-by: Andrzej Hajda 
---
 arch/powerpc/kernel/nvram_64.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/nvram_64.c b/arch/powerpc/kernel/nvram_64.c
index 1e703f8..6f6597b 100644
--- a/arch/powerpc/kernel/nvram_64.c
+++ b/arch/powerpc/kernel/nvram_64.c
@@ -541,10 +541,9 @@ static ssize_t nvram_pstore_read(u64 *id, enum 
pstore_type_id *type,
time->tv_sec = be64_to_cpu(oops_hdr->timestamp);
time->tv_nsec = 0;
}
-   *buf = kmalloc(length, GFP_KERNEL);
+   *buf = kmemdup(buff + hdr_size, length, GFP_KERNEL);
if (*buf == NULL)
return -ENOMEM;
-   memcpy(*buf, buff + hdr_size, length);
kfree(buff);
 
if (err_type == ERR_TYPE_KERNEL_PANIC_GZ)
-- 
1.9.1

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 06/31] arch/powerpc/pseries: use kmemdup rather than duplicating its implementation

2015-08-07 Thread Andrzej Hajda
The patch was generated using fixed coccinelle semantic patch
scripts/coccinelle/api/memdup.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2014320

Signed-off-by: Andrzej Hajda 
---
 arch/powerpc/platforms/pseries/hotplug-memory.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c 
b/arch/powerpc/platforms/pseries/hotplug-memory.c
index 0ced387..e9ff44c 100644
--- a/arch/powerpc/platforms/pseries/hotplug-memory.c
+++ b/arch/powerpc/platforms/pseries/hotplug-memory.c
@@ -92,13 +92,12 @@ static struct property *dlpar_clone_drconf_property(struct 
device_node *dn)
return NULL;
 
new_prop->name = kstrdup(prop->name, GFP_KERNEL);
-   new_prop->value = kmalloc(prop->length, GFP_KERNEL);
+   new_prop->value = kmemdup(prop->value, prop->length, GFP_KERNEL);
if (!new_prop->name || !new_prop->value) {
dlpar_free_drconf_property(new_prop);
return NULL;
}
 
-   memcpy(new_prop->value, prop->value, prop->length);
new_prop->length = prop->length;
 
/* Convert the property to cpu endian-ness */
-- 
1.9.1

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH V2 3/6] powerpc/powernv: use one M64 BAR in Single PE mode for one VF BAR

2015-08-07 Thread Alexey Kardashevskiy

On 08/07/2015 11:48 AM, Wei Yang wrote:

On Thu, Aug 06, 2015 at 08:07:01PM +1000, Gavin Shan wrote:

On Thu, Aug 06, 2015 at 05:36:02PM +0800, Wei Yang wrote:

On Thu, Aug 06, 2015 at 03:20:25PM +1000, Gavin Shan wrote:

On Wed, Aug 05, 2015 at 09:25:00AM +0800, Wei Yang wrote:

In current implementation, when VF BAR is bigger than 64MB, it uses 4 M64
BAR in Single PE mode to cover the number of VFs required to be enabled.
By doing so, several VFs would be in one VF Group and leads to interference
between VFs in the same group.

This patch changes the design by using one M64 BAR in Single PE mode for
one VF BAR. This gives absolute isolation for VFs.

Signed-off-by: Wei Yang 
---
arch/powerpc/include/asm/pci-bridge.h |5 +-
arch/powerpc/platforms/powernv/pci-ioda.c |  180 -
2 files changed, 76 insertions(+), 109 deletions(-)

diff --git a/arch/powerpc/include/asm/pci-bridge.h 
b/arch/powerpc/include/asm/pci-bridge.h
index 712add5..8aeba4c 100644
--- a/arch/powerpc/include/asm/pci-bridge.h
+++ b/arch/powerpc/include/asm/pci-bridge.h
@@ -214,10 +214,9 @@ struct pci_dn {
u16 vfs_expanded;   /* number of VFs IOV BAR expanded */
u16 num_vfs;/* number of VFs enabled*/
int offset; /* PE# for the first VF PE */
-#define M64_PER_IOV 4
-   int m64_per_iov;
+   boolm64_single_mode;/* Use M64 BAR in Single Mode */
#define IODA_INVALID_M64(-1)
-   int m64_wins[PCI_SRIOV_NUM_BARS][M64_PER_IOV];
+   int (*m64_map)[PCI_SRIOV_NUM_BARS];


It can be explicit? For example:

int *m64_map;

/* Initialization */
size_t size = sizeof(*pdn->m64_map) * PCI_SRIOV_NUM_BARS * 
num_of_max_VFs;
pdn->m64_map = kmalloc(size, GFP_KERNEL);
for (i = 0; i < PCI_SRIOV_NUM_BARS; i++)
for (j = 0; j < num_of_max_VFs; j++)
pdn->m64_map[i * PCI_SRIOV_NUM_BARS + j] = 
PNV_INVALID_M64;

/* Destroy */
int step = 1;

if (!pdn->m64_single_mode)
step = phb->ioda.total_pe;
for (i = 0; i < PCI_SRIOV_NUM_BARS * num_of_max_VFs; i += step)
if (pdn->m64_map[i] == PNV_INVALID_M64)
continue;

/* Unmap the window */



The m64_map is a pointer to an array with 6 elements, which represents the 6
M64 BAR index for the 6 VF BARs.

When we use Shared Mode, one array is allocated. The six elements
represents the six M64 BAR(at most) used to map the whole IOV BAR.

When we use Single Mode, num_vfs array is allocate. Each array represents
the map between one VF's BAR and M64 BAR index.

During the map and un-map, M64 BAR is assigned one by one in VF BAR's order.
So I think the code is explicit.

In your code, you allocate a big one dimension array to hold the M64 BAR
index. It works, while I don't think this is more explicit than original code.



When M64 is in Single Mode, array with (num_vfs * 6) entries is allocated
because every VF BAR (6 at most) will have one corresponding PHB M64 BAR.
Anything I missed?

The point in my code is you needn't worry about the mode (single vs shared)
As I said, not too much memory wasted. However, it's up to you.



If we don't want to save some memory, how about just define them static
instead of dynamically allocate?



I like static and you can make it uint8_t[][] (or char[][]) as these 
indexes are not going to be bigger than 255 anyway.





I'm not fan of "int (*m64_map)[PCI_SRIOV_NUM_BARS]". Instead, you can replace
it with "int *m64_map" and calculate its size using following formula:

sizeof(*pdn->m64_map) * PCI_SRIOV_NUM_BARS;

sizeof(*pdn->m64_map) * PCI_SRIOV_NUM_BARS * num_vfs;





--
Alexey
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

RE: [PATCH V2] QorIQ/TMU: add thermal management support based on TMU

2015-08-07 Thread Hongtao Jia
Thanks for your comments.
Please see my questions inline.

Thanks.
---
Best Regards,
Hongtao


> -Original Message-
> From: Eduardo Valentin [mailto:edubez...@gmail.com]
> Sent: Thursday, August 06, 2015 3:43 AM
> To: Jia Hongtao-B38951
> Cc: linux...@vger.kernel.org; linuxppc-dev@lists.ozlabs.org; Wood Scott-
> B07421
> Subject: Re: [PATCH V2] QorIQ/TMU: add thermal management support based
> on TMU
> 
> On Thu, Jul 30, 2015 at 08:13:09AM +, Hongtao Jia wrote:
> > - "Any specific reason why not using OF thermal?"
> > - No, actually.
> >
> > I'd like to use OF thermal after some clarification.
> >
> > Regarding to "cooling-maps". For some cases there should be more than
> > one cpus as cooling device and they are independent.
> > 1. Let's say 4. So we need to provide 4 maps like map0-map3. Right?
> 
> That would depend on the amount of sensors you have. Do you have one
> sensor per cpu? if the answer is yes, then you probably want to have four
> different map entries, yes, but one on each thermal zone of each cpu
> temperature sensor. if the answer is no, then you would need to have all
> the maps in the same thermal zone.
> 
> > 2. "cooling-max-level" may vary depend on switch settings or firmware.
> Is that
> >OK if I do not provide "cooling-min-level" and "cooling-max-level"
> property?
> 
> That is already achievable by using the cooling-device property of a
> cooling map.
> 
> Please have a look in the example section of the
> Documentation/devicetree/bindings/thermal/thermal.txt

Yes, I read this file.
So in my understanding:
There is no need to provide "cooling-min-level" and "cooling-max-level" 
property.
THERMAL_NO_LIMIT value in cooling device node will indicate the driver to
automatically parse the min and max state, right?

Talking about THERMAL_NO_LIMIT, I need to #include 

to provide the definition. But I got compiling error when build dtb file.
I did some research and using "make t1040qds.dtb" in order to involve 
preprocessor.
But with simply adding "#include " to 
t1040si-post.dtsi
at line 35 I still got error like this:
Error: arch/powerpc/boot/dts/fsl/t1040si-post.dtsi:35.1-9 syntax error
FATAL ERROR: Unable to parse input tree

Could you help me out here.
Thanks.

> 
> Let me know if you need further clarification.
> 
> 
> BR,
> 
> Eduardo Valentin
> 
> >
> > Thanks.
> > -Hongtao
> >
> >
> > > -Original Message-
> > > From: Eduardo Valentin [mailto:edubez...@gmail.com]
> > > Sent: Thursday, July 30, 2015 2:56 PM
> > > To: Jia Hongtao-B38951
> > > Cc: linux...@vger.kernel.org; linuxppc-dev@lists.ozlabs.org; Wood
> > > Scott-
> > > B07421
> > > Subject: Re: [PATCH V2] QorIQ/TMU: add thermal management support
> > > based on TMU
> > >
> > > On Wed, Jul 29, 2015 at 02:19:39PM +0800, Jia Hongtao wrote:
> > > > It supports one critical trip point and one passive trip point.
> > > > The cpufreq is used as the cooling device to throttle CPUs when
> > > > the passive trip is crossed.
> > > >
> > > > Signed-off-by: Jia Hongtao 
> > > > ---
> > > > This patch based on:
> > > > http://patchwork.ozlabs.org/patch/482987/
> > > >
> > > > Changes for V2:
> > > > * Add tmu-range parse.
> > > > * Use default trend hook.
> > > > * Using latest thermal_zone_bind_cooling_device API.
> > > > * Add calibration check during initialization.
> > > > * Disable/enalbe device when suspend/resume.
> > > >
> > > >  drivers/thermal/Kconfig |  11 ++
> > > >  drivers/thermal/Makefile|   1 +
> > > >  drivers/thermal/qoriq_thermal.c | 406
> > > > 
> > > >  3 files changed, 418 insertions(+)  create mode 100644
> > > > drivers/thermal/qoriq_thermal.c
> > > >
> > > > diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig
> > > > index
> > > > 118938e..a200745 100644
> > > > --- a/drivers/thermal/Kconfig
> > > > +++ b/drivers/thermal/Kconfig
> > > > @@ -180,6 +180,17 @@ config IMX_THERMAL
> > > >   cpufreq is used as the cooling device to throttle CPUs when
> the
> > > >   passive trip is crossed.
> > > >
> > > > +config QORIQ_THERMAL
> > > > +   tristate "Freescale QorIQ Thermal Monitoring Unit"
> > > > +   depends on CPU_THERMAL
> > > > +   depends on OF
> > > > +   default n
> > > > +   help
> > > > + Enable thermal management based on Freescale QorIQ Thermal
> > > Monitoring
> > > > + Unit (TMU). It supports one critical trip point and one
> > > > +passive
> > > trip
> > > > + point. The cpufreq is used as the cooling device to
> throttle
> > > > +CPUs
> > > when
> > > > + the passive trip is crossed.
> > > > +
> > > >  config SPEAR_THERMAL
> > > > bool "SPEAr thermal sensor driver"
> > > > depends on PLAT_SPEAR
> > > > diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile
> > > > index
> > > > 535dfee..8c25859 100644
> > > > --- a/drivers/thermal/Makefile
> > > > +++ b/drivers/thermal/Makefile
> > > > @@ -33,6 +33,7 @@ obj-$(CONFIG_DOVE_TH

Re: [PATCH V2 3/6] powerpc/powernv: use one M64 BAR in Single PE mode for one VF BAR

2015-08-07 Thread Alexey Kardashevskiy

On 08/07/2015 12:01 PM, Wei Yang wrote:

On Thu, Aug 06, 2015 at 08:04:58PM +1000, Alexey Kardashevskiy wrote:

On 08/05/2015 11:25 AM, Wei Yang wrote:

In current implementation, when VF BAR is bigger than 64MB, it uses 4 M64
BAR in Single PE mode to cover the number of VFs required to be enabled.
By doing so, several VFs would be in one VF Group and leads to interference
between VFs in the same group.

This patch changes the design by using one M64 BAR in Single PE mode for
one VF BAR. This gives absolute isolation for VFs.

Signed-off-by: Wei Yang 
---
  arch/powerpc/include/asm/pci-bridge.h |5 +-
  arch/powerpc/platforms/powernv/pci-ioda.c |  180 -
  2 files changed, 76 insertions(+), 109 deletions(-)

diff --git a/arch/powerpc/include/asm/pci-bridge.h 
b/arch/powerpc/include/asm/pci-bridge.h
index 712add5..8aeba4c 100644
--- a/arch/powerpc/include/asm/pci-bridge.h
+++ b/arch/powerpc/include/asm/pci-bridge.h
@@ -214,10 +214,9 @@ struct pci_dn {
u16 vfs_expanded;   /* number of VFs IOV BAR expanded */
u16 num_vfs;/* number of VFs enabled*/
int offset; /* PE# for the first VF PE */
-#define M64_PER_IOV 4
-   int m64_per_iov;
+   boolm64_single_mode;/* Use M64 BAR in Single Mode */
  #define IODA_INVALID_M64(-1)
-   int m64_wins[PCI_SRIOV_NUM_BARS][M64_PER_IOV];
+   int (*m64_map)[PCI_SRIOV_NUM_BARS];
  #endif /* CONFIG_PCI_IOV */
  #endif
struct list_head child_list;
diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c 
b/arch/powerpc/platforms/powernv/pci-ioda.c
index 7192e62..f5d110c 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -1148,29 +1148,36 @@ static void pnv_pci_ioda_setup_PEs(void)
  }

  #ifdef CONFIG_PCI_IOV
-static int pnv_pci_vf_release_m64(struct pci_dev *pdev)
+static int pnv_pci_vf_release_m64(struct pci_dev *pdev, u16 num_vfs)
  {
struct pci_bus*bus;
struct pci_controller *hose;
struct pnv_phb*phb;
struct pci_dn *pdn;
inti, j;
+   intm64_bars;

bus = pdev->bus;
hose = pci_bus_to_host(bus);
phb = hose->private_data;
pdn = pci_get_pdn(pdev);

+   if (pdn->m64_single_mode)
+   m64_bars = num_vfs;
+   else
+   m64_bars = 1;
+
for (i = 0; i < PCI_SRIOV_NUM_BARS; i++)
-   for (j = 0; j < M64_PER_IOV; j++) {
-   if (pdn->m64_wins[i][j] == IODA_INVALID_M64)
+   for (j = 0; j < m64_bars; j++) {
+   if (pdn->m64_map[j][i] == IODA_INVALID_M64)
continue;
opal_pci_phb_mmio_enable(phb->opal_id,
-   OPAL_M64_WINDOW_TYPE, pdn->m64_wins[i][j], 0);
-   clear_bit(pdn->m64_wins[i][j], 
&phb->ioda.m64_bar_alloc);
-   pdn->m64_wins[i][j] = IODA_INVALID_M64;
+   OPAL_M64_WINDOW_TYPE, pdn->m64_map[j][i], 0);
+   clear_bit(pdn->m64_map[j][i], &phb->ioda.m64_bar_alloc);
+   pdn->m64_map[j][i] = IODA_INVALID_M64;
}

+   kfree(pdn->m64_map);
return 0;
  }

@@ -1187,8 +1194,7 @@ static int pnv_pci_vf_assign_m64(struct pci_dev *pdev, 
u16 num_vfs)
inttotal_vfs;
resource_size_tsize, start;
intpe_num;
-   intvf_groups;
-   intvf_per_group;
+   intm64_bars;

bus = pdev->bus;
hose = pci_bus_to_host(bus);
@@ -1196,26 +1202,26 @@ static int pnv_pci_vf_assign_m64(struct pci_dev *pdev, 
u16 num_vfs)
pdn = pci_get_pdn(pdev);
total_vfs = pci_sriov_get_totalvfs(pdev);

-   /* Initialize the m64_wins to IODA_INVALID_M64 */
-   for (i = 0; i < PCI_SRIOV_NUM_BARS; i++)
-   for (j = 0; j < M64_PER_IOV; j++)
-   pdn->m64_wins[i][j] = IODA_INVALID_M64;
+   if (pdn->m64_single_mode)



This is a physical function's @pdn, right?


Yes





+   m64_bars = num_vfs;
+   else
+   m64_bars = 1;
+
+   pdn->m64_map = kmalloc(sizeof(*pdn->m64_map) * m64_bars, GFP_KERNEL);



Assume we have SRIOV device with 16VF.
So it was m64_wins[6][4], now it is (roughly speaking) m64_map[6][16]
(for a single PE mode) or m64_map[6][1]. I believe m64_bars cannot be
bigger than 16 on PHB3, right? Is this checked anywhere (does it have
to)?


In pnv_pci_vf_assign_m64(), we need to find_next_zero_bit() and check the
return value. If exceed m64_bar_idx, means fail.



This m64_wins -> m64_map change - is was not a map (what was it?),
and it is, is not it?


Hmm... Gavin like this name.



What does it store? An index of M64 BAR (0..

Re: [PATCH V2 4/6] powerpc/powernv: replace the hard coded boundary with gate

2015-08-07 Thread Alexey Kardashevskiy

On 08/06/2015 03:26 PM, Gavin Shan wrote:

On Wed, Aug 05, 2015 at 09:25:01AM +0800, Wei Yang wrote:

Based on the limitation of M64 Window size, when VF BAR size is bigger than
64MB, IOV BAR just round up power of 2 of the total_vfs. While the 64MB is
a magic boundary in code, which is hard to maintain.

This patch replaces the hard coded boundary with gate, which is calculated
from m64_segsize and adds comment to explain the reason for it.

Signed-off-by: Wei Yang 
---
arch/powerpc/platforms/powernv/pci-ioda.c |   22 +-
1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c 
b/arch/powerpc/platforms/powernv/pci-ioda.c
index f5d110c..31dcedc 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -2702,7 +2702,7 @@ static void pnv_pci_ioda_fixup_iov_resources(struct 
pci_dev *pdev)
struct pnv_phb *phb;
struct resource *res;
int i;
-   resource_size_t size;
+   resource_size_t size, gate;
struct pci_dn *pdn;
int mul, total_vfs;

@@ -2718,6 +2718,17 @@ static void pnv_pci_ioda_fixup_iov_resources(struct 
pci_dev *pdev)

total_vfs = pci_sriov_get_totalvfs(pdev);
mul = phb->ioda.total_pe;
+   /*
+* If bigger than or equal to half of m64_segsize, just round up power
+* of two.
+*
+* Generally, one M64 BAR maps one IOV BAR. To avoid conflict with
+* other devices, IOV BAR size is expanded to be (total_pe * VF size).
+* When VF size is half of m64_segsize , the expanded size would equal
+* to half of the whole M64 Window size, which will exhaust the M64
+* Window and limit the system flexibility.
+*/


s/VF size/VF BAR size
s/m64_segsize/M64 segment size
s/M64 Window/M64 space


I thought I started understanding the stuff and you just introduces new 
term - "M64 space". Not "64bit MMIO space" but "M64 space" - what is this? 
Is that 64GB 64bit MMIO window which we get from the hostboot?






+   gate = phb->ioda.m64_segsize >> 1;

for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
res = &pdev->resource[i + PCI_IOV_RESOURCES];
@@ -2732,10 +2743,11 @@ static void pnv_pci_ioda_fixup_iov_resources(struct 
pci_dev *pdev)

size = pci_iov_resource_size(pdev, i + PCI_IOV_RESOURCES);

-   /* bigger than 64M */
-   if (size > (1 << 26)) {
-   dev_info(&pdev->dev, "PowerNV: VF BAR%d: %pR IOV size is 
bigger than 64M, roundup power2\n",
-i, res);
+   /* bigger than or equal to gate */
+   if (size >= gate) {
+   dev_info(&pdev->dev, "PowerNV: VF BAR%d: %pR IOV size "
+   "is bigger than %lld, roundup power2\n",
+i, res, gate);


If I understand the changes correctly, single VF BAR size is still checked 
against
the "gate" (128MB), not the total VF BAR size. Recap the comments I gave last 
time:

I mean to check the sum of all VF BARs. For example, the VFs attached to its PF 
has two
VF BARs and each of them is 64MB. For this case, the MMIO resource can't be 
allocated
once extending them to 256 VFs. So we have to try "single-pe-mode" for this 
situation.
So the check becomes as below:

 struct pci_controller *hose = pci_bus_to_host(pdev->bus);
 struct pnv_phb *phb = hose->private_data;
 resource_size_t total_vf_bar_sz = 0;
 resource_size_t gate;

 /* Some comments to explain the "gate" */
 gate = phb->m64_segsize / 2;
 for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
 total_vf_bar_sz += pci_iov_resource_size(pdev, 
PCI_IOV_RESOURCES + i);

 if (total_vf_bar_sz >= gate)



Why would be compare to the total size of the BARs? If VFs have 3 64MB BARs 
each (these are 64bit BARs so up to 3 per VF, right?), which is 192MB in 
total per VF, we can use 3 M64's, each in segmented mode (1 segment == 
64MB) and cover many VFs.





 /* single-pe-mode */
 else
 /* shared-mode */


mul = roundup_pow_of_two(total_vfs);
pdn->m64_single_mode = true;
break;
--
1.7.9.5






--
Alexey
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH V2 6/6] powerpc/powernv: allocate discrete PE# when using M64 BAR in Single PE mode

2015-08-07 Thread Alexey Kardashevskiy

On 08/07/2015 03:54 PM, Gavin Shan wrote:

On Fri, Aug 07, 2015 at 01:44:33PM +0800, Wei Yang wrote:

On Fri, Aug 07, 2015 at 01:43:01PM +1000, Gavin Shan wrote:

On Fri, Aug 07, 2015 at 10:33:33AM +0800, Wei Yang wrote:

On Fri, Aug 07, 2015 at 11:36:56AM +1000, Gavin Shan wrote:

On Thu, Aug 06, 2015 at 09:41:41PM +0800, Wei Yang wrote:

On Thu, Aug 06, 2015 at 03:36:01PM +1000, Gavin Shan wrote:

On Wed, Aug 05, 2015 at 09:25:03AM +0800, Wei Yang wrote:

When M64 BAR is set to Single PE mode, the PE# assigned to VF could be
discrete.


s/discrete/sparse/ may be?




This patch restructures the patch to allocate discrete PE# for VFs when M64
BAR is set to Single PE mode.

Signed-off-by: Wei Yang 
---
arch/powerpc/include/asm/pci-bridge.h |2 +-
arch/powerpc/platforms/powernv/pci-ioda.c |   69 +
2 files changed, 51 insertions(+), 20 deletions(-)

diff --git a/arch/powerpc/include/asm/pci-bridge.h 
b/arch/powerpc/include/asm/pci-bridge.h
index 8aeba4c..72415c7 100644
--- a/arch/powerpc/include/asm/pci-bridge.h
+++ b/arch/powerpc/include/asm/pci-bridge.h
@@ -213,7 +213,7 @@ struct pci_dn {
#ifdef CONFIG_PCI_IOV
u16 vfs_expanded;   /* number of VFs IOV BAR expanded */
u16 num_vfs;/* number of VFs enabled*/
-   int offset; /* PE# for the first VF PE */
+   int *offset;/* PE# for the first VF PE or array */
boolm64_single_mode;/* Use M64 BAR in Single Mode */
#define IODA_INVALID_M64(-1)
int (*m64_map)[PCI_SRIOV_NUM_BARS];


how about renaming "offset" to "pe_num_map", or "pe_map" ? Similar to the 
comments
I gave to the "m64_bar_map", num_of_max_vfs entries can be allocated. Though not
all of them will be used, not too much memory will be wasted.



Thanks for your comment.

I have thought about change the name to make it more self explain. While
another fact I want to take in is this field is also used to be reflect the
shift offset when M64 BAR is used in the Shared Mode. So I maintain the name.

How about use "enum", one maintain the name "offset", and another one rename to
"pe_num_map". And use the meaningful name at proper place?



So I suppose you agree with my naming proposal.



No, I dislike the "enum" things.



OK, then you suggest to rename it pe_num_map or keep it as offset?



pe_num_map would be better.



+1. @offset is very confusing.

It could be a linked list actually, "struct list_head pe_list" in pci_dn 
and "struct list_head next" in struct pnv_ioda_pe.  I could not quickly 
spot places where you would access this array outside a loop 
for(i=0;i



--
Alexey
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH] kvm:powerpc:Fix error handling in the function mpic_set_default_irq_routing

2015-08-07 Thread Paolo Bonzini


On 06/08/2015 19:13, Nicholas Krause wrote:
> diff --git a/arch/powerpc/kvm/mpic.c b/arch/powerpc/kvm/mpic.c
> index 6249cdc..5a18859 100644
> --- a/arch/powerpc/kvm/mpic.c
> +++ b/arch/powerpc/kvm/mpic.c
> @@ -1641,13 +1641,16 @@ static void mpic_destroy(struct kvm_device *dev)
>  static int mpic_set_default_irq_routing(struct openpic *opp)
>  {
>   struct kvm_irq_routing_entry *routing;
> + int ret;
>  
>   /* Create a nop default map, so that dereferencing it still works */
>   routing = kzalloc((sizeof(*routing)), GFP_KERNEL);
>   if (!routing)
>   return -ENOMEM;
>  
> - kvm_set_irq_routing(opp->kvm, routing, 0, 0);
> + ret = kvm_set_irq_routing(opp->kvm, routing, 0, 0);
> + if (ret)
> + return ret;
>  
>   kfree(routing);
>   return 0;

The patch leaks the "routing" variable if you hit the error path.

Paolo
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

4.1-rc6: ATA link is slow to respond, please be patient

2015-08-07 Thread Christian Kujau
Hi,

this PowerBook G4 was running 3.16 for a while but now I wanted to upgrade 
to latest mainline. However, during bootup the following happens:

===
[2.237102] ata1: PATA max UDMA/100 irq 39
[2.401708] ata1.00: ATA-8: SAMSUNG HM061GC, LR100-10, max UDMA/100
[2.401764] ata1.00: 117231408 sectors, multi 16: LBA48 
[2.417633] ata1.00: configured for UDMA/100
[   44.918102] ata1.00: exception Emask 0x0 SAct 0x0 SErr 0x0 action 0x0
[   44.920452] ata1.00: failed command: READ DMA
[   44.922725] ata1.00: cmd c8/00:88:64:c2:12/00:00:00:00:00/e0 tag 0 dma 69632 
in
[   44.927257] ata1.00: status: { DRDY }
[   49.971784] ata1.00: qc timeout (cmd 0xec)
[   49.976529] ata1.00: failed to IDENTIFY (I/O error, err_mask=0x4)
[   49.978908] ata1.00: revalidation failed (errno=-5)
[   55.019662] ata1: link is slow to respond, please be patient (ready=0)
[   60.007677] ata1: device not ready (errno=-16), forcing hardreset
[   60.012670] ata1: soft resetting link
[   60.193638] ata1.00: configured for UDMA/100
[   60.196158] ata1.00: device reported invalid CHS sector 0
[   60.198610] ata1: EH complete
===

This happens only once, but systemd thinks there's a hard problem and will 
drop to a recovery shell. I can start sshd and login remotely and then the 
system appears to be running just fine.

This happened in 4.2.0-rc5 so I went back a few versions and found that
4.1-rc5 was OK (the error does not show up and the system boots just fine)
and 4.1-rc6 is not.

Unfortunately a git-bisect between these two versions went completly off 
the charts, I don't know what happened here:

==
first bad commit:

0fa372b6c95013af1334b3d5c9b5f03a70ecedab is the first bad commit
commit 0fa372b6c95013af1334b3d5c9b5f03a70ecedab
Author: Takashi Iwai 
Date:   Wed May 27 16:17:19 2015 +0200

ALSA: hda - Fix noise on AMD radeon 290x controller
==

I don't have this driver (or ALSA) even selected. I can reproduce this 
error pretty reliably and I'd like to attempt another git-bisect
run when I'm more awake. But maybe somebody recognizes this error and
has a hint where this could come from?

dmesg & .config:  http://nerdbynature.de/bits/v4.1-rc6/

Thanks,
Christian.
-- 
BOFH excuse #225:

It's those computer people in X {city of world}.  They keep stuffing things up.
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH V6 4/6] mm: mlock: Add mlock flags to enable VM_LOCKONFAULT usage

2015-08-07 Thread Vlastimil Babka

On 07/29/2015 05:42 PM, Eric B Munson wrote:

The previous patch introduced a flag that specified pages in a VMA
should be placed on the unevictable LRU, but they should not be made
present when the area is created.  This patch adds the ability to set
this state via the new mlock system calls.

We add MLOCK_ONFAULT for mlock2 and MCL_ONFAULT for mlockall.
MLOCK_ONFAULT will set the VM_LOCKONFAULT modifier for VM_LOCKED.
MCL_ONFAULT should be used as a modifier to the two other mlockall
flags.  When used with MCL_CURRENT, all current mappings will be marked
with VM_LOCKED | VM_LOCKONFAULT.  When used with MCL_FUTURE, the
mm->def_flags will be marked with VM_LOCKED | VM_LOCKONFAULT.  When used
with both MCL_CURRENT and MCL_FUTURE, all current mappings and
mm->def_flags will be marked with VM_LOCKED | VM_LOCKONFAULT.

Prior to this patch, mlockall() will unconditionally clear the
mm->def_flags any time it is called without MCL_FUTURE.  This behavior
is maintained after adding MCL_ONFAULT.  If a call to
mlockall(MCL_FUTURE) is followed by mlockall(MCL_CURRENT), the
mm->def_flags will be cleared and new VMAs will be unlocked.  This
remains true with or without MCL_ONFAULT in either mlockall()
invocation.

munlock() will unconditionally clear both vma flags.  munlockall()
unconditionally clears for VMA flags on all VMAs and in the
mm->def_flags field.

Signed-off-by: Eric B Munson 
Cc: Michal Hocko 
Cc: Vlastimil Babka 


The logic seems ok, although the fact that apply_mlockall_flags() is 
shared by both mlockall and munlockall makes it even more subtle than 
before :)


Anyway, just some nitpicks below.

Acked-by: Vlastimil Babka 

[...]


+/*
+ * Take the MCL_* flags passed into mlockall (or 0 if called from munlockall)
+ * and translate into the appropriate modifications to mm->def_flags and/or the
+ * flags for all current VMAs.
+ *
+ * There are a couple of sublties with this.  If mlockall() is called multiple


^ typo


+ * times with different flags, the values do not necessarily stack.  If 
mlockall
+ * is called once including the MCL_FUTURE flag and then a second time without
+ * it, VM_LOCKED and VM_LOCKONFAULT will be cleared from mm->def_flags.
+ */
  static int apply_mlockall_flags(int flags)
  {
struct vm_area_struct * vma, * prev = NULL;
+   vm_flags_t to_add = 0;

-   if (flags & MCL_FUTURE)
+   current->mm->def_flags &= ~(VM_LOCKED | VM_LOCKONFAULT);
+   if (flags & MCL_FUTURE) {
current->mm->def_flags |= VM_LOCKED;
-   else
-   current->mm->def_flags &= ~VM_LOCKED;

-   if (flags == MCL_FUTURE)
-   goto out;
+   if (flags & MCL_ONFAULT)
+   current->mm->def_flags |= VM_LOCKONFAULT;
+
+   /*
+* When there were only two flags, we used to early out if only
+* MCL_FUTURE was set.  Now that we have MCL_ONFAULT, we can
+* only early out if MCL_FUTURE is set, but MCL_CURRENT is not.


Describing the relation to history of individual code lines in such 
detail is noise imho. The stacking subtleties is already described above.



+* This is done, even though it promotes odd behavior, to
+* maintain behavior from older kernels
+*/
+   if (!(flags & MCL_CURRENT))
+   goto out;

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: 4.1-rc6: ATA link is slow to respond, please be patient

2015-08-07 Thread Denis Kirjanov
On 8/7/15, Christian Kujau  wrote:
> Hi,
>
> this PowerBook G4 was running 3.16 for a while but now I wanted to upgrade
> to latest mainline. However, during bootup the following happens:
>
> ===
> [2.237102] ata1: PATA max UDMA/100 irq 39
> [2.401708] ata1.00: ATA-8: SAMSUNG HM061GC, LR100-10, max UDMA/100
> [2.401764] ata1.00: 117231408 sectors, multi 16: LBA48
> [2.417633] ata1.00: configured for UDMA/100
> [   44.918102] ata1.00: exception Emask 0x0 SAct 0x0 SErr 0x0 action 0x0
> [   44.920452] ata1.00: failed command: READ DMA
> [   44.922725] ata1.00: cmd c8/00:88:64:c2:12/00:00:00:00:00/e0 tag 0 dma
> 69632 in
> [   44.927257] ata1.00: status: { DRDY }
> [   49.971784] ata1.00: qc timeout (cmd 0xec)
> [   49.976529] ata1.00: failed to IDENTIFY (I/O error, err_mask=0x4)
> [   49.978908] ata1.00: revalidation failed (errno=-5)
> [   55.019662] ata1: link is slow to respond, please be patient (ready=0)
> [   60.007677] ata1: device not ready (errno=-16), forcing hardreset
> [   60.012670] ata1: soft resetting link
> [   60.193638] ata1.00: configured for UDMA/100
> [   60.196158] ata1.00: device reported invalid CHS sector 0
> [   60.198610] ata1: EH complete
> ===

Interesting, I'll try to reproduce it on my G4.

>
> This happens only once, but systemd thinks there's a hard problem and will
> drop to a recovery shell. I can start sshd and login remotely and then the
> system appears to be running just fine.
>
> This happened in 4.2.0-rc5 so I went back a few versions and found that
> 4.1-rc5 was OK (the error does not show up and the system boots just fine)
> and 4.1-rc6 is not.
>
> Unfortunately a git-bisect between these two versions went completly off
> the charts, I don't know what happened here:
>
> ==
> first bad commit:
>
> 0fa372b6c95013af1334b3d5c9b5f03a70ecedab is the first bad commit
> commit 0fa372b6c95013af1334b3d5c9b5f03a70ecedab
> Author: Takashi Iwai 
> Date:   Wed May 27 16:17:19 2015 +0200
>
> ALSA: hda - Fix noise on AMD radeon 290x controller
> ==
>
> I don't have this driver (or ALSA) even selected. I can reproduce this
> error pretty reliably and I'd like to attempt another git-bisect
> run when I'm more awake. But maybe somebody recognizes this error and
> has a hint where this could come from?
>
> dmesg & .config:  http://nerdbynature.de/bits/v4.1-rc6/
>
> Thanks,
> Christian.
> --
> BOFH excuse #225:
>
> It's those computer people in X {city of world}.  They keep stuffing things
> up.
> ___
> Linuxppc-dev mailing list
> Linuxppc-dev@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/linuxppc-dev
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH] kvm:powerpc:Fix error handling in the function mpic_set_default_irq_routing

2015-08-07 Thread Nicholas Krause
This fixes error handling in the function mpic_set_default_irq_routing
by checking if the call to the function kvm_set_irq_routing has failed
and if so exit immediately to the caller by first freeing the structure
pointer routing in order to avoid a memory leak before returning the error
code returned by the call to mpic_set_default_irq_routing.

Signed-off-by: Nicholas Krause 
---
 arch/powerpc/kvm/mpic.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kvm/mpic.c b/arch/powerpc/kvm/mpic.c
index 6249cdc..7b1375a 100644
--- a/arch/powerpc/kvm/mpic.c
+++ b/arch/powerpc/kvm/mpic.c
@@ -1641,13 +1641,18 @@ static void mpic_destroy(struct kvm_device *dev)
 static int mpic_set_default_irq_routing(struct openpic *opp)
 {
struct kvm_irq_routing_entry *routing;
+   int ret;
 
/* Create a nop default map, so that dereferencing it still works */
routing = kzalloc((sizeof(*routing)), GFP_KERNEL);
if (!routing)
return -ENOMEM;
 
-   kvm_set_irq_routing(opp->kvm, routing, 0, 0);
+   ret = kvm_set_irq_routing(opp->kvm, routing, 0, 0);
+   if (ret) {
+   kfree(routing);
+   return ret;
+   }
 
kfree(routing);
return 0;
-- 
2.1.4

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH] kvm:powerpc:Fix error handling in the function mpic_set_default_irq_routing

2015-08-07 Thread Paolo Bonzini


On 07/08/2015 15:47, Nicholas Krause wrote:
> - kvm_set_irq_routing(opp->kvm, routing, 0, 0);
> + ret = kvm_set_irq_routing(opp->kvm, routing, 0, 0);
> + if (ret) {
> + kfree(routing);
> + return ret;
> + }
>  
>   kfree(routing);
>   return 0;

You could just return ret here.  The new "if" is not necessary.

Paolo
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH] kvm:powerpc:Fix error handling in the function mpic_set_default_irq_routing

2015-08-07 Thread nick


On 2015-08-07 09:59 AM, Paolo Bonzini wrote:
> 
> 
> On 07/08/2015 15:47, Nicholas Krause wrote:
>> -kvm_set_irq_routing(opp->kvm, routing, 0, 0);
>> +ret = kvm_set_irq_routing(opp->kvm, routing, 0, 0);
>> +if (ret) {
>> +kfree(routing);
>> +return ret;
>> +}
>>  
>>  kfree(routing);
>>  return 0;
> 
> You could just return ret here.  The new "if" is not necessary.
> 
> Paolo
> 

Ok sure that seems fine to be and much simpler then this.
Sorry about the wasting your time with this patch.
Nick 
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH] kvm:powerpc:Fix incorrect return statement in the function mpic_set_default_irq_routing

2015-08-07 Thread Nicholas Krause
This fixes the incorrect return statement in the function
mpic_set_default_irq_routing from always returning zero
to signal success to this function's caller to instead
return the return value of kvm_set_irq_routing as this
function can fail and we need to correctly signal the
caller of mpic_set_default_irq_routing when the call
to this particular function has failed.

Signed-off-by: Nicholas Krause 
---
 arch/powerpc/kvm/mpic.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kvm/mpic.c b/arch/powerpc/kvm/mpic.c
index 6249cdc..b14b85a 100644
--- a/arch/powerpc/kvm/mpic.c
+++ b/arch/powerpc/kvm/mpic.c
@@ -1641,16 +1641,17 @@ static void mpic_destroy(struct kvm_device *dev)
 static int mpic_set_default_irq_routing(struct openpic *opp)
 {
struct kvm_irq_routing_entry *routing;
+   int ret;
 
/* Create a nop default map, so that dereferencing it still works */
routing = kzalloc((sizeof(*routing)), GFP_KERNEL);
if (!routing)
return -ENOMEM;
 
-   kvm_set_irq_routing(opp->kvm, routing, 0, 0);
+   ret = kvm_set_irq_routing(opp->kvm, routing, 0, 0);
 
kfree(routing);
-   return 0;
+   return ret;
 }
 
 static int mpic_create(struct kvm_device *dev, u32 type)
-- 
2.1.4

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH 0/8] misc: remove boundary checks from bin attr users

2015-08-07 Thread Vladimir Zapolskiy
Hi Wolfram,

On 07.08.2015 19:10, Wolfram Sang wrote:
> Vladimir,
> 
> On Mon, Jul 27, 2015 at 12:18:22AM +0300, Vladimir Zapolskiy wrote:
>> This change removes a number of redundant checks on bin attribute
>> client's side, the same checks are done by sysfs_kf_bin_read() or
>> sysfs_kf_bin_write() caller from fs/sysfs/file.c.
>>
>> Note, drivers/misc/pch_phub.c and drivers/misc/c2port/core.c may be
>> updated in a similar way, however this task is not done due to more
>> complicated read()/write() callbacks.
> 
> Can you resend the patches which touch i2c drivers with me on cc? I'd
> like to take care of them.

if we're talking about this particular series, you should have them in
your mailbox, since you have them applied in wsa/i2c/for-next:

commit d12c0aaf3780c5b26b4ea9e795252381f586c063
Author: Vladimir Zapolskiy 
Date:   Mon Jul 27 00:18:51 2015 +0300

misc: eeprom: at24: clean up at24_bin_write()

The change removes redundant sysfs binary file boundary check, since
this task is already done on caller side in fs/sysfs/file.c

Signed-off-by: Vladimir Zapolskiy 
Signed-off-by: Wolfram Sang 

commit 1f023297f7f77d434ecc221018d2e181eac0ae36
Author: Vladimir Zapolskiy 
Date:   Mon Jul 27 00:16:31 2015 +0300

i2c: slave eeprom: clean up sysfs bin attribute read()/write()

The change removes redundant sysfs binary file boundary checks,
since this task is already done on caller side in fs/sysfs/file.c

Note, on file size overflow read() now returns 0, and this is a
correct and expected EOF notification according to POSIX.

Signed-off-by: Vladimir Zapolskiy 
Signed-off-by: Wolfram Sang 


Do you want me to send them to you again anyway?

--
With best wishes,
Vladimir
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH 0/8] misc: remove boundary checks from bin attr users

2015-08-07 Thread Wolfram Sang
Vladimir,

On Mon, Jul 27, 2015 at 12:18:22AM +0300, Vladimir Zapolskiy wrote:
> This change removes a number of redundant checks on bin attribute
> client's side, the same checks are done by sysfs_kf_bin_read() or
> sysfs_kf_bin_write() caller from fs/sysfs/file.c.
> 
> Note, drivers/misc/pch_phub.c and drivers/misc/c2port/core.c may be
> updated in a similar way, however this task is not done due to more
> complicated read()/write() callbacks.

Can you resend the patches which touch i2c drivers with me on cc? I'd
like to take care of them.

Thanks,

   Wolfram



signature.asc
Description: Digital signature
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH v3 7/9] hvc/xen: Further s/MFN/GFN clean-up

2015-08-07 Thread Julien Grall
HVM_PARAM_CONSOLE_PFN is used to retrieved the console PFN for HVM
guest. It returns a PFN (aka GFN) and not a MFN.

Furthermore, use directly virt_to_gfn for both PV and HVM domain rather
than doing a special case for each of the them.

Signed-off-by: Julien Grall 
Reviewed-by: David Vrabel 

---
Cc: Greg Kroah-Hartman 
Cc: Jiri Slaby 
Cc: linuxppc-dev@lists.ozlabs.org

Changes in v2:
- Add David's reviewed-by
---
 drivers/tty/hvc/hvc_xen.c | 15 +--
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/drivers/tty/hvc/hvc_xen.c b/drivers/tty/hvc/hvc_xen.c
index efe5124..10beb15 100644
--- a/drivers/tty/hvc/hvc_xen.c
+++ b/drivers/tty/hvc/hvc_xen.c
@@ -200,7 +200,7 @@ static int xen_hvm_console_init(void)
 {
int r;
uint64_t v = 0;
-   unsigned long mfn;
+   unsigned long gfn;
struct xencons_info *info;
 
if (!xen_hvm_domain())
@@ -217,7 +217,7 @@ static int xen_hvm_console_init(void)
}
/*
 * If the toolstack (or the hypervisor) hasn't set these values, the
-* default value is 0. Even though mfn = 0 and evtchn = 0 are
+* default value is 0. Even though gfn = 0 and evtchn = 0 are
 * theoretically correct values, in practice they never are and they
 * mean that a legacy toolstack hasn't initialized the pv console 
correctly.
 */
@@ -229,8 +229,8 @@ static int xen_hvm_console_init(void)
r = hvm_get_parameter(HVM_PARAM_CONSOLE_PFN, &v);
if (r < 0 || v == 0)
goto err;
-   mfn = v;
-   info->intf = xen_remap(mfn << PAGE_SHIFT, PAGE_SIZE);
+   gfn = v;
+   info->intf = xen_remap(gfn << PAGE_SHIFT, PAGE_SIZE);
if (info->intf == NULL)
goto err;
info->vtermno = HVC_COOKIE;
@@ -375,7 +375,6 @@ static int xencons_connect_backend(struct xenbus_device 
*dev,
int ret, evtchn, devid, ref, irq;
struct xenbus_transaction xbt;
grant_ref_t gref_head;
-   unsigned long mfn;
 
ret = xenbus_alloc_evtchn(dev, &evtchn);
if (ret)
@@ -390,10 +389,6 @@ static int xencons_connect_backend(struct xenbus_device 
*dev,
irq, &domU_hvc_ops, 256);
if (IS_ERR(info->hvc))
return PTR_ERR(info->hvc);
-   if (xen_pv_domain())
-   mfn = virt_to_gfn(info->intf);
-   else
-   mfn = __pa(info->intf) >> PAGE_SHIFT;
ret = gnttab_alloc_grant_references(1, &gref_head);
if (ret < 0)
return ret;
@@ -402,7 +397,7 @@ static int xencons_connect_backend(struct xenbus_device 
*dev,
if (ref < 0)
return ref;
gnttab_grant_foreign_access_ref(ref, info->xbdev->otherend_id,
-   mfn, 0);
+   virt_to_gfn(info->intf), 0);
 
  again:
ret = xenbus_transaction_start(&xbt);
-- 
2.1.4

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH v3 0/9] Use correctly the Xen memory terminologies

2015-08-07 Thread Julien Grall
Hi all,

This patch series aims to use the memory terminologies described in
include/xen/mm.h [1] for Linux xen code.

The differences from v2 is minor but I resent it because my 64K series depends
on this series.

Linux is using mistakenly MFN when GFN is meant, I suspect this is because the
first support of Xen was for PV. This has brought some misimplementation
of memory helpers on ARM and make the developper confused about the expected
behavior.

For instance, with pfn_to_mfn, we expect to get a MFN based on the name.
Although, if we look at the implementation on x86, it's returning a GFN.
Most of the callers are also using it this way.

The first 2 patches of this series is ARM related in order to remove
PV specific helpers which should not be used and fixing the implementation of
pfn_to_mfn.

The rest of the series is here rename most of the usage in the common code
of MFN to GFN. I also took the opportunity to replace most of the call to
pfn_to_gfn in the common code by page_to_gfn avoid construction such
as pfn_to_gfn(page_to_pfn(...).

Note the one xen-blkfront will be dropped by 64K series [2], I can include
here if necessary.

Major changes in v3:
- More typoes
- Rename page_to_gfn to xen_page_to_gfn to avoid confusing with the
KVM function gfn_to_page

Major changes in v2:
- Use bfn rather than dfn for the DMA address
- Re-introduced pfn_to_mfn for PV guests only
- Typoes

For all the changes see in each patch.

This series is based on xentip for-linus-4.3 branch. A branch with all the
patches can be found here:
git://xenbits.xen.org/people/julieng/linux-arm.git branch page-renaming-v3

It has been boot tested on ARM64 and ARM32 and only built for x86.
I would be happy if someone can give a try on x86 as I don't have a x86
box setup with Xen.

Sincerely yours,

[1] 
http://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=e758ed14f390342513405dd766e874934573e6cb
[2] https://lkml.org/lkml/2015/7/9/628

Cc: Boris Ostrovsky 
Cc: David Vrabel 
Cc: Dmitry Torokhov 
Cc: Greg Kroah-Hartman 
Cc: "H. Peter Anvin" 
Cc: Ian Campbell 
Cc: Ingo Molnar 
Cc: "James E.J. Bottomley" 
Cc: Jean-Christophe Plagniol-Villard 
Cc: Jiri Slaby 
Cc: Juergen Gross 
Cc: Konrad Rzeszutek Wilk 
Cc: linux-...@vger.kernel.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-fb...@vger.kernel.org
Cc: linux-in...@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-s...@vger.kernel.org
Cc: net...@vger.kernel.org
Cc: "Roger Pau Monné" 
Cc: Russell King 
Cc: Stefano Stabellini 
Cc: Thomas Gleixner 
Cc: Tomi Valkeinen 
Cc: Wei Liu 
Cc: x...@kernel.org



Julien Grall (9):
  arm/xen: Remove helpers which are PV specific
  xen: Make clear that swiotlb and biomerge are dealing with DMA address
  arm/xen: implement correctly pfn_to_mfn
  xen: Use correctly the Xen memory terminologies
  xen/tmem: Use xen_page_to_gfn rather than pfn_to_gfn
  video/xen-fbfront: Further s/MFN/GFN clean-up
  hvc/xen: Further s/MFN/GFN clean-up
  xen/privcmd: Further s/MFN/GFN/ clean-up
  xen/xenbus: Rename the variable xen_store_mfn to xen_store_gfn

 arch/arm/include/asm/xen/page.h | 44 -
 arch/arm/xen/enlighten.c| 18 +++---
 arch/arm/xen/mm.c   |  4 +--
 arch/x86/include/asm/xen/page.h | 35 +-
 arch/x86/xen/mmu.c  | 32 
 arch/x86/xen/smp.c  |  2 +-
 drivers/block/xen-blkfront.c|  6 ++---
 drivers/input/misc/xen-kbdfront.c   |  4 +--
 drivers/net/xen-netback/netback.c   |  4 +--
 drivers/net/xen-netfront.c  | 12 +
 drivers/scsi/xen-scsifront.c| 10 
 drivers/tty/hvc/hvc_xen.c   | 18 ++
 drivers/video/fbdev/xen-fbfront.c   | 20 +++
 drivers/xen/balloon.c   |  2 +-
 drivers/xen/biomerge.c  |  6 ++---
 drivers/xen/events/events_base.c|  2 +-
 drivers/xen/events/events_fifo.c|  4 +--
 drivers/xen/gntalloc.c  |  3 ++-
 drivers/xen/manage.c|  2 +-
 drivers/xen/privcmd.c   | 44 -
 drivers/xen/swiotlb-xen.c   | 16 ++--
 drivers/xen/tmem.c  | 21 ++--
 drivers/xen/xenbus/xenbus_client.c  |  2 +-
 drivers/xen/xenbus/xenbus_dev_backend.c |  2 +-
 drivers/xen/xenbus/xenbus_probe.c   | 16 ++--
 drivers/xen/xlate_mmu.c | 18 +++---
 include/uapi/xen/privcmd.h  |  4 +++
 include/xen/page.h  |  4 +--
 include/xen/xen-ops.h   | 10 
 29 files changed, 191 insertions(+), 174 deletions(-)

-- 
2.1.4

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH v3 4/9] xen: Use correctly the Xen memory terminologies

2015-08-07 Thread Julien Grall
Based on include/xen/mm.h [1], Linux is mistakenly using MFN when GFN
is meant, I suspect this is because the first support for Xen was for
PV. This resulted in some misimplementation of helpers on ARM and
confused developers about the expected behavior.

For instance, with pfn_to_mfn, we expect to get an MFN based on the name.
Although, if we look at the implementation on x86, it's returning a GFN.

For clarity and avoid new confusion, replace any reference to mfn with
gfn in any helpers used by PV drivers. The x86 code will still keep some
reference of pfn_to_mfn but exclusively for PV (a BUG_ON has been added
to ensure this). No changes as been made in the hypercall field, even
though they may be invalid, in order to keep the same as the defintion
in xen repo.

Note that page_to_mfn has been renamed to xen_page_to_gfn to avoid a
name to close to the KVM function gfn_to_page.

Take also the opportunity to simplify simple construction such
as pfn_to_mfn(page_to_pfn(page)) into xen_page_to_gfn. More complex clean up
will come in follow-up patches.

[1] 
http://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=e758ed14f390342513405dd766e874934573e6cb

Signed-off-by: Julien Grall 
Reviewed-by: Stefano Stabellini 
Acked-by: Dmitry Torokhov 
Acked-by: Wei Liu 

---
Cc: Russell King 
Cc: Konrad Rzeszutek Wilk 
Cc: Boris Ostrovsky 
Cc: David Vrabel 
Cc: Thomas Gleixner 
Cc: Ingo Molnar 
Cc: "H. Peter Anvin" 
Cc: x...@kernel.org
Cc: "Roger Pau Monné" 
Cc: Ian Campbell 
Cc: Juergen Gross 
Cc: "James E.J. Bottomley" 
Cc: Greg Kroah-Hartman 
Cc: Jiri Slaby 
Cc: Jean-Christophe Plagniol-Villard 
Cc: Tomi Valkeinen 
Cc: linux-in...@vger.kernel.org
Cc: net...@vger.kernel.org
Cc: linux-s...@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-fb...@vger.kernel.org
Cc: linux-arm-ker...@lists.infradead.org

Note that I've re-introduced in v2 mfn_to_pfn & co only for x86 PV code.
The helpers contain a BUG_ON to ensure that it's never called for
auto-translated guests. I did as best as my can to determine whether
mfn or gfn helpers should be used. Although, I haven't tried to boot
it.

It may be possible to do further cleanup in the mmu.c where I found
some check to auto-translated. I'm not sure why given that the pvmmu
callback are only used for non-auto translated guest.

Changes in v3:
- Add Stefano's reviewed-by (except for the x86 bits)
- Add Wei (netback) and Dmitry's (input) acked-by
- Keep the VIRT <-> MACHINE macro in the same order as before
in arch/x86/include/asm/xen/page.h
- Rename page_to_gfn to xen_page_to_gfn to avoid confusion with
the KVM function gfn_to_page.
- Typoes in the commit title

Changes in v2:
- Give directly the URL to the commit rather than the commit ID
- xenstored_local_init: keep the cast to void *
- Typoes
- Keep pfn_to_mfn for x86 and PV-only. The *mfn* helpers are
used in arch/x86/xen for enlighten.c, mmu.c, p2m.c, setup.c,
smp.c and mm.c
---
 arch/arm/include/asm/xen/page.h | 13 +++--
 arch/x86/include/asm/xen/page.h | 31 +--
 arch/x86/xen/smp.c  |  2 +-
 drivers/block/xen-blkfront.c|  6 +++---
 drivers/input/misc/xen-kbdfront.c   |  4 ++--
 drivers/net/xen-netback/netback.c   |  4 ++--
 drivers/net/xen-netfront.c  | 12 +++-
 drivers/scsi/xen-scsifront.c| 10 +-
 drivers/tty/hvc/hvc_xen.c   |  5 +++--
 drivers/video/fbdev/xen-fbfront.c   |  4 ++--
 drivers/xen/balloon.c   |  2 +-
 drivers/xen/events/events_base.c|  2 +-
 drivers/xen/events/events_fifo.c|  4 ++--
 drivers/xen/gntalloc.c  |  3 ++-
 drivers/xen/manage.c|  2 +-
 drivers/xen/tmem.c  |  4 ++--
 drivers/xen/xenbus/xenbus_client.c  |  2 +-
 drivers/xen/xenbus/xenbus_dev_backend.c |  2 +-
 drivers/xen/xenbus/xenbus_probe.c   |  8 +++-
 include/xen/page.h  |  4 ++--
 20 files changed, 73 insertions(+), 51 deletions(-)

diff --git a/arch/arm/include/asm/xen/page.h b/arch/arm/include/asm/xen/page.h
index 911d62b..1279563 100644
--- a/arch/arm/include/asm/xen/page.h
+++ b/arch/arm/include/asm/xen/page.h
@@ -34,14 +34,15 @@ typedef struct xpaddr {
 unsigned long __pfn_to_mfn(unsigned long pfn);
 extern struct rb_root phys_to_mach;
 
-static inline unsigned long pfn_to_mfn(unsigned long pfn)
+/* Pseudo-physical <-> Guest conversion */
+static inline unsigned long pfn_to_gfn(unsigned long pfn)
 {
return pfn;
 }
 
-static inline unsigned long mfn_to_pfn(unsigned long mfn)
+static inline unsigned long gfn_to_pfn(unsigned long gfn)
 {
-   return mfn;
+   return gfn;
 }
 
 /* Pseudo-physical <-> BUS conversion */
@@ -65,9 +66,9 @@ static inline unsigned long bfn_to_pfn(unsigned long bfn)
 
 #define bfn_to_local_pfn

[PATCH v3 11/20] tty/hvc: xen: Use xen page definition

2015-08-07 Thread Julien Grall
The console ring is always based on the page granularity of Xen.

Signed-off-by: Julien Grall 
Reviewed-by: Stefano Stabellini 

---
Cc: Greg Kroah-Hartman 
Cc: Jiri Slaby 
Cc: David Vrabel 
Cc: Boris Ostrovsky 
Cc: linuxppc-dev@lists.ozlabs.org

Changes in v3:
- Some changes has been moved in the series "Use correctly the
Xen memory terminologies in Linux".
- Add Stefano's reviewed-by
---
 drivers/tty/hvc/hvc_xen.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/hvc/hvc_xen.c b/drivers/tty/hvc/hvc_xen.c
index 10beb15..0599d9d 100644
--- a/drivers/tty/hvc/hvc_xen.c
+++ b/drivers/tty/hvc/hvc_xen.c
@@ -230,7 +230,7 @@ static int xen_hvm_console_init(void)
if (r < 0 || v == 0)
goto err;
gfn = v;
-   info->intf = xen_remap(gfn << PAGE_SHIFT, PAGE_SIZE);
+   info->intf = xen_remap(gfn << XEN_PAGE_SHIFT, PAGE_SIZE);
if (info->intf == NULL)
goto err;
info->vtermno = HVC_COOKIE;
@@ -472,7 +472,7 @@ static int xencons_resume(struct xenbus_device *dev)
struct xencons_info *info = dev_get_drvdata(&dev->dev);
 
xencons_disconnect_backend(info);
-   memset(info->intf, 0, PAGE_SIZE);
+   memset(info->intf, 0, XEN_PAGE_SIZE);
return xencons_connect_backend(dev, info);
 }
 
-- 
2.1.4

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH 05/31] arch/powerpc/nvram: use kmemdup rather than duplicating its implementation

2015-08-07 Thread Nathan Fontenot
On 08/07/2015 02:59 AM, Andrzej Hajda wrote:
> The patch was generated using fixed coccinelle semantic patch
> scripts/coccinelle/api/memdup.cocci [1].
> 
> [1]: http://permalink.gmane.org/gmane.linux.kernel/2014320
> 
> Signed-off-by: Andrzej Hajda 

Reviewed-by: Nathan Fontenot 

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH 06/31] arch/powerpc/pseries: use kmemdup rather than duplicating its implementation

2015-08-07 Thread Nathan Fontenot
On 08/07/2015 02:59 AM, Andrzej Hajda wrote:
> The patch was generated using fixed coccinelle semantic patch
> scripts/coccinelle/api/memdup.cocci [1].
> 
> [1]: http://permalink.gmane.org/gmane.linux.kernel/2014320
> 
> Signed-off-by: Andrzej Hajda 

Reviewed-by: Nathan Fontenot 

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [v4, 0/9] Freescale DPAA FMan

2015-08-07 Thread David Miller
From: 
Date: Wed, 5 Aug 2015 12:25:16 +0300

> The Freescale Data Path Acceleration Architecture (DPAA)
> is a set of hardware components on specific QorIQ multicore processors.
> This architecture provides the infrastructure to support simplified
> sharing of networking interfaces and accelerators by multiple CPU cores
> and the accelerators.

I think the directory and code structure of this new driver is
quite excessive.

Because you've split things up _so_ much, you have to have
all of these directories, and even worse and much more important
to me you have to export so many functions from one source file
to another.

I think this is way too much.

For example, in one file you have a bunch of initialization routines.
init_a(), init_b(), init_c(), and you export them all.  Then they
are always called in sequence:

init_a();
init_b();
init_c();

This is completely pointless.  You just needed to export one
function which calls all three functions.

The namespace pollution of this driver is out of control.

You really need to completely rework the architecture and
layout of this driver before I will even begin to review it
again.

And the lack of review interest by other developers should be an
indication to you how undesirable this code submission is to read.

Thanks.
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH 0/8] misc: remove boundary checks from bin attr users

2015-08-07 Thread Wolfram Sang

> if we're talking about this particular series, you should have them in
> your mailbox, since you have them applied in wsa/i2c/for-next:

Those are already in linus tree. I mean all drivers which use struct
i2c_driver. Or do you prefer they go via Greg? I am fine with both.



signature.asc
Description: Digital signature
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [v2 8/9] dpaa_eth: add debugfs entries

2015-08-07 Thread David Miller
From: Madalin Bucur 
Date: Wed, 5 Aug 2015 18:41:28 +0300

> Export per CPU counters through debugfs.
> 
> Signed-off-by: Madalin Bucur 

This is absolutely inappropriate.

You can export these just fine via ethtool statistics.  There is zero reason
to add ugly debugfs crap for something like this.
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH 1/3] Powerpc: mpc85xx: refactor the PM operations

2015-08-07 Thread Scott Wood
On Fri, 2015-08-07 at 11:19 +0800, Chenhui Zhao wrote:
> On Fri, Aug 7, 2015 at 2:02 AM, Scott Wood  
> wrote:
> > On Thu, 2015-08-06 at 13:54 +0800, Chenhui Zhao wrote:
> > >  On Thu, Aug 6, 2015 at 1:46 PM, Scott Wood 
> > >  wrote:
> > >  > On Thu, 2015-08-06 at 12:20 +0800, Chenhui Zhao wrote:
> > >  > >  On Thu, Aug 6, 2015 at 10:57 AM, Scott Wood
> > >  > > 
> > >  > >  wrote:
> > >  > >  > On Wed, 2015-08-05 at 18:11 +0800, Chenhui Zhao wrote:
> > >  > >  > >  On Tue, Aug 4, 2015 at 4:26 AM, Scott Wood
> > >  > > 
> > >  > >  > >  wrote:
> > >  > >  > >  > On Mon, 2015-08-03 at 19:32 +0800, Chenhui Zhao wrote:
> > >  > >  > >  > >  >
> > >  > >  > >  >
> > >  > >  > >  > >  On Sat, Aug 1, 2015 at 7:59 AM, Scott Wood
> > >  > >  > > 
> > >  > >  > >  > >  wrote:
> > >  > >  > >  >
> > >  > >  > >  > >  >
> > >  > >  > >  > >  > Could you explain irq_mask()?  Why would there 
> > > still be
> > >  > > IRQs
> > >  > >  > >  > > destined
> > >  > >  > >  > >  > for
> > >  > >  > >  > >  > this CPU at this point?
> > >  > >  > >  > >
> > >  > >  > >  > >  This function just masks irq by setting the 
> > > registers in
> > >  > > RCPM
> > >  > >  > > (for
> > >  > >  > >  > >  example, RCPM_CPMIMR, RCPM_CPMCIMR). Actually, all 
> > > irqs to
> > >  > >  > > this CPU
> > >  > >  > >  > >  have been migrated to other CPUs.
> > >  > >  > >  >
> > >  > >  > >  > So why do we need to set those bits in RCPM?  Is it just
> > >  > > caution?
> > >  > >  > >
> > >  > >  > >  Setting these bits can mask interrupts signalled to RCPM 
> > > from
> > >  > > MPIC
> > >  > >  > > as a
> > >  > >  > >  means of
> > >  > >  > >  waking up from a lower power state. So, cores will not be
> > >  > > waked up
> > >  > >  > >  unexpectedly.
> > >  > >  >
> > >  > >  > Why would the MPIC be signalling those interrupts if they've 
> > > been
> > >  > >  > masked at
> > >  > >  > the MPIC?
> > >  > >  >
> > >  > >  > -Scott
> > >  > >  >
> > >  > >
> > >  > >  The interrupts to RCPM from MPIC are IRQ, Machine Check, NMI 
> > > and
> > >  > >  Critical interrupts. Some of them didn't be masked in MPIC.
> > >  >
> > >  > What interrupt could actually happen to a sleeping cpu that this
> > >  > protects
> > >  > against?
> > >  >
> > >  > -Scott
> > > 
> > >  Not sure. Maybe spurious interrupts or hardware exceptions.
> > 
> > Spurious interrupts happen due to race conditions.  They don't happen 
> > because
> > the MPIC is bored and decides to ring a CPU's doorbell and hide in 
> > the bushes.
> > 
> > If by "hardware exceptions" you mean machine checks, how would such a 
> > machine
> > check be generated by a core that is off?
> > 
> > >   However, setting them make sure dead cpus can not be waked up 
> > > unexpectedly.
> > 
> > I'm not seeing enough value here to warrant resurrecting the old 
> > sleep node
> > stuff.
> > 
> > -Scott
> 
> My guess maybe not accurate. My point is that electronic parts don't 
> always work as expected. Taking preventative measures can make the 
> system more robust. In addition, this step is required in deep sleep 
> procedure.

The deep sleep part is more convincing -- so MPIC masking is not effective 
during deep sleep?

-Scott

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 00/16] Add vTPM support to SLOF

2015-08-07 Thread Stefan Berger
The following series of patches adds TPM support to SLOF.
In particular it adds the following:

- TPM drivers for hardware interface and CRQ interface
- TPM initialization
- TPM logging area and firmware API to transfer it to the OS
  (measurements are visible in sysfs)
- Some measurement code (Static Core Root Of Trust)
- TPM menu (accessible via 't' key during boot if TPM is available)
- Firmware API extensions following Power Firmware Doc
  (to make trusted grub work)

Necessarily, some of its parts are written in Forth, many are written
in 'C'. The extensions are known to work with QEMU for ppc64 running Linux.

Patches 4-6 will eventually need to be merged to avoid compiler warnings
related to unused functions.

Regards,
Stefan

Stefan Berger (16):
  Add a TPM driver implementation
  Add TPM initialization support
  Add sha1 implementation
  Add initial support for logging
  Extend internal firmware API
  Return value of actual log in sml-get-handover-size
  Perform some initial measurements
  Add support for controlling the states of the TPM
  Add support for a TPM menu to control the state of the TPM
  Implement measurements of the master boot record
  Measure the static core root of trust for measurements
  Add TPM firmware API calls hash-all, log-event, hash-log-extend-event
  Add TPM firmware API call get-maximum-cmd-size
  Add TPM firmware API call pass-through-to-tpm
  Add TPM firmware API call get-state
  Add TPM firmware API call get-failure-reason

 board-js2x/slof/OF.fs   |2 +
 board-qemu/Makefile |2 +-
 board-qemu/slof/Makefile|   10 +-
 board-qemu/slof/OF.fs   |7 +
 board-qemu/slof/tree.fs |3 +
 board-qemu/slof/vio-vtpm-cdriver.fs |  144 
 board-qemu/slof/vtpm-sml.fs |  108 +++
 include/helpers.h   |1 +
 lib/Makefile|2 +-
 lib/libtpm/Makefile |   51 ++
 lib/libtpm/sha1.c   |  197 +
 lib/libtpm/sha1.h   |   20 +
 lib/libtpm/tcgbios.c| 1563 +++
 lib/libtpm/tcgbios.h|   53 ++
 lib/libtpm/tcgbios_int.h|  206 +
 lib/libtpm/tpm.code |  207 +
 lib/libtpm/tpm.in   |   33 +
 lib/libtpm/tpm_drivers.c|  456 ++
 lib/libtpm/tpm_drivers.h|   93 +++
 slof/fs/packages/disk-label.fs  |6 +-
 slof/fs/start-up.fs |9 +
 slof/fs/tpm/tpm-static.fs   |  351 
 slof/helpers.c  |6 +
 23 files changed, 3524 insertions(+), 6 deletions(-)
 create mode 100644 board-qemu/slof/vio-vtpm-cdriver.fs
 create mode 100644 board-qemu/slof/vtpm-sml.fs
 create mode 100644 lib/libtpm/Makefile
 create mode 100644 lib/libtpm/sha1.c
 create mode 100644 lib/libtpm/sha1.h
 create mode 100644 lib/libtpm/tcgbios.c
 create mode 100644 lib/libtpm/tcgbios.h
 create mode 100644 lib/libtpm/tcgbios_int.h
 create mode 100644 lib/libtpm/tpm.code
 create mode 100644 lib/libtpm/tpm.in
 create mode 100644 lib/libtpm/tpm_drivers.c
 create mode 100644 lib/libtpm/tpm_drivers.h
 create mode 100644 slof/fs/tpm/tpm-static.fs

-- 
1.9.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 02/16] Add TPM initialization support

2015-08-07 Thread Stefan Berger
This patch implements the main part of the fimrmware extensions. It provides
the following functionality:

- initialization of the TPM by sending a sequence of commands to it
- proper setup of the TPM before the firmware hands over control to the 
bootloader

Structures that are needed in subsequent patches are also included in the
private header file tcgbios_int.h at this point.

Signed-off-by: Stefan Berger 
---
 board-qemu/Makefile |   2 +-
 board-qemu/slof/Makefile|  10 +-
 board-qemu/slof/OF.fs   |   6 +
 board-qemu/slof/tree.fs |   3 +
 board-qemu/slof/vio-vtpm-cdriver.fs |  74 +++
 board-qemu/slof/vtpm-sml.fs |  56 ++
 lib/Makefile|   2 +-
 lib/libtpm/Makefile |   2 +-
 lib/libtpm/tcgbios.c| 371 
 lib/libtpm/tcgbios.h|  21 ++
 lib/libtpm/tcgbios_int.h| 162 
 lib/libtpm/tpm.code |  37 
 lib/libtpm/tpm.in   |  17 ++
 slof/fs/tpm/tpm-static.fs   |  34 
 14 files changed, 791 insertions(+), 6 deletions(-)
 create mode 100644 board-qemu/slof/vio-vtpm-cdriver.fs
 create mode 100644 board-qemu/slof/vtpm-sml.fs
 create mode 100644 lib/libtpm/tcgbios.c
 create mode 100644 lib/libtpm/tcgbios.h
 create mode 100644 lib/libtpm/tcgbios_int.h
 create mode 100644 lib/libtpm/tpm.code
 create mode 100644 lib/libtpm/tpm.in
 create mode 100644 slof/fs/tpm/tpm-static.fs

diff --git a/board-qemu/Makefile b/board-qemu/Makefile
index 29ee016..0c03e54 100644
--- a/board-qemu/Makefile
+++ b/board-qemu/Makefile
@@ -15,7 +15,7 @@ BOARD_TARGETS = tools_build romfs_build clients_build stage1 
subdirs
 SUBDIRS = slof
 
 COMMON_LIBS = libc libbootmsg libbases libnvram libelf libhvcall libvirtio 
libusb \
-  libveth libe1k
+  libveth libe1k libtpm
 
 all: $(BOARD_TARGETS)
$(MAKE) boot_rom.bin
diff --git a/board-qemu/slof/Makefile b/board-qemu/slof/Makefile
index 283f77d..be6eec1 100644
--- a/board-qemu/slof/Makefile
+++ b/board-qemu/slof/Makefile
@@ -21,7 +21,7 @@ all: version.o Makefile.dep OF.ffs paflof 
$(SLOFCMNDIR)/xvect.bin
 CPPFLAGS = -I$(LIBCMNDIR)/libbootmsg -I$(LIBCMNDIR)/libhvcall \
   -I$(LIBCMNDIR)/libvirtio -I$(LIBCMNDIR)/libnvram \
   -I$(LIBCMNDIR)/libusb -I$(LIBCMNDIR)/libveth \
-  -I$(LIBCMNDIR)/libe1k
+  -I$(LIBCMNDIR)/libe1k -I$(LIBCMNDIR)/libtpm
 SLOF_LIBS = \
$(LIBCMNDIR)/libbootmsg.a \
$(LIBCMNDIR)/libelf.a \
@@ -30,7 +30,8 @@ SLOF_LIBS = \
$(LIBCMNDIR)/libusb.a \
$(LIBCMNDIR)/libnvram.a \
$(LIBCMNDIR)/libveth.a \
-   $(LIBCMNDIR)/libe1k.a
+   $(LIBCMNDIR)/libe1k.a \
+   $(LIBCMNDIR)/libtpm.a
 BOARD_SLOF_IN = \
$(LIBCMNDIR)/libhvcall/hvcall.in \
$(LIBCMNDIR)/libvirtio/virtio.in \
@@ -40,7 +41,8 @@ BOARD_SLOF_IN = \
$(LIBCMNDIR)/libnvram/libnvram.in \
$(LIBCMNDIR)/libbases/libbases.in \
$(LIBCMNDIR)/libveth/veth.in \
-   $(LIBCMNDIR)/libe1k/e1k.in
+   $(LIBCMNDIR)/libe1k/e1k.in \
+   $(LIBCMNDIR)/libtpm/tpm.in
 BOARD_SLOF_CODE = $(BOARD_SLOF_IN:%.in=%.code)
 
 include $(SLOFCMNDIR)/Makefile.inc
@@ -71,6 +73,7 @@ VIO_FFS_FILES = \
$(SLOFBRDDIR)/pci-device_1af4_1009.fs \
$(SLOFBRDDIR)/vio-hvterm.fs \
$(SLOFBRDDIR)/vio-vscsi.fs \
+   $(SLOFBRDDIR)/vio-vtpm-cdriver.fs \
$(SLOFBRDDIR)/vio-veth.fs \
$(SLOFBRDDIR)/rtas-nvram.fs \
$(SLOFBRDDIR)/virtio-net.fs \
@@ -99,6 +102,7 @@ OF_FFS_FILES = \
$(SLOFBRDDIR)/default-font.bin \
$(SLOFBRDDIR)/pci-phb.fs \
$(SLOFBRDDIR)/rtas.fs \
+   $(SLOFBRDDIR)/vtpm-sml.fs \
$(SLOFBRDDIR)/pci-device_1234_.fs \
$(SLOFBRDDIR)/pci-device_1013_00b8.fs \
$(SLOFBRDDIR)/pci-device_8086_100e.fs \
diff --git a/board-qemu/slof/OF.fs b/board-qemu/slof/OF.fs
index 561d892..bd9495e 100644
--- a/board-qemu/slof/OF.fs
+++ b/board-qemu/slof/OF.fs
@@ -113,6 +113,10 @@ d# 51200 VALUE tb-frequency   \ default value - needed 
for "ms" to work
 
 #include "fdt.fs"
 
+350 cp
+
+#include 
+
 360 cp
 
 #include 
@@ -300,6 +304,8 @@ cr
 #include "copyright-oss.fs"
 cr cr
 
+vtpm-unassert-pp
+
 \ this CATCH is to ensure the code bellow always executes:  boot may ABORT!
 ' start-it CATCH drop
 
diff --git a/board-qemu/slof/tree.fs b/board-qemu/slof/tree.fs
index 4aba4c5..b71009d 100644
--- a/board-qemu/slof/tree.fs
+++ b/board-qemu/slof/tree.fs
@@ -83,6 +83,9 @@ include fbuffer.fs
2dup " qemu,spapr-nvram" strequal IF
" rtas-nvram.fs" included
THEN
+   2dup " IBM,vtpm" strequal IF
+" vio-vtpm-cdriver.fs" included
+   THEN
 2drop
THEN
peer
diff --git a/board-qemu/slof/vio-vtpm-cdriver.fs 
b/board-qemu/slof/vio-vtpm-cdriver.fs
new file mode 100644
index 000..2fc1657
--- /dev/null
+++ b/boa

[PATCH 13/16] Add TPM firmware API call get-maximum-cmd-size

2015-08-07 Thread Stefan Berger
This patch adds support for the firmware API call get-maximum-cmd-size.

Signed-off-by: Stefan Berger 
---
 board-qemu/slof/vio-vtpm-cdriver.fs |  7 ++
 board-qemu/slof/vtpm-sml.fs |  6 +
 lib/libtpm/tcgbios.c| 44 +
 lib/libtpm/tcgbios.h|  1 +
 lib/libtpm/tcgbios_int.h|  7 ++
 lib/libtpm/tpm.code | 10 +
 lib/libtpm/tpm.in   |  1 +
 slof/fs/tpm/tpm-static.fs   | 12 ++
 8 files changed, 88 insertions(+)

diff --git a/board-qemu/slof/vio-vtpm-cdriver.fs 
b/board-qemu/slof/vio-vtpm-cdriver.fs
index 44e5aec..22fef4f 100644
--- a/board-qemu/slof/vio-vtpm-cdriver.fs
+++ b/board-qemu/slof/vio-vtpm-cdriver.fs
@@ -95,6 +95,13 @@ false VALUE vtpm-debug?
 THEN
 ;
 
+\ firmware API call
+: get-maximum-cmd-size ( -- maximum-size )
+" get-maximum-cmd-size" call-forward IF
+0
+THEN
+;
+
 : open ( )
 vtpm-debug? IF ." VTPM: vTPM open()" cr THEN
 true
diff --git a/board-qemu/slof/vtpm-sml.fs b/board-qemu/slof/vtpm-sml.fs
index 8783bf1..e62c20c 100644
--- a/board-qemu/slof/vtpm-sml.fs
+++ b/board-qemu/slof/vtpm-sml.fs
@@ -73,6 +73,12 @@ log-base LOG-SIZE tpm-set-log-parameters
 vtpm-hash-log-extend-event
 ;
 
+: get-maximum-cmd-size ( -- max-size )
+vtpm-debug? IF
+." Call to get-maximum-cmd-size" cr
+THEN
+vtpm-get-maximum-cmd-size
+;
 
 : open  true ;
 : close ;
diff --git a/lib/libtpm/tcgbios.c b/lib/libtpm/tcgbios.c
index 621c3e8..b306edf 100644
--- a/lib/libtpm/tcgbios.c
+++ b/lib/libtpm/tcgbios.c
@@ -35,6 +35,8 @@
} \
 } while (0);
 
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+
 static const uint8_t Startup_ST_CLEAR[] = { 0x00, TPM_ST_CLEAR };
 static const uint8_t Startup_ST_STATE[] = { 0x00, TPM_ST_STATE };
 
@@ -71,6 +73,11 @@ static const uint8_t GetCapability_Durations[] = {
0x00, 0x00, 0x01, 0x20
 };
 
+static const uint8_t GetCapability_BufferSize[] = {
+   0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x04,
+   0x00, 0x00, 0x01, 0x24
+};
+
 static uint8_t evt_separator[] = {0xff,0xff,0xff,0xff};
 
 struct tpm_state {
@@ -1461,3 +1468,40 @@ uint32_t tpm_measure_scrtm(void)
 
return rc;
 }
+
+/*
+ * tpm_get_maximum_cmd_size: Function for interfacing with the firmware API
+ *
+ * This function returns the maximum size a TPM command (or response) may have.
+ */
+uint32_t tpm_get_maximum_cmd_size(void)
+{
+   uint32_t rc;
+   uint32_t returnCode;
+   struct tpm_res_getcap_buffersize buffersize;
+   uint32_t result;
+   struct tpm_driver *td = tpm_state.tpm_driver_to_use;
+
+   if (!has_working_tpm())
+   return 0;
+
+   rc = build_and_send_cmd(TPM_ORD_GetCapability,
+   GetCapability_BufferSize,
+   sizeof(GetCapability_BufferSize),
+   (uint8_t *)&buffersize, sizeof(buffersize),
+   &returnCode, TPM_DURATION_TYPE_SHORT);
+
+   if (rc || returnCode)
+   goto err_exit;
+
+   result = MIN(cpu_to_be32(buffersize.buffersize), td->getbuffersize());
+
+   return result;
+
+err_exit:
+   dprintf("TPM malfunctioning (line %d).\n", __LINE__);
+
+   tpm_state.tpm_working = 0;
+
+   return 0;
+}
diff --git a/lib/libtpm/tcgbios.h b/lib/libtpm/tcgbios.h
index 0dacba2..2aa7d20 100644
--- a/lib/libtpm/tcgbios.h
+++ b/lib/libtpm/tcgbios.h
@@ -36,6 +36,7 @@ uint32_t tpm_process_opcode(uint8_t op, bool verbose);
 uint32_t tpm_hash_log_extend_event(struct pcpes *pcpes);
 bool tpm_log_event(struct pcpes *pcpes);
 uint32_t tpm_hash_all(const void *data, uint32_t datalen, void *hashptr);
+uint32_t tpm_get_maximum_cmd_size(void);
 
 /* flags returned by tpm_get_state */
 #define TPM_STATE_ENABLED1
diff --git a/lib/libtpm/tcgbios_int.h b/lib/libtpm/tcgbios_int.h
index bedc2f1..249e205 100644
--- a/lib/libtpm/tcgbios_int.h
+++ b/lib/libtpm/tcgbios_int.h
@@ -177,6 +177,13 @@ struct tpm_res_getcap_durations {
 uint32_tdurations[TPM_NUM_DURATIONS];
 } __attribute__((packed));
 
+struct tpm_res_getcap_buffersize {
+TPM_RSP_HEADER
+uint32_tsize;
+uint32_tbuffersize;
+} __attribute__((packed));
+
+
 struct tpm_res_sha1start {
 TPM_RSP_HEADER
 uint32_tmax_num_bytes;
diff --git a/lib/libtpm/tpm.code b/lib/libtpm/tpm.code
index acd3a10..5c3d4db 100644
--- a/lib/libtpm/tpm.code
+++ b/lib/libtpm/tpm.code
@@ -164,3 +164,13 @@ PRIM(tpm_X2d_hash_X2d_all)
void *dataptr = TOS.a;
TOS.n = tpm_hash_all(dataptr, datalen, hashptr);
 MIRP
+
+//
+/* Firmware API */
+/* SLOF:   tpm-get-maximum-cmd-size ( -- max-size)  */
+/* LIBTPM: maxsize = tpm_get_maximum_cmd_size() */
+//
+PRIM(tpm_X2d_get_X2d_maximum_X2d_cmd_X2d_size)
+   PUSH;
+  

[PATCH 05/16] Extend internal firmware API

2015-08-07 Thread Stefan Berger
Extend the internal API of the TPM firmware support with additional
functions for hashing data, extending the TPM's platform configuration
registers with a hash, and appending to the log that is recording
what was hashed.

Signed-off-by: Stefan Berger 
---
 lib/libtpm/tcgbios.c | 276 +++
 lib/libtpm/tcgbios_int.h |   1 +
 2 files changed, 277 insertions(+)

diff --git a/lib/libtpm/tcgbios.c b/lib/libtpm/tcgbios.c
index afbaede..072ed4d 100644
--- a/lib/libtpm/tcgbios.c
+++ b/lib/libtpm/tcgbios.c
@@ -24,6 +24,9 @@
 #include "tcgbios.h"
 #include "tcgbios_int.h"
 #include "stdio.h"
+#include "sha1.h"
+#include "stddef.h"
+#include "helpers.h"
 
 #define DEBUG 0
 #define dprintf(_x ...) do { \
@@ -79,6 +82,8 @@ extern struct tpm_driver tpm_drivers[];
 
 static void *log_base;
 static uint32_t log_area_size;
+/* next log entry goes here */
+static void *log_area_address_next;
 
 /
   Extensions for TCG-enabled BIOS
@@ -89,6 +94,7 @@ void tpm_set_log_parameters(void *addr, unsigned int size)
dprintf("Log is at 0x%llx; size is %u bytes\n",
(uint64_t)addr, size);
log_base = addr;
+   log_area_address_next = addr;
log_area_size = size;
 }
 
@@ -399,3 +405,273 @@ err_exit:
return rc;
return TCGBIOS_COMMAND_ERROR;
 }
+
+static void set_log_area_address_next(void *next)
+{
+   log_area_address_next = next;
+}
+
+static void *get_log_area_address_next(void)
+{
+   return log_area_address_next;
+}
+
+static uint32_t tpm_sha1_calc(const uint8_t *data, uint32_t length,
+ uint8_t *hash)
+{
+   uint32_t rc;
+   uint32_t returnCode;
+   struct tpm_res_sha1start start;
+   struct tpm_res_sha1complete complete;
+   uint32_t blocks = length / 64;
+   uint32_t rest = length & 0x3f;
+   uint32_t numbytes, numbytes_no;
+   uint32_t offset = 0;
+
+   rc = build_and_send_cmd(TPM_ORD_SHA1Start,
+   NULL, 0,
+   (uint8_t *)&start, sizeof(start),
+   &returnCode, TPM_DURATION_TYPE_SHORT);
+
+   if (rc || returnCode)
+   goto err_exit;
+
+   while (blocks > 0) {
+
+   numbytes = be32_to_cpu(start.max_num_bytes);
+   if (numbytes > blocks * 64)
+numbytes = blocks * 64;
+
+   numbytes_no = cpu_to_be32(numbytes);
+
+   rc = build_and_send_cmd_od(TPM_ORD_SHA1Update,
+  (uint8_t *)&numbytes_no,
+  sizeof(numbytes_no),
+  NULL, 0, &returnCode,
+  &data[offset], numbytes,
+  TPM_DURATION_TYPE_SHORT);
+
+   if (rc || returnCode)
+   goto err_exit;
+
+   offset += numbytes;
+   blocks -= (numbytes / 64);
+   }
+
+   numbytes_no = cpu_to_be32(rest);
+
+   rc = build_and_send_cmd_od(TPM_ORD_SHA1Complete,
+ (uint8_t *)&numbytes_no, sizeof(numbytes_no),
+ (uint8_t *)&complete, sizeof(complete),
+ &returnCode,
+ &data[offset], rest,
+ TPM_DURATION_TYPE_SHORT);
+
+   if (rc || returnCode)
+   goto err_exit;
+
+   memcpy(hash, complete.hash, sizeof(complete.hash));
+
+   return 0;
+
+err_exit:
+   dprintf("TPM SHA1 malfunctioning.\n");
+
+   tpm_state.tpm_working = 0;
+   if (rc)
+   return rc;
+   return TCGBIOS_COMMAND_ERROR;
+}
+
+static uint32_t sha1_calc(const uint8_t *data, uint32_t length, uint8_t *hash)
+{
+   if (tpm_state.tpm_driver_to_use &&
+   length < tpm_state.tpm_driver_to_use->sha1threshold)
+   return tpm_sha1_calc(data, length, hash);
+
+   return sha1(data, length, hash);
+}
+
+/*
+ * Extend the ACPI log with the given entry by copying the
+ * entry data into the log.
+ *
+ * @pcpes: Pointer to the structure to be copied into the log
+ * @event: The event to be appended to 'pcpes'
+ * @event_length: The length of the event
+ *
+ * Output:
+ *  lower 16 bits of return code contain entry number
+ *  if entry number is '0', then upper 16 bits contain error code.
+ */
+static uint32_t tpm_extend_ofdt_log(struct pcpes *pcpes,
+   const char *event, uint32_t event_length)
+{
+   uint32_t size;
+   uint32_t log_area_size = get_log_area_size();
+   uint8_t *log_area_start_address = get_log_base_ptr();
+   uint8_t *log_area_address_next = get_log_area_address_next();
+
+   dprintf("LASA_BASE = %p, LASA_NEXT = %p\n",
+   log_area_start_address, log_area_address_next);

[PATCH 03/16] Add sha1 implementation

2015-08-07 Thread Stefan Berger
The following patch adds a SHA1 implementation based on the algorithm
description in NIST FIPS PUB 180-4.

Signed-off-by: Stefan Berger 
---
 lib/libtpm/Makefile |   2 +-
 lib/libtpm/sha1.c   | 197 
 lib/libtpm/sha1.h   |  20 ++
 3 files changed, 218 insertions(+), 1 deletion(-)
 create mode 100644 lib/libtpm/sha1.c
 create mode 100644 lib/libtpm/sha1.h

diff --git a/lib/libtpm/Makefile b/lib/libtpm/Makefile
index 53d3abb..f8ad468 100644
--- a/lib/libtpm/Makefile
+++ b/lib/libtpm/Makefile
@@ -24,7 +24,7 @@ TARGET = ../libtpm.a
 
 all: $(TARGET)
 
-SRCS = tpm_drivers.c tcgbios.c
+SRCS = tpm_drivers.c tcgbios.c sha1.c
 
 OBJS = $(SRCS:%.c=%.o)
 
diff --git a/lib/libtpm/sha1.c b/lib/libtpm/sha1.c
new file mode 100644
index 000..2454b8f
--- /dev/null
+++ b/lib/libtpm/sha1.c
@@ -0,0 +1,197 @@
+/*
+ * Copyright (c) 2015 IBM Corporation
+ * All rights reserved.
+ * This program and the accompanying materials
+ * are made available under the terms of the BSD License
+ * which accompanies this distribution, and is available at
+ * http://www.opensource.org/licenses/bsd-license.php
+ *
+ * Contributors:
+ * IBM Corporation - initial implementation
+ */
+
+/*
+ *  See: NIST standard for SHA-1 in FIPS PUB 180-4
+ */
+
+#include "byteorder.h"
+#include "sha1.h"
+#include "string.h"
+
+typedef struct _sha1_ctx {
+   uint32_t h[5];
+} sha1_ctx;
+
+static uint32_t rol(uint32_t data, uint8_t n)
+{
+   if (!n)
+   return data;
+   return (data << n) | (data >> (32 - n));
+}
+
+static void sha1_block(uint32_t *w, sha1_ctx *ctx)
+{
+   uint32_t i;
+   uint32_t a,b,c,d,e,f;
+   uint32_t tmp;
+   uint32_t idx;
+
+   /*
+* FIPS 180-4 4.2.1: SHA1 Constants
+*/
+   static const uint32_t sha_ko[4] = {
+   0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6
+   };
+
+   /*
+* FIPS 180-4 6.1.2: step 1
+*
+*  0 <= i <= 15:
+*W(t) = M(t)
+* 16 <= i <= 79:
+*W(t) = ROTL(W(t-3) XOR W(t-8) XOR W(t-14) XOR W(t-16), 1)
+*/
+
+   /* w(0)..(w15) already in big endian format */
+
+   for (i = 16; i <= 79; i++) {
+   tmp = w[i-3] ^ w[i-8] ^ w[i-14] ^ w[i-16];
+   w[i] = rol(tmp, 1);
+   }
+
+   /*
+* step 2: a = H0, b = H1, c = H2, d = H3, e = H4.
+*/
+   a = ctx->h[0];
+   b = ctx->h[1];
+   c = ctx->h[2];
+   d = ctx->h[3];
+   e = ctx->h[4];
+
+   /*
+* step 3: For i = 0 to 79:
+*T = ROTL(a, 5) + f(i; b,c,d) + e + W(t) + K(t);
+*/
+   for (i = 0; i <= 79; i++) {
+   /*
+* FIPS 180-4: 4.1.1 : definition of f(i; b,c,d)
+*/
+   if (i <= 19) {
+   /*
+*  0 <= i <= 19:
+*  f(i; b,c,d) = (b AND c) OR ((NOT b) AND d)
+*/
+   f = (b & c) | ((b ^ 0x) & d);
+   idx = 0;
+   } else if (i <= 39) {
+   /*
+*  20 <= i <= 39:
+*   f(i; b,c,d) = b XOR c XOR d
+*/
+   f = b ^ c ^ d;
+   idx = 1;
+   } else if (i <= 59) {
+   /*
+* 40 <= i <= 59:
+*  f(i; b,c,d) = (b AND c) OR (b AND d) OR (c AND 
d)
+*/
+   f = (b & c) | (b & d) | (c & d);
+   idx = 2;
+   } else {
+   /*
+* 60 <= i <= 79:
+*  f(i; b,c,d) = b XOR c XOR d
+*/
+   f = b ^ c ^ d;
+   idx = 3;
+   }
+
+   /*
+* step 3:
+*t = ROTL(a, 5) + f(t;b,c,d) + e + K(t) + W(t);
+*e = d;  d = c;  c = ROTL(b, 30);  b = a; a = t;
+*/
+   tmp = rol(a, 5) +
+ f +
+ e +
+ sha_ko[idx] +
+ w[i];
+   e = d;
+   d = c;
+   c = rol(b, 30);
+   b = a;
+   a = tmp;
+   }
+
+   /*
+* step 4:
+*H0 = a + H0, H1 = b + H1, H2 = c + H2, H3 = d + H3, H4 = e + H4
+*/
+   ctx->h[0] += a;
+   ctx->h[1] += b;
+   ctx->h[2] += c;
+   ctx->h[3] += d;
+   ctx->h[4] += e;
+}
+
+static void sha1_do(sha1_ctx *ctx, const uint8_t*data32, uint32_t length)
+{
+   uint32_t offset;
+   uint16_t num;
+   uint32_t bits = 0;
+   uint32_t

[PATCH 01/16] Add a TPM driver implementation

2015-08-07 Thread Stefan Berger
This patch adds a TPM driver for the CRQ interface as used by
the QEMU PAPR implementation.

Signed-off-by: Stefan Berger 
---
 include/helpers.h|   1 +
 lib/libtpm/Makefile  |  51 ++
 lib/libtpm/tpm_drivers.c | 456 +++
 lib/libtpm/tpm_drivers.h |  93 ++
 slof/helpers.c   |   6 +
 5 files changed, 607 insertions(+)
 create mode 100644 lib/libtpm/Makefile
 create mode 100644 lib/libtpm/tpm_drivers.c
 create mode 100644 lib/libtpm/tpm_drivers.h

diff --git a/include/helpers.h b/include/helpers.h
index fb10534..9e6bdf8 100644
--- a/include/helpers.h
+++ b/include/helpers.h
@@ -33,6 +33,7 @@ extern long SLOF_pci_config_read16(long offset);
 extern void SLOF_pci_config_write32(long offset, long value);
 extern void SLOF_pci_config_write16(long offset, long value);
 extern void *SLOF_translate_my_address(void *addr);
+extern unsigned long SLOF_get_vtpm_unit(void);
 
 #define offset_of(type, member) ((long) &((type *)0)->member)
 #define container_of(ptr, type, member) ({  \
diff --git a/lib/libtpm/Makefile b/lib/libtpm/Makefile
new file mode 100644
index 000..a174815
--- /dev/null
+++ b/lib/libtpm/Makefile
@@ -0,0 +1,51 @@
+# *
+# * Copyright (c) 2015 IBM Corporation
+# * All rights reserved.
+# * This program and the accompanying materials
+# * are made available under the terms of the BSD License
+# * which accompanies this distribution, and is available at
+# * http://www.opensource.org/licenses/bsd-license.php
+# *
+# * Contributors:
+# * IBM Corporation - initial implementation
+# /
+
+TOPCMNDIR ?= ../..
+
+ASFLAGS = $(FLAG) $(RELEASE) $(CPUARCHDEF) -Wa,-mregnames
+CPPFLAGS = -I../libc/include $(CPUARCHDEF) -I$(INCLBRDDIR) \
+  -I$(INCLCMNDIR) -I$(INCLCMNDIR)/$(CPUARCH) -I$(SLOFCMNDIR)
+CPPFLAGS += -I../libhvcall
+
+LDFLAGS = -nostdlib
+
+TARGET = ../libtpm.a
+
+
+all: $(TARGET)
+
+SRCS = tpm_drivers.c
+
+OBJS = $(SRCS:%.c=%.o)
+
+$(TARGET): $(OBJS)
+   $(AR) -rc $@ $(OBJS)
+   $(RANLIB) $@
+
+clean:
+   $(RM) $(TARGET) $(OBJS)
+
+distclean: clean
+   $(RM) Makefile.dep
+
+
+# Rules for creating the dependency file:
+depend:
+   $(RM) Makefile.dep
+   $(MAKE) Makefile.dep
+
+Makefile.dep: Makefile
+   $(CC) -M $(CPPFLAGS) $(CFLAGS) $(SRCS) $(SRCSS) > Makefile.dep
+
+# Include dependency file if available:
+-include Makefile.dep
diff --git a/lib/libtpm/tpm_drivers.c b/lib/libtpm/tpm_drivers.c
new file mode 100644
index 000..850da8c
--- /dev/null
+++ b/lib/libtpm/tpm_drivers.c
@@ -0,0 +1,456 @@
+/*
+ * Copyright (c) 2015 IBM Corporation
+ * All rights reserved.
+ * This program and the accompanying materials
+ * are made available under the terms of the BSD License
+ * which accompanies this distribution, and is available at
+ * http://www.opensource.org/licenses/bsd-license.php
+ *
+ * Contributors:
+ * IBM Corporation - initial implementation
+ */
+
+#include 
+#include 
+#include 
+
+#include "string.h"
+#include "helpers.h"
+#include "byteorder.h"
+#include "tpm_drivers.h"
+#include "tcgbios.h"
+#include "libhvcall.h"
+#include "paflof.h"
+
+#define PAPR_VTPM_DEBUG   0
+
+#define dprintf(_x ...) \
+   if (PAPR_VTPM_DEBUG) { \
+   printf("VTPM CRQ: " _x); \
+   }
+
+#define MIN(a, b) ((a) > (b) ? (b) : (a))
+
+#define TPM_DEFAULT_DURATION_SHORT (2000)
+#define TPM_DEFAULT_DURATION_MEDIUM(2)
+#define TPM_DEFAULT_DURATION_LONG  (6)
+
+struct crq {
+   uint8_t valid;
+   uint8_t msg;
+   uint16_t len;
+   uint32_t data;
+   uint64_t reserved;
+} __attribute__((packed));
+
+#define PAPR_VTPM_INIT_CRQ_COMMAND  0xC0
+#define PAPR_VTPM_VALID_COMMAND 0x80
+#define PAPR_VTPM_MSG_RESULT0x80
+
+/* msg types for valid = VALID_INIT_CRQ */
+#define PAPR_VTPM_INIT_CRQ_RESULT   0x1
+
+/* msg types for valid = IBMVTPM_VALID_CMD */
+#define PAPR_VTPM_GET_VERSION   0x1
+#define PAPR_VTPM_TPM_COMMAND   0x2
+#define PAPR_VTPM_GET_RTCE_BUFFER_SIZE  0x3
+
+static const uint32_t tpm_default_durations[TPM_NUM_DURATIONS] = {
+   TPM_DEFAULT_DURATION_SHORT,
+   TPM_DEFAULT_DURATION_MEDIUM,
+   TPM_DEFAULT_DURATION_LONG,
+};
+
+#define PAGE_SIZE 4096
+
+/* state of the PAPR CRQ VTPM driver */
+static struct spapr_vtpm_driver_state {
+/* durations of short, medium, & long commands */
+   uint32_t durations[TPM_NUM_DURATIONS];
+   unsigned long vtpm_unit;
+   unsigned char *qaddr;
+   unsigned long qsize;
+   /* current q_entry */
+   unsigned int q_entry;
+   /* current response CRQ */
+   struct crq *response;
+   pfw_drv_state drive

[PATCH 07/16] Perform some initial measurements

2015-08-07 Thread Stefan Berger
This patch puts an 'event' separator into the log that can
then be seen in Linux's /sys/kernel/security/tpm0/ascii_bios_measurements.
More low-level C functions are added for measuring and logging of disk
related data, along with their FORTH-level counterparts. These functions
will be called in subsequent patches.

Logging follows the specifications found on the following page:

http://www.trustedcomputinggroup.org/resources/pc_client_work_group_specific_implementation_specification_for_conventional_bios

Signed-off-by: Stefan Berger 
---
 board-qemu/slof/OF.fs |   1 +
 lib/libtpm/tcgbios.c  | 201 ++
 lib/libtpm/tcgbios.h  |   9 +++
 lib/libtpm/tpm.code   |  34 
 lib/libtpm/tpm.in |   3 +
 slof/fs/tpm/tpm-static.fs |  11 +++
 6 files changed, 259 insertions(+)

diff --git a/board-qemu/slof/OF.fs b/board-qemu/slof/OF.fs
index bd9495e..1306371 100644
--- a/board-qemu/slof/OF.fs
+++ b/board-qemu/slof/OF.fs
@@ -304,6 +304,7 @@ cr
 #include "copyright-oss.fs"
 cr cr
 
+vtpm-add-event-separators
 vtpm-unassert-pp
 
 \ this CATCH is to ensure the code bellow always executes:  boot may ABORT!
diff --git a/lib/libtpm/tcgbios.c b/lib/libtpm/tcgbios.c
index e86cfc2..2f5b048 100644
--- a/lib/libtpm/tcgbios.c
+++ b/lib/libtpm/tcgbios.c
@@ -66,6 +66,8 @@ static const uint8_t GetCapability_Durations[] = {
0x00, 0x00, 0x01, 0x20
 };
 
+static uint8_t evt_separator[] = {0xff,0xff,0xff,0xff};
+
 struct tpm_state {
uint8_t   tpm_probed:1;
uint8_t   tpm_found:1;
@@ -690,3 +692,202 @@ static uint32_t hash_log_extend_event(const void 
*hashdata,
 
return tpm_extend(pcpes->digest, pcrindex);
 }
+
+/*
+ * Add a measurement to the log;
+ *
+ * Input parameters:
+ *  @pcrindex : PCR to extend
+ *  @event_type : type of event
+ *  @info : pointer to info (i.e., string) to be added to the log as-is
+ *  @info_length: length of the info
+ *  @data : pointer to data to be hashed
+ *  @data_length: length of the data
+ *
+ */
+static uint32_t tpm_add_measurement_to_log(uint32_t pcrindex,
+  uint32_t eventtype,
+  const char *info,
+  uint32_t infolen,
+  const uint8_t *data,
+  uint32_t datalen)
+{
+   struct pcpes pcpes;
+
+   pcpes.pcrindex  = pcrindex;
+   pcpes.eventtype = eventtype;
+   memset(&pcpes.digest, 0, sizeof(pcpes.digest));
+
+   return hash_log_extend_event(data, datalen, &pcpes,
+info, infolen, pcrindex);
+}
+
+/*
+ * Add a measurement to the list of measurements
+ * pcrindex   : PCR to be extended
+ * event_type : type of event
+ * string : string describing the event; used if event_type is EV_ACTION
+ */
+static uint32_t tpm_add_measurement(uint32_t pcrindex,
+   uint16_t event_type,
+   const char *string)
+{
+   uint32_t rc;
+   uint32_t len;
+
+   switch (event_type) {
+   case EV_SEPARATOR:
+   len = sizeof(evt_separator);
+   rc = tpm_add_measurement_to_log(pcrindex, event_type,
+   NULL, 0,
+   (uint8_t *)evt_separator, len);
+   break;
+
+   case EV_ACTION:
+   rc = tpm_add_measurement_to_log(pcrindex, event_type,
+   string, strlen(string),
+   (uint8_t *)string, strlen(string));
+   break;
+
+   default:
+   rc = TCGBIOS_INVALID_INPUT_PARA;
+   }
+
+   return rc;
+}
+
+/*
+ * Add event separators for PCRs 0 to 7
+ */
+uint32_t tpm_add_event_separators(void)
+{
+   uint32_t rc;
+   uint32_t pcrindex = 0;
+
+   if (!has_working_tpm())
+   return TCGBIOS_GENERAL_ERROR;
+
+   while (pcrindex <= 7) {
+   rc = tpm_add_measurement(pcrindex, EV_SEPARATOR, NULL);
+   if (rc)
+   break;
+   pcrindex ++;
+   }
+
+   return rc;
+}
+
+/*
+ * Add a measurement regarding the boot device (CDRom, Floppy, HDD) to
+ * the list of measurements.
+ */
+static uint32_t tpm_add_bootdevice(uint32_t bootcd, uint32_t bootdrv)
+{
+   const char *string;
+
+   dprintf("add bootdevice: bootcd = %d, bootdrv = 0x%x\n", bootcd, 
bootdrv);
+
+   if (!has_working_tpm())
+   return TCGBIOS_GENERAL_ERROR;
+
+   switch (bootcd) {
+   case 0:
+   switch (bootdrv) {
+   case 0:
+   string = "Booting BCV device 00h (Floppy)";
+   break;
+
+   case 0x80:
+   string = "Booting BCV device 80h (HDD)";
+   break;
+
+   default:
+   string = "Booting unknown device";
+

[PATCH 11/16] Measure the static core root of trust for measurements

2015-08-07 Thread Stefan Berger
This patch adds support for measuring the static core root of trust
(S-CRTM) and logging the measurements.

Signed-off-by: Stefan Berger 
---
 board-qemu/slof/vio-vtpm-cdriver.fs |  2 ++
 lib/libtpm/tcgbios.c| 37 +
 lib/libtpm/tcgbios.h|  1 +
 lib/libtpm/tcgbios_int.h|  2 ++
 lib/libtpm/tpm.code | 10 ++
 lib/libtpm/tpm.in   |  1 +
 slof/fs/tpm/tpm-static.fs   | 11 +++
 7 files changed, 64 insertions(+)

diff --git a/board-qemu/slof/vio-vtpm-cdriver.fs 
b/board-qemu/slof/vio-vtpm-cdriver.fs
index 2fc1657..0b4ba41 100644
--- a/board-qemu/slof/vio-vtpm-cdriver.fs
+++ b/board-qemu/slof/vio-vtpm-cdriver.fs
@@ -72,3 +72,5 @@ vtpm-init
 
 \ setup the log
 include vtpm-sml.fs
+
+vtpm-measure-scrtm
diff --git a/lib/libtpm/tcgbios.c b/lib/libtpm/tcgbios.c
index 40557d6..adec313 100644
--- a/lib/libtpm/tcgbios.c
+++ b/lib/libtpm/tcgbios.c
@@ -1383,3 +1383,40 @@ bool tpm_is_working(void)
 {
return has_working_tpm();
 }
+
+uint32_t tpm_measure_scrtm(void)
+{
+   uint32_t rc;
+
+   extern long print_version, print_version_end;
+   extern long _slof_data, _slof_data_end;
+
+   char *version_start = (char *)&print_version;
+   uint32_t version_length = (long)&print_version_end - 
(long)&print_version;
+
+   char *slof_start = (char *)&_slof_data;
+   uint32_t slof_length = (long)&_slof_data_end - (long)&_slof_data;
+
+   const char *scrtm = "S-CRTM Contents";
+
+   dprintf("Measure S-CRTM Version: addr = %p, length = %d\n",
+   version_start, version_length);
+
+   rc = tpm_add_measurement_to_log(
+   0, EV_S_CRTM_VERSION,
+   version_start, version_length,
+   (uint8_t *)version_start, version_length);
+
+   if (rc)
+   return rc;
+
+   dprintf("Measure S-CRTM Content: start = %p, length = %d\n",
+   &slof_start, slof_length);
+
+   rc = tpm_add_measurement_to_log(
+   0, EV_S_CRTM_CONTENTS,
+   scrtm, strlen(scrtm),
+   (uint8_t *)slof_start, slof_length);
+
+   return rc;
+}
diff --git a/lib/libtpm/tcgbios.h b/lib/libtpm/tcgbios.h
index 902ea1f..9f07caf 100644
--- a/lib/libtpm/tcgbios.h
+++ b/lib/libtpm/tcgbios.h
@@ -24,6 +24,7 @@ enum ipltype {
 
 uint32_t tpm_start(void);
 uint32_t tpm_unassert_pp(void);
+uint32_t tpm_measure_scrtm(void);
 void tpm_set_log_parameters(void *address, unsigned int size);
 uint32_t tpm_get_logsize(void);
 uint32_t tpm_ipl(enum ipltype bootcd, const uint8_t *addr, uint32_t length);
diff --git a/lib/libtpm/tcgbios_int.h b/lib/libtpm/tcgbios_int.h
index 420049f..bedc2f1 100644
--- a/lib/libtpm/tcgbios_int.h
+++ b/lib/libtpm/tcgbios_int.h
@@ -57,6 +57,8 @@
 #define EV_SEPARATOR 4
 #define EV_ACTION5
 #define EV_EVENT_TAG 6
+#define EV_S_CRTM_CONTENTS   7
+#define EV_S_CRTM_VERSION8
 #define EV_COMPACT_HASH 12
 #define EV_IPL  13
 #define EV_IPL_PARTITION_DATA   14
diff --git a/lib/libtpm/tpm.code b/lib/libtpm/tpm.code
index 66250d5..34b9cbc 100644
--- a/lib/libtpm/tpm.code
+++ b/lib/libtpm/tpm.code
@@ -122,3 +122,13 @@ PRIM(tpm_X2d_is_X2d_working)
PUSH;
TOS.n = tpm_is_working();
 MIRP
+
+//
+/* Have the S-CRTM measured */
+/* SLOF:   tpm-measure-scrtm  ( -- errcode )*/
+/* LIBTPM: errcode = tpm_measure_scrtm  */
+//
+PRIM(tpm_X2d_measure_X2d_scrtm)
+   PUSH;
+   TOS.n = tpm_measure_scrtm();
+MIRP
diff --git a/lib/libtpm/tpm.in b/lib/libtpm/tpm.in
index f2cc81e..48c0d75 100644
--- a/lib/libtpm/tpm.in
+++ b/lib/libtpm/tpm.in
@@ -23,3 +23,4 @@ cod(tpm-add-bcv)
 cod(tpm-process-opcode)
 cod(tpm-get-state)
 cod(tpm-is-working)
+cod(tpm-measure-scrtm)
diff --git a/slof/fs/tpm/tpm-static.fs b/slof/fs/tpm/tpm-static.fs
index bc5138a..1bc37c9 100644
--- a/slof/fs/tpm/tpm-static.fs
+++ b/slof/fs/tpm/tpm-static.fs
@@ -33,6 +33,17 @@ false VALUE vtpm-debug?
 THEN
 ;
 
+: vtpm-measure-scrtm
+vtpm-available? IF
+tpm-measure-scrtm ( -- errcode )
+vtpm-debug? IF
+." VTPM: Error code from tpm-measure-scrtm: " . cr
+ELSE
+drop
+THEN
+THEN
+;
+
 : vtpm-unassert-pp
 vtpm-available? IF
 tpm-unassert-pp( -- errcode )
-- 
1.9.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 12/16] Add TPM firmware API calls hash-all, log-event, hash-log-extend-event

2015-08-07 Thread Stefan Berger
Add the TPM firmware API calls hash-all, log-event, and hash-log-extend-event.
These firmware calls are implemented in /vdevice/vtpm and /ibm,vtpm but the
former merely forwards the calls to the latter. The implementation follows
the Virtual TPM firmware documentation.

These particular 3 API calls enable trusted grub extensions.

Signed-off-by: Stefan Berger 
---
 board-qemu/slof/vio-vtpm-cdriver.fs | 37 +
 board-qemu/slof/vtpm-sml.fs | 22 
 lib/libtpm/tcgbios.c| 41 +
 lib/libtpm/tcgbios.h|  5 +
 lib/libtpm/tpm.code | 32 +
 lib/libtpm/tpm.in   |  3 +++
 slof/fs/tpm/tpm-static.fs   | 40 
 7 files changed, 180 insertions(+)

diff --git a/board-qemu/slof/vio-vtpm-cdriver.fs 
b/board-qemu/slof/vio-vtpm-cdriver.fs
index 0b4ba41..44e5aec 100644
--- a/board-qemu/slof/vio-vtpm-cdriver.fs
+++ b/board-qemu/slof/vio-vtpm-cdriver.fs
@@ -58,6 +58,43 @@ false VALUE vtpm-debug?
 r> to my-self
 ;
 
+\ forward a call to /ibm,vtpm, which implements the function with the
+\ given name
+: call-forward ( arg ... arg name namelen -- failure? ret ... ret )
+s" /ibm,vtpm" open-dev ?dup IF
+dup >r ( arg ... arg name namelen ihandle 
r:ihandle -- )
+$call-method   ( r:ihandle -- ret ... ret )
+r> close-dev   ( -- ret ... ret )
+false  ( -- false ret ... ret )
+ELSE
+true   ( -- true )
+THEN
+;
+
+\ firmware API call
+: hash-all ( data-ptr data-len hash-ptr -- )
+" hash-all" call-forward IF
+\ call-forward failed; clean up stack
+3drop
+THEN
+;
+
+\ firmware API call
+: log-event ( event-ptr -- success? )
+" log-event" call-forward IF
+drop
+false
+THEN
+;
+
+\ firmware API call
+: hash-log-extend-event ( event-ptr -- rc )
+" hash-log-extend-event" call-forward IF
+drop
+9 \ TPM_FAIL
+THEN
+;
+
 : open ( )
 vtpm-debug? IF ." VTPM: vTPM open()" cr THEN
 true
diff --git a/board-qemu/slof/vtpm-sml.fs b/board-qemu/slof/vtpm-sml.fs
index 28c30f1..8783bf1 100644
--- a/board-qemu/slof/vtpm-sml.fs
+++ b/board-qemu/slof/vtpm-sml.fs
@@ -52,6 +52,28 @@ log-base LOG-SIZE tpm-set-log-parameters
 move
 ;
 
+: hash-all ( data-ptr data-len hash-ptr -- )
+vtpm-debug? IF
+." Call to hash-all" cr
+THEN
+vtpm-hash-all
+;
+
+: log-event ( event-ptr -- ok? )
+vtpm-debug? IF
+." Call to log-event" cr
+THEN
+vtpm-log-event
+;
+
+: hash-log-extend-event ( event-ptr -- rc )
+vtpm-debug? IF
+." Call to hash-log-extend-event" cr
+THEN
+vtpm-hash-log-extend-event
+;
+
+
 : open  true ;
 : close ;
 
diff --git a/lib/libtpm/tcgbios.c b/lib/libtpm/tcgbios.c
index adec313..621c3e8 100644
--- a/lib/libtpm/tcgbios.c
+++ b/lib/libtpm/tcgbios.c
@@ -563,6 +563,20 @@ static uint32_t tpm_extend_ofdt_log(struct pcpes *pcpes,
return 0;
 }
 
+/*
+ * tpm_log_event: Function for interfacing with the firmware API
+ */
+bool tpm_log_event(struct pcpes *pcpes)
+{
+   const char *event = NULL;
+   uint32_t event_length = pcpes->eventdatasize;
+
+   if (event_length)
+   event = (void *)pcpes + offset_of(struct pcpes, event);
+
+   return (tpm_extend_ofdt_log(pcpes, event, event_length) == 0);
+}
+
 static uint32_t is_preboot_if_shutdown(void)
 {
return tpm_state.if_shutdown;
@@ -656,6 +670,14 @@ static uint32_t tpm_extend(uint8_t *hash, uint32_t 
pcrindex)
 }
 
 /*
+ * tpm_hash_all: Function for interfacing with the firmware API
+ */
+uint32_t tpm_hash_all(const void *data, uint32_t datalen, void *hashptr)
+{
+   return sha1(data, datalen, hashptr);
+}
+
+/*
  * Hash then given input data and append the hash to the log
  *
  * @hashdata: the data to hash
@@ -766,6 +788,25 @@ static uint32_t tpm_add_measurement(uint32_t pcrindex,
 }
 
 /*
+ * tpm_hash_log_extend_event: Function for interfacing with then firmware API
+ */
+uint32_t tpm_hash_log_extend_event(struct pcpes *pcpes)
+{
+   const char *event = NULL;
+   uint32_t event_length = pcpes->eventdatasize;
+
+   if (!has_working_tpm())
+   return TCGBIOS_GENERAL_ERROR;
+
+   if (event_length)
+   event = (void *)pcpes + offset_of(struct pcpes, event);
+
+   return hash_log_extend_event(&pcpes->event, pcpes->eventdatasize,
+pcpes, event, event_length,
+pcpes->pcrindex);
+}
+
+/*
  * Add event separators for PCRs 0 to 7
  */
 uint32_t tpm_add_event_separators(void)
diff --git a/lib/libtpm/tcgbios.h b/lib/libtpm/tcgbios.h
index 9f07caf..0dacba2 100644
--- a/lib/libtpm/tcgbios.h
+++ b/lib/libtpm/tcgbios.h
@@ -22,6 +22,8 @@ enum ipltype {

[PATCH 06/16] Return value of actual log in sml-get-handover-size

2015-08-07 Thread Stefan Berger
With the functions for calculating the actual size of the log in place,
use them to determine the exact size of the log that the firmware
API call sml-get-handover-size now returns.

Signed-off-by: Stefan Berger 
---
 board-qemu/slof/vtpm-sml.fs |  4 ++--
 lib/libtpm/tcgbios.c| 15 +++
 lib/libtpm/tcgbios.h|  1 +
 lib/libtpm/tpm.code | 10 ++
 lib/libtpm/tpm.in   |  1 +
 5 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/board-qemu/slof/vtpm-sml.fs b/board-qemu/slof/vtpm-sml.fs
index 741a953..28c30f1 100644
--- a/board-qemu/slof/vtpm-sml.fs
+++ b/board-qemu/slof/vtpm-sml.fs
@@ -37,9 +37,9 @@ log-base LOG-SIZE tpm-set-log-parameters
 
 : sml-get-handover-size ( -- size )
 vtpm-debug? IF
-." Call to sml-get-handover-size; size = " LOG-SIZE . cr
+." Call to sml-get-handover-size; size = " tpm-get-logsize . cr
 THEN
-LOG-SIZE
+tpm-get-logsize
 ;
 
 : sml-handover ( dest size -- )
diff --git a/lib/libtpm/tcgbios.c b/lib/libtpm/tcgbios.c
index 072ed4d..e86cfc2 100644
--- a/lib/libtpm/tcgbios.c
+++ b/lib/libtpm/tcgbios.c
@@ -416,6 +416,21 @@ static void *get_log_area_address_next(void)
return log_area_address_next;
 }
 
+uint32_t tpm_get_logsize(void)
+{
+   uint8_t *log_area_start_address = get_log_base_ptr();
+   uint8_t *log_area_address_next = get_log_area_address_next();
+   uint32_t logsize;
+
+   if (log_area_address_next) {
+   logsize = log_area_address_next - log_area_start_address;
+   dprintf("log size: %u\n", logsize);
+   return logsize;
+   }
+
+   return 0;
+}
+
 static uint32_t tpm_sha1_calc(const uint8_t *data, uint32_t length,
  uint8_t *hash)
 {
diff --git a/lib/libtpm/tcgbios.h b/lib/libtpm/tcgbios.h
index 9b51826..b217dd1 100644
--- a/lib/libtpm/tcgbios.h
+++ b/lib/libtpm/tcgbios.h
@@ -18,5 +18,6 @@
 uint32_t tpm_start(void);
 uint32_t tpm_unassert_pp(void);
 void tpm_set_log_parameters(void *address, unsigned int size);
+uint32_t tpm_get_logsize(void);
 
 #endif /* TCGBIOS_H */
diff --git a/lib/libtpm/tpm.code b/lib/libtpm/tpm.code
index a6b66a8..b868ca3 100644
--- a/lib/libtpm/tpm.code
+++ b/lib/libtpm/tpm.code
@@ -46,3 +46,13 @@ PRIM(tpm_X2d_set_X2d_log_X2d_parameters)
void *addr = TOS.a; POP;
tpm_set_log_parameters(addr, size);
 MIRP
+
+//
+/* Get the size of the log  */
+/* SLOF:   tpm-get-logsize ( -- size )  */
+/* LIBTPM: logsize = tpm_get_logsize(void)  */
+//
+PRIM(tpm_X2d_get_X2d_logsize)
+   PUSH;
+   TOS.n = tpm_get_logsize();
+MIRP
diff --git a/lib/libtpm/tpm.in b/lib/libtpm/tpm.in
index a2f7cb9..32d675f 100644
--- a/lib/libtpm/tpm.in
+++ b/lib/libtpm/tpm.in
@@ -16,3 +16,4 @@
 cod(tpm-start)
 cod(tpm-unassert-pp)
 cod(tpm-set-log-parameters)
+cod(tpm-get-logsize)
-- 
1.9.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 09/16] Add support for a TPM menu to control the state of the TPM

2015-08-07 Thread Stefan Berger
This patch provides an addtional menu that enables the user to control
certain aspects of the TPM's state.

If a working TPM has been detected, the menu will look like this:

The TPM is enabled, active, does not have an owner but one can be installed.

To configure the TPM, choose one of the following actions:

d. Disable the TPM
v. Deactivate the TPM
p. Prevent installation of an owner


Note: To fully use the TPM it must be enabled and activated.

Press escape to continue boot.


This menu can be access by pressing the 't' key during boot. The menu will not
be shown if no TPM is available.

Signed-off-by: Stefan Berger 
---
 board-qemu/slof/OF.fs |   2 +-
 lib/libtpm/tcgbios.c  |  33 
 lib/libtpm/tcgbios.h  |   9 +++
 lib/libtpm/tpm.code   |  20 +
 lib/libtpm/tpm.in |   2 +
 slof/fs/start-up.fs   |   9 +++
 slof/fs/tpm/tpm-static.fs | 193 ++
 7 files changed, 267 insertions(+), 1 deletion(-)

diff --git a/board-qemu/slof/OF.fs b/board-qemu/slof/OF.fs
index 1306371..cb63455 100644
--- a/board-qemu/slof/OF.fs
+++ b/board-qemu/slof/OF.fs
@@ -180,6 +180,7 @@ CREATE version-str 10 ALLOT
 version-str 8 + @   \ end
 over - terminal-write drop
 " Press 's' to enter Open Firmware." terminal-write drop
+vtpm-available? IF "  Press 't' to enter TPM menu." terminal-write drop 
THEN
 cr cr
 temp-ptr disp-size > IF
temp-ptr disp-size MOD
@@ -305,7 +306,6 @@ cr
 cr cr
 
 vtpm-add-event-separators
-vtpm-unassert-pp
 
 \ this CATCH is to ensure the code bellow always executes:  boot may ABORT!
 ' start-it CATCH drop
diff --git a/lib/libtpm/tcgbios.c b/lib/libtpm/tcgbios.c
index cabd980..40557d6 100644
--- a/lib/libtpm/tcgbios.c
+++ b/lib/libtpm/tcgbios.c
@@ -1350,3 +1350,36 @@ uint32_t tpm_process_opcode(uint8_t op, bool verbose)
 
return tpm_process_cfg(&cfg, verbose, &returnCode);
 }
+
+int tpm_get_state(void)
+{
+   int state = 0;
+   struct tpm_permanent_flags pf;
+   bool has_owner;
+
+   if (read_permanent_flags((char *)&pf, sizeof(pf)) ||
+   read_has_owner(&has_owner))
+   return ~0;
+
+   if (!pf.flags[PERM_FLAG_IDX_DISABLE])
+   state |= TPM_STATE_ENABLED; /* enabled */
+
+   if (!pf.flags[PERM_FLAG_IDX_DEACTIVATED])
+   state |= TPM_STATE_ACTIVE; /* active */
+
+   if (has_owner) {
+   state |= TPM_STATE_OWNED; /* has owner */
+   } else {
+   if (pf.flags[PERM_FLAG_IDX_OWNERSHIP])
+   state |= TPM_STATE_OWNERINSTALL; /* owner can be 
installed */
+   }
+
+   dprintf("TPM state flags = 0x%x\n", state);
+
+   return state;
+}
+
+bool tpm_is_working(void)
+{
+   return has_working_tpm();
+}
diff --git a/lib/libtpm/tcgbios.h b/lib/libtpm/tcgbios.h
index e0a7045..902ea1f 100644
--- a/lib/libtpm/tcgbios.h
+++ b/lib/libtpm/tcgbios.h
@@ -31,4 +31,13 @@ uint32_t tpm_add_bcv(uint32_t bootdrv, const uint8_t *addr, 
uint32_t length);
 uint32_t tpm_add_event_separators(void);
 uint32_t tpm_process_opcode(uint8_t op, bool verbose);
 
+/* flags returned by tpm_get_state */
+#define TPM_STATE_ENABLED1
+#define TPM_STATE_ACTIVE 2
+#define TPM_STATE_OWNED  4
+#define TPM_STATE_OWNERINSTALL   8
+
+int tpm_get_state(void);
+bool tpm_is_working(void);
+
 #endif /* TCGBIOS_H */
diff --git a/lib/libtpm/tpm.code b/lib/libtpm/tpm.code
index 7728317..66250d5 100644
--- a/lib/libtpm/tpm.code
+++ b/lib/libtpm/tpm.code
@@ -102,3 +102,23 @@ PRIM(tpm_X2d_process_X2d_opcode)
bool verbose = TOS.u;
TOS.n = tpm_process_opcode(opcode, verbose);
 MIRP
+
+//
+/* Get state of the TPM in form of flags*/
+/* SLOF:   tpm-get-state  ( -- flags )  */
+/* LIBTPM: state = tpm_get_state()  */
+//
+PRIM(tpm_X2d_get_X2d_state)
+   PUSH;
+   TOS.n = tpm_get_state();
+MIRP
+
+//
+/* Check whether the TPM is working */
+/* SLOF:   tpm-is-working  ( -- true | false )  */
+/* LIBTPM: bool = tpm_is_working()  */
+//
+PRIM(tpm_X2d_is_X2d_working)
+   PUSH;
+   TOS.n = tpm_is_working();
+MIRP
diff --git a/lib/libtpm/tpm.in b/lib/libtpm/tpm.in
index e5dbc25..f2cc81e 100644
--- a/lib/libtpm/tpm.in
+++ b/lib/libtpm/tpm.in
@@ -21,3 +21,5 @@ cod(tpm-add-event-separators)
 cod(tpm-ipl)
 cod(tpm-add-bcv)
 cod(tpm-process-opcode)
+cod(tpm-get-state)
+cod(tpm-is-working)
diff --git a/slof/fs/start-up.fs b/slof/fs/start-up.fs
index f1488fa..015e6c1 100644
--- a/slof/fs/start-up.fs
+++ b/slof/fs/start-up.fs
@@ -55,7 +55,15 @@
nvramlog-write-string-cr
 ;
 
+: (t-pressed) ( -- )
+   vtpm-menu
+;
+
 : (boot?) ( -- )
+   \ before we boot (and after the TPM menu) make sure we give up
+   \ physical presence on the T

[PATCH 04/16] Add initial support for logging

2015-08-07 Thread Stefan Berger
This patch adds initial support for the logging that will be done
following measurements done by further code added to SLOF.

Signed-off-by: Stefan Berger 
Reviewed-by: Nikunj A Dadhania 
---
 board-qemu/slof/vtpm-sml.fs |  3 +++
 lib/libtpm/tcgbios.c| 30 ++
 lib/libtpm/tcgbios.h|  1 +
 lib/libtpm/tpm.code | 11 +++
 lib/libtpm/tpm.in   |  1 +
 5 files changed, 46 insertions(+)

diff --git a/board-qemu/slof/vtpm-sml.fs b/board-qemu/slof/vtpm-sml.fs
index 72edac0..741a953 100644
--- a/board-qemu/slof/vtpm-sml.fs
+++ b/board-qemu/slof/vtpm-sml.fs
@@ -25,6 +25,9 @@ LOG-SIZE alloc-mem to log-base
 \ create /ibm,vtpm
 s" ibm,vtpm" 2dup device-name device-type
 
+\ convey logbase and size to the C driver
+log-base LOG-SIZE tpm-set-log-parameters
+
 : sml-get-allocated-size ( -- buffer-size)
 vtpm-debug? IF
 ." Call to sml-get-allocated-size; size = " LOG-SIZE . cr
diff --git a/lib/libtpm/tcgbios.c b/lib/libtpm/tcgbios.c
index efa4cdf..afbaede 100644
--- a/lib/libtpm/tcgbios.c
+++ b/lib/libtpm/tcgbios.c
@@ -77,10 +77,40 @@ static struct tpm_state tpm_state = {
 
 extern struct tpm_driver tpm_drivers[];
 
+static void *log_base;
+static uint32_t log_area_size;
+
 /
   Extensions for TCG-enabled BIOS
  ***/
 
+void tpm_set_log_parameters(void *addr, unsigned int size)
+{
+   dprintf("Log is at 0x%llx; size is %u bytes\n",
+   (uint64_t)addr, size);
+   log_base = addr;
+   log_area_size = size;
+}
+
+static uint8_t *get_log_base_ptr(void)
+{
+   return log_base;
+}
+
+static uint32_t get_log_area_size(void)
+{
+   return log_area_size;
+}
+
+/* clear the OpenFirmware device tree log */
+static void reset_ofdt_log(void)
+{
+   uint8_t *log_area_start_address = get_log_base_ptr();
+
+   if (log_area_start_address)
+   memset(log_area_start_address, 0, get_log_area_size());
+}
+
 static bool is_tpm_present(void)
 {
bool rc = false;
diff --git a/lib/libtpm/tcgbios.h b/lib/libtpm/tcgbios.h
index c4c462e..9b51826 100644
--- a/lib/libtpm/tcgbios.h
+++ b/lib/libtpm/tcgbios.h
@@ -17,5 +17,6 @@
 
 uint32_t tpm_start(void);
 uint32_t tpm_unassert_pp(void);
+void tpm_set_log_parameters(void *address, unsigned int size);
 
 #endif /* TCGBIOS_H */
diff --git a/lib/libtpm/tpm.code b/lib/libtpm/tpm.code
index 567b384..a6b66a8 100644
--- a/lib/libtpm/tpm.code
+++ b/lib/libtpm/tpm.code
@@ -35,3 +35,14 @@ PRIM(tpm_X2d_unassert_X2d_pp)
PUSH;
TOS.n = tpm_unassert_pp();
 MIRP
+
+/*/
+/* Convey log address and size   */
+/* SLOF:   tpm-set-log-parameters  ( addr size -- )  */
+/* LIBTPM: tpm_set_log_parameters(void *addr, uint64_t size) */
+/*/
+PRIM(tpm_X2d_set_X2d_log_X2d_parameters)
+   int size = TOS.u; POP;
+   void *addr = TOS.a; POP;
+   tpm_set_log_parameters(addr, size);
+MIRP
diff --git a/lib/libtpm/tpm.in b/lib/libtpm/tpm.in
index 266439e..a2f7cb9 100644
--- a/lib/libtpm/tpm.in
+++ b/lib/libtpm/tpm.in
@@ -15,3 +15,4 @@
 
 cod(tpm-start)
 cod(tpm-unassert-pp)
+cod(tpm-set-log-parameters)
-- 
1.9.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 08/16] Add support for controlling the states of the TPM

2015-08-07 Thread Stefan Berger
This patch adds support for controlling the various states of
the TPM, such as enabling and disabling the TPM, deactivating
and activating it, and clearing ownership.

The TPM menu implementation will call these functions by
calling tpm_process_opcode with an opcode indicating as to
how the state of the TPM is to be changed.

Signed-off-by: Stefan Berger 
---
 lib/libtpm/tcgbios.c | 459 +++
 lib/libtpm/tcgbios.h |   2 +
 lib/libtpm/tcgbios_int.h |  34 
 lib/libtpm/tpm.code  |  12 ++
 lib/libtpm/tpm.in|   1 +
 5 files changed, 508 insertions(+)

diff --git a/lib/libtpm/tcgbios.c b/lib/libtpm/tcgbios.c
index 2f5b048..cabd980 100644
--- a/lib/libtpm/tcgbios.c
+++ b/lib/libtpm/tcgbios.c
@@ -51,6 +51,11 @@ static const uint8_t GetCapability_Permanent_Flags[] = {
0x00, 0x00, 0x01, 0x08
 };
 
+static const uint8_t GetCapability_STClear_Flags[] = {
+   0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04,
+   0x00, 0x00, 0x01, 0x09
+};
+
 static const uint8_t GetCapability_OwnerAuth[] = {
0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x04,
0x00, 0x00, 0x01, 0x11
@@ -82,6 +87,10 @@ static struct tpm_state tpm_state = {
 
 extern struct tpm_driver tpm_drivers[];
 
+typedef struct {
+   uint8_t  op;
+} tpm_bios_cfg;
+
 static void *log_base;
 static uint32_t log_area_size;
 /* next log entry goes here */
@@ -891,3 +900,453 @@ uint32_t tpm_add_bcv(uint32_t bootdrv, const uint8_t 
*addr, uint32_t length)
 
return tpm_ipl(IPL_BCV, addr, length);
 }
+
+static uint32_t read_stclear_flags(char *buf, int buf_len)
+{
+   uint32_t rc;
+   uint32_t returnCode;
+   struct tpm_res_getcap_stclear_flags stcf;
+
+   memset(buf, 0, buf_len);
+
+   rc = build_and_send_cmd(TPM_ORD_GetCapability,
+   GetCapability_STClear_Flags,
+   sizeof(GetCapability_STClear_Flags),
+   (uint8_t *)&stcf, sizeof(stcf),
+   &returnCode, TPM_DURATION_TYPE_SHORT);
+
+   dprintf("Return code from TPM_GetCapability() = 0x%08x\n",
+   returnCode);
+
+   if (rc || returnCode)
+   goto err_exit;
+
+   memcpy(buf, &stcf.stclear_flags, buf_len);
+
+   return 0;
+
+err_exit:
+   dprintf("TPM malfunctioning (line %d).\n", __LINE__);
+
+   tpm_state.tpm_working = 0;
+   if (rc)
+   return rc;
+   return TCGBIOS_COMMAND_ERROR;
+}
+
+static uint32_t assert_physical_presence(bool verbose)
+{
+   uint32_t rc = 0;
+   uint32_t returnCode;
+   struct tpm_stclear_flags stcf;
+
+   rc = read_stclear_flags((char *)&stcf, sizeof(stcf));
+   if (rc) {
+   dprintf("Error reading STClear flags: 0x%08x\n", rc);
+   return rc;
+   }
+
+   if (stcf.flags[STCLEAR_FLAG_IDX_PHYSICAL_PRESENCE])
+   /* physical presence already asserted */
+   return 0;
+
+   rc = build_and_send_cmd(TPM_ORD_PhysicalPresence,
+   PhysicalPresence_CMD_ENABLE,
+   sizeof(PhysicalPresence_CMD_ENABLE),
+   NULL, 0, &returnCode,
+   TPM_DURATION_TYPE_SHORT);
+
+   dprintf("Return code from TSC_PhysicalPresence(CMD_ENABLE) = 0x%08x\n",
+   returnCode);
+
+   if (rc || returnCode) {
+   if (verbose)
+   printf("Error: Could not enable physical 
presence.\n\n");
+   goto err_exit;
+   }
+
+   rc = build_and_send_cmd(TPM_ORD_PhysicalPresence,
+   PhysicalPresence_PRESENT,
+   sizeof(PhysicalPresence_PRESENT),
+   NULL, 0, &returnCode,
+   TPM_DURATION_TYPE_SHORT);
+
+   dprintf("Return code from TSC_PhysicalPresence(PRESENT) = 0x%08x\n",
+   returnCode);
+
+   if (rc || returnCode) {
+   if (verbose)
+   printf("Error: Could not set presence flag.\n\n");
+   goto err_exit;
+   }
+
+   return 0;
+
+err_exit:
+   dprintf("TPM malfunctioning (line %d).\n", __LINE__);
+
+   tpm_state.tpm_working = 0;
+   if (rc)
+   return rc;
+   return TCGBIOS_COMMAND_ERROR;
+}
+
+static uint32_t read_permanent_flags(char *buf, int buf_len)
+{
+   uint32_t rc;
+   uint32_t returnCode;
+   struct tpm_res_getcap_perm_flags pf;
+
+   memset(buf, 0, buf_len);
+
+   rc = build_and_send_cmd(TPM_ORD_GetCapability,
+   GetCapability_Permanent_Flags,
+   sizeof(GetCapability_Permanent_Flags),
+   (uint8_t *)&pf, sizeof(pf),
+   &returnCode, TPM_DURATION_TYPE_SHORT);
+
+   dprintf("Return code from TPM_GetCapability() = 0x%08x\n",
+  

[PATCH 14/16] Add TPM firmware API call pass-through-to-tpm

2015-08-07 Thread Stefan Berger
This patch adds support for the firmware API call pass-through-to-tpm.

Signed-off-by: Stefan Berger 
---
 board-qemu/slof/vio-vtpm-cdriver.fs |  8 
 board-qemu/slof/vtpm-sml.fs |  7 +++
 lib/libtpm/tcgbios.c| 28 
 lib/libtpm/tcgbios.h|  1 +
 lib/libtpm/tpm.code | 11 +++
 lib/libtpm/tpm.in   |  1 +
 slof/fs/tpm/tpm-static.fs   | 13 +
 7 files changed, 69 insertions(+)

diff --git a/board-qemu/slof/vio-vtpm-cdriver.fs 
b/board-qemu/slof/vio-vtpm-cdriver.fs
index 22fef4f..5d55148 100644
--- a/board-qemu/slof/vio-vtpm-cdriver.fs
+++ b/board-qemu/slof/vio-vtpm-cdriver.fs
@@ -96,6 +96,14 @@ false VALUE vtpm-debug?
 ;
 
 \ firmware API call
+: pass-through-to-tpm ( buf-addr buf-size -- response-size )
+" pass-through-to-tpm" call-forward IF
+2drop
+0
+THEN
+;
+
+\ firmware API call
 : get-maximum-cmd-size ( -- maximum-size )
 " get-maximum-cmd-size" call-forward IF
 0
diff --git a/board-qemu/slof/vtpm-sml.fs b/board-qemu/slof/vtpm-sml.fs
index e62c20c..3ce1ace 100644
--- a/board-qemu/slof/vtpm-sml.fs
+++ b/board-qemu/slof/vtpm-sml.fs
@@ -80,6 +80,13 @@ log-base LOG-SIZE tpm-set-log-parameters
 vtpm-get-maximum-cmd-size
 ;
 
+: pass-through-to-tpm ( buf-addr cmd-size -- rsp-size )
+vtpm-debug? IF
+." Call to pass-through-to-tpm" cr
+THEN
+vtpm-pass-through-to-tpm
+;
+
 : open  true ;
 : close ;
 
diff --git a/lib/libtpm/tcgbios.c b/lib/libtpm/tcgbios.c
index b306edf..6c991b2 100644
--- a/lib/libtpm/tcgbios.c
+++ b/lib/libtpm/tcgbios.c
@@ -640,6 +640,34 @@ static bool pass_through_to_tpm(unsigned char *req,
 }
 
 /*
+ * tpm_pass_through_to_tpm: Function for interfacing with the firmware API
+ *
+ * buf: buffer holding the command; also used for holding the entire response
+ * cmdlen: length of the command in the buffer
+ *
+ * Returns 0 in case of failure, the size of the response otherwise.
+ */
+uint32_t tpm_pass_through_to_tpm(unsigned char *buf, uint32_t cmdlen)
+{
+   uint32_t resplen = PAPR_VTPM_MAX_BUFFER_SIZE;
+
+   /*
+* API spec: caller must ensure that the buffer is large
+*   enough to receive the full response into
+*   the same buffer where the command is in.
+*   We anticipate the largest possible buffer
+*   the driver supports in 'resplen'.
+* For duration we use the worst-case timeout 'LONG'
+* so that any command can be sent and will not time out.
+*/
+   if (pass_through_to_tpm(buf, cmdlen,
+   TPM_DURATION_TYPE_LONG,
+   buf, &resplen))
+   return 0;
+   return resplen;
+}
+
+/*
  * Extend a PCR of the TPM with the given hash
  *
  * @hash: sha1 hash (20 bytes) to extend PCR with
diff --git a/lib/libtpm/tcgbios.h b/lib/libtpm/tcgbios.h
index 2aa7d20..6951af3 100644
--- a/lib/libtpm/tcgbios.h
+++ b/lib/libtpm/tcgbios.h
@@ -37,6 +37,7 @@ uint32_t tpm_hash_log_extend_event(struct pcpes *pcpes);
 bool tpm_log_event(struct pcpes *pcpes);
 uint32_t tpm_hash_all(const void *data, uint32_t datalen, void *hashptr);
 uint32_t tpm_get_maximum_cmd_size(void);
+uint32_t tpm_pass_through_to_tpm(unsigned char *buf, uint32_t cmdlen);
 
 /* flags returned by tpm_get_state */
 #define TPM_STATE_ENABLED1
diff --git a/lib/libtpm/tpm.code b/lib/libtpm/tpm.code
index 5c3d4db..e763f45 100644
--- a/lib/libtpm/tpm.code
+++ b/lib/libtpm/tpm.code
@@ -174,3 +174,14 @@ PRIM(tpm_X2d_get_X2d_maximum_X2d_cmd_X2d_size)
PUSH;
TOS.n = tpm_get_maximum_cmd_size();
 MIRP
+
+/***/
+/* Firmware API*/
+/* SLOF:   tpm-pass-through-to-tpm (buf-addr cmd-size -- rsp-size) */
+/* LIBTPM: respsize = tpm_pass_through_to_tpm(buf, cmdsize)*/
+/***/
+PRIM(tpm_X2d_pass_X2d_through_X2d_to_X2d_tpm)
+   int cmdsize = TOS.n; POP;
+   void *buf = TOS.a;
+   TOS.n = tpm_pass_through_to_tpm(buf, cmdsize);
+MIRP
diff --git a/lib/libtpm/tpm.in b/lib/libtpm/tpm.in
index 0923fc0..8b7cde8 100644
--- a/lib/libtpm/tpm.in
+++ b/lib/libtpm/tpm.in
@@ -28,3 +28,4 @@ cod(tpm-log-event)
 cod(tpm-hash-log-extend-event)
 cod(tpm-hash-all)
 cod(tpm-get-maximum-cmd-size)
+cod(tpm-pass-through-to-tpm)
diff --git a/slof/fs/tpm/tpm-static.fs b/slof/fs/tpm/tpm-static.fs
index fca0058..f9583b0 100644
--- a/slof/fs/tpm/tpm-static.fs
+++ b/slof/fs/tpm/tpm-static.fs
@@ -120,6 +120,19 @@ false VALUE vtpm-debug?
 THEN
 ;
 
+\ firmware API function
+: vtpm-pass-through-to-tpm ( buf-addr cmd-size -- rsp-size )
+vtpm-available? IF
+tpm-pass-through-to-tpm( -- rsp-size )
+vtpm-debug? IF
+." VTPM: Return value from tpm-pass-thr

[PATCH 10/16] Implement measurements of the master boot record

2015-08-07 Thread Stefan Berger
This patch adds support for measuring the boot block of the
MBR and logging the measurement.

Signed-off-by: Stefan Berger 
---
 board-js2x/slof/OF.fs  |  2 ++
 slof/fs/packages/disk-label.fs |  6 +-
 slof/fs/tpm/tpm-static.fs  | 13 +
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/board-js2x/slof/OF.fs b/board-js2x/slof/OF.fs
index 3e37735..8e736c7 100644
--- a/board-js2x/slof/OF.fs
+++ b/board-js2x/slof/OF.fs
@@ -255,6 +255,8 @@ create vpd-bootlist 4 allot
 #include 
 320 cp
 #include 
+\\ need tpm-static for verbs in disk-labels.fs
+#include 
 #include 
 360 cp
 #include "tree.fs"
diff --git a/slof/fs/packages/disk-label.fs b/slof/fs/packages/disk-label.fs
index e034d64..f827d72 100644
--- a/slof/fs/packages/disk-label.fs
+++ b/slof/fs/packages/disk-label.fs
@@ -545,7 +545,11 @@ B9E5CONSTANT GPT-BASIC-DATA-PARTITION-2
 \ load from a bootable partition
 : load-from-boot-partition ( addr -- size )
debug-disk-label? IF ." Trying DOS boot " .s cr THEN
-   dup load-from-dos-boot-partition ?dup 0 <> IF nip EXIT THEN
+   dup load-from-dos-boot-partition ?dup 0 <> IF
+  nip
+  80 block 200 vtpm-add-bcv
+  EXIT
+   THEN
 
debug-disk-label? IF ." Trying CHRP boot " .s cr THEN
1 disk-chrp-boot !
diff --git a/slof/fs/tpm/tpm-static.fs b/slof/fs/tpm/tpm-static.fs
index 7954be2..bc5138a 100644
--- a/slof/fs/tpm/tpm-static.fs
+++ b/slof/fs/tpm/tpm-static.fs
@@ -44,6 +44,19 @@ false VALUE vtpm-debug?
 THEN
 ;
 
+: vtpm-add-bcv ( boodrv addr length -- )
+vtpm-available? IF
+tpm-add-bcv( -- errcode )
+vtpm-debug? IF
+." VTPM: Error code from tpm-add-bootdevice-ipl: " . cr
+ELSE
+drop
+THEN
+ELSE
+3drop
+THEN
+;
+
 1 CONSTANT TPM_ST_ENABLED
 2 CONSTANT TPM_ST_ACTIVE
 4 CONSTANT TPM_ST_OWNED
-- 
1.9.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 16/16] Add TPM firmware API call get-failure-reason

2015-08-07 Thread Stefan Berger
This patch adds support for the TPM firmware API call get-failure-reason.

Signed-off-by: Stefan Berger 
---
 board-qemu/slof/vio-vtpm-cdriver.fs |  8 
 board-qemu/slof/vtpm-sml.fs |  7 +++
 lib/libtpm/tcgbios.c| 16 
 lib/libtpm/tcgbios.h|  1 +
 lib/libtpm/tpm.code | 10 ++
 lib/libtpm/tpm.in   |  1 +
 slof/fs/tpm/tpm-static.fs   | 12 
 7 files changed, 55 insertions(+)

diff --git a/board-qemu/slof/vio-vtpm-cdriver.fs 
b/board-qemu/slof/vio-vtpm-cdriver.fs
index 474c24c..18ee85a 100644
--- a/board-qemu/slof/vio-vtpm-cdriver.fs
+++ b/board-qemu/slof/vio-vtpm-cdriver.fs
@@ -80,6 +80,14 @@ false VALUE vtpm-debug?
 ;
 
 \ firmware API call
+: get-failure-reason ( -- reason )
+" get-failure-reason" call-forward IF
+\ call-forward failed; return a value
+0 \ invalid
+THEN
+;
+
+\ firmware API call
 : hash-all ( data-ptr data-len hash-ptr -- )
 " hash-all" call-forward IF
 \ call-forward failed; clean up stack
diff --git a/board-qemu/slof/vtpm-sml.fs b/board-qemu/slof/vtpm-sml.fs
index 449f6fc..a37aa80 100644
--- a/board-qemu/slof/vtpm-sml.fs
+++ b/board-qemu/slof/vtpm-sml.fs
@@ -59,6 +59,13 @@ log-base LOG-SIZE tpm-set-log-parameters
 vtpm-driver-get-state
 ;
 
+: get-failure-reason ( -- reason )
+vtpm-debug? IF
+." Call to get-failure-reason" cr
+THEN
+vtpm-driver-get-failure-reason
+;
+
 : hash-all ( data-ptr data-len hash-ptr -- )
 vtpm-debug? IF
 ." Call to hash-all" cr
diff --git a/lib/libtpm/tcgbios.c b/lib/libtpm/tcgbios.c
index 02ad91a..7194141 100644
--- a/lib/libtpm/tcgbios.c
+++ b/lib/libtpm/tcgbios.c
@@ -1545,3 +1545,19 @@ uint32_t tpm_driver_get_state(void)
 
return td->getstate();
 }
+
+/*
+ * tpm_driver_get_failure_reason: Function for interfacing with the firmware
+ *API
+ */
+uint32_t tpm_driver_get_failure_reason(void)
+{
+   struct tpm_driver *td = tpm_state.tpm_driver_to_use;
+
+   /* do not check for a working TPM here */
+
+   if (!td)
+   return PFW_DRV_ERROR_NO_FAILURE;
+
+   return td->geterror();
+}
diff --git a/lib/libtpm/tcgbios.h b/lib/libtpm/tcgbios.h
index 05cadb0..c7fbc29 100644
--- a/lib/libtpm/tcgbios.h
+++ b/lib/libtpm/tcgbios.h
@@ -39,6 +39,7 @@ uint32_t tpm_hash_all(const void *data, uint32_t datalen, 
void *hashptr);
 uint32_t tpm_get_maximum_cmd_size(void);
 uint32_t tpm_pass_through_to_tpm(unsigned char *buf, uint32_t cmdlen);
 uint32_t tpm_driver_get_state(void);
+uint32_t tpm_driver_get_failure_reason(void);
 
 /* flags returned by tpm_get_state */
 #define TPM_STATE_ENABLED1
diff --git a/lib/libtpm/tpm.code b/lib/libtpm/tpm.code
index 574c7eb..29e3b3d 100644
--- a/lib/libtpm/tpm.code
+++ b/lib/libtpm/tpm.code
@@ -163,6 +163,16 @@ PRIM(tpm_X2d_driver_X2d_get_X2d_state)
TOS.n = tpm_driver_get_state();
 MIRP
 
+//
+/* Firmware API */
+/* SLOF:   tpm-driver-get-error ( -- errcode)   */
+/* LIBTPM: errcode = tpm_driver_get_error(void) */
+//
+PRIM(tpm_X2d_driver_X2d_get_X2d_failure_X2d_reason)
+   PUSH;
+   TOS.n = tpm_driver_get_failure_reason();
+MIRP
+
 /*/
 /* Firmware API  */
 /* SLOF:   tpm-hash-all ( data-ptr data-len hash-ptr -- errcode) */
diff --git a/lib/libtpm/tpm.in b/lib/libtpm/tpm.in
index 3dd78f4..5f33d05 100644
--- a/lib/libtpm/tpm.in
+++ b/lib/libtpm/tpm.in
@@ -30,3 +30,4 @@ cod(tpm-hash-all)
 cod(tpm-get-maximum-cmd-size)
 cod(tpm-pass-through-to-tpm)
 cod(tpm-driver-get-state)
+cod(tpm-driver-get-failure-reason)
diff --git a/slof/fs/tpm/tpm-static.fs b/slof/fs/tpm/tpm-static.fs
index 31ac815..cbd92cb 100644
--- a/slof/fs/tpm/tpm-static.fs
+++ b/slof/fs/tpm/tpm-static.fs
@@ -81,6 +81,18 @@ false VALUE vtpm-debug?
 ;
 
 \ firmware API function
+: vtpm-driver-get-failure-reason ( -- reason )
+vtpm-available? IF
+tpm-driver-get-failure-reason
+vtpm-debug? IF
+." VTPM: Return value from tpm-driver-get-failure-reason: " dup . 
cr
+THEN
+ELSE
+-1 \ no failure
+THEN
+;
+
+\ firmware API function
 : vtpm-log-event ( event-ptr -- ok? )
 vtpm-available? IF
 tpm-log-event
-- 
1.9.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 15/16] Add TPM firmware API call get-state

2015-08-07 Thread Stefan Berger
This patch adds support for the TPM firmware API call get-state.

Signed-off-by: Stefan Berger 
---
 board-qemu/slof/vio-vtpm-cdriver.fs |  8 
 board-qemu/slof/vtpm-sml.fs |  7 +++
 lib/libtpm/tcgbios.c| 12 
 lib/libtpm/tcgbios.h|  1 +
 lib/libtpm/tpm.code | 10 ++
 lib/libtpm/tpm.in   |  1 +
 slof/fs/tpm/tpm-static.fs   | 12 
 7 files changed, 51 insertions(+)

diff --git a/board-qemu/slof/vio-vtpm-cdriver.fs 
b/board-qemu/slof/vio-vtpm-cdriver.fs
index 5d55148..474c24c 100644
--- a/board-qemu/slof/vio-vtpm-cdriver.fs
+++ b/board-qemu/slof/vio-vtpm-cdriver.fs
@@ -72,6 +72,14 @@ false VALUE vtpm-debug?
 ;
 
 \ firmware API call
+: get-state ( -- state )
+" get-state" call-forward IF
+\ call-forward failed; return a value
+0 \ invalid
+THEN
+;
+
+\ firmware API call
 : hash-all ( data-ptr data-len hash-ptr -- )
 " hash-all" call-forward IF
 \ call-forward failed; clean up stack
diff --git a/board-qemu/slof/vtpm-sml.fs b/board-qemu/slof/vtpm-sml.fs
index 3ce1ace..449f6fc 100644
--- a/board-qemu/slof/vtpm-sml.fs
+++ b/board-qemu/slof/vtpm-sml.fs
@@ -52,6 +52,13 @@ log-base LOG-SIZE tpm-set-log-parameters
 move
 ;
 
+: get-state ( -- state )
+vtpm-debug? IF
+." Call to get-state" cr
+THEN
+vtpm-driver-get-state
+;
+
 : hash-all ( data-ptr data-len hash-ptr -- )
 vtpm-debug? IF
 ." Call to hash-all" cr
diff --git a/lib/libtpm/tcgbios.c b/lib/libtpm/tcgbios.c
index 6c991b2..02ad91a 100644
--- a/lib/libtpm/tcgbios.c
+++ b/lib/libtpm/tcgbios.c
@@ -1533,3 +1533,15 @@ err_exit:
 
return 0;
 }
+
+uint32_t tpm_driver_get_state(void)
+{
+   struct tpm_driver *td = tpm_state.tpm_driver_to_use;
+
+   /* do not check for a working TPM here */
+
+   if (!td)
+   return PFW_DRV_STATE_INVALID;
+
+   return td->getstate();
+}
diff --git a/lib/libtpm/tcgbios.h b/lib/libtpm/tcgbios.h
index 6951af3..05cadb0 100644
--- a/lib/libtpm/tcgbios.h
+++ b/lib/libtpm/tcgbios.h
@@ -38,6 +38,7 @@ bool tpm_log_event(struct pcpes *pcpes);
 uint32_t tpm_hash_all(const void *data, uint32_t datalen, void *hashptr);
 uint32_t tpm_get_maximum_cmd_size(void);
 uint32_t tpm_pass_through_to_tpm(unsigned char *buf, uint32_t cmdlen);
+uint32_t tpm_driver_get_state(void);
 
 /* flags returned by tpm_get_state */
 #define TPM_STATE_ENABLED1
diff --git a/lib/libtpm/tpm.code b/lib/libtpm/tpm.code
index e763f45..574c7eb 100644
--- a/lib/libtpm/tpm.code
+++ b/lib/libtpm/tpm.code
@@ -153,6 +153,16 @@ PRIM(tpm_X2d_hash_X2d_log_X2d_extend_X2d_event)
TOS.n = tpm_hash_log_extend_event(eventptr);
 MIRP
 
+//
+/* Firmware API */
+/* SLOF:   tpm-driver-get-state ( -- state) */
+/* LIBTPM: state = tpm_driver_get_state(void)   */
+//
+PRIM(tpm_X2d_driver_X2d_get_X2d_state)
+   PUSH;
+   TOS.n = tpm_driver_get_state();
+MIRP
+
 /*/
 /* Firmware API  */
 /* SLOF:   tpm-hash-all ( data-ptr data-len hash-ptr -- errcode) */
diff --git a/lib/libtpm/tpm.in b/lib/libtpm/tpm.in
index 8b7cde8..3dd78f4 100644
--- a/lib/libtpm/tpm.in
+++ b/lib/libtpm/tpm.in
@@ -29,3 +29,4 @@ cod(tpm-hash-log-extend-event)
 cod(tpm-hash-all)
 cod(tpm-get-maximum-cmd-size)
 cod(tpm-pass-through-to-tpm)
+cod(tpm-driver-get-state)
diff --git a/slof/fs/tpm/tpm-static.fs b/slof/fs/tpm/tpm-static.fs
index f9583b0..31ac815 100644
--- a/slof/fs/tpm/tpm-static.fs
+++ b/slof/fs/tpm/tpm-static.fs
@@ -69,6 +69,18 @@ false VALUE vtpm-debug?
 ;
 
 \ firmware API function
+: vtpm-driver-get-state ( -- state )
+vtpm-available? IF
+tpm-driver-get-state
+vtpm-debug? IF
+." VTPM: Return value from tpm-driver-get-state: " dup . cr
+THEN
+ELSE
+0 \ invalid
+THEN
+;
+
+\ firmware API function
 : vtpm-log-event ( event-ptr -- ok? )
 vtpm-available? IF
 tpm-log-event
-- 
1.9.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: powerpc/fsl_book3e: fix the relocatable bug in debug interrupt handler

2015-08-07 Thread Scott Wood
[Please wrap commit messages at around 74 columns]

On Fri, Aug 07, 2015 at 02:58:10PM +0800, Yuanjie Huang wrote:
> PowerPC Book3E processor features hardware-supported single instruction
> execution, and it is used for ptrace(PTRACE_SINGLESTEP, ...).  When a
> debugger loads a debuggee, it typically sets the CPU to yield debug
> interrupt on first instruction complete or branch taken.  However, the
> newly-forked child process could run into instruction TLB miss
> exception handler when switched to, and causes a debug interrupt in the
> exception entry sequence.  This is not expected by caller of
> ptrace(PTRACE_SINGLESTEP, ...), so the next instruction address saved
> in DSRR0 is checked against the boundary of exception entry sequence,
> to ensure the kernel only process the interrupt as a normal exception
> if the address does not fall in the exception entry sequence.  Failure
> in obtaining the correct boundary leads to such debug exception handled
> as from privileged mode, and causes kernel oops.
> 
> The LOAD_REG_IMMEDIATE can't be used to load the boundary addresses
> when relocatable enabled, so this patch replace them with
> LOAD_REG_ADDR_PIC.  LR is backed up and restored before and after
> calling LOAD_REG_ADDR_PIC, because LOAD_REG_ADDR_PIC clobbers it.
> 
> Signed-off-by: Yuanjie Huang 
> ---
>  arch/powerpc/kernel/exceptions-64e.S | 24 
>  1 file changed, 24 insertions(+)
> 
> diff --git a/arch/powerpc/kernel/exceptions-64e.S 
> b/arch/powerpc/kernel/exceptions-64e.S
> index 3e68d1c..c475f569 100644
> --- a/arch/powerpc/kernel/exceptions-64e.S
> +++ b/arch/powerpc/kernel/exceptions-64e.S
> @@ -735,12 +735,24 @@ END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
>   andis.  r15,r14,(DBSR_IC|DBSR_BT)@h
>   beq+1f
>  
> +#ifdef CONFIG_RELOCATABLE
> + mflrr14
> + LOAD_REG_ADDR_PIC(r15,interrupt_base_book3e)
> + mtlrr14
> + cmpld   cr0,r10,r15
> + blt+cr0,1f
> + LOAD_REG_ADDR_PIC(r15,interrupt_end_book3e)
> + mtlrr14
> + cmpld   cr0,r10,r15
> + bge+cr0,1f
> +#else

CONFIG_RELOCATABLE is not supported on 64-bit book3e without applying
additional patches, such as the RFC patchset I posted recently that
contained the patch "powerpc/book3e-64: rename interrupt_end_book3e with
__end_interrupts".  But if you've applied that patchset, then you
wouldn't be working with the name interrupt_base_book3e, so how are you
seeing this?

Also, why not use the RELOCATABLE version unconditionally?  I don't think
this is a performance-critical path.

-Scott
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [v3] powerpc/fsl-booke: Add T1040D4RDB/T1042D4RDB board support

2015-08-07 Thread Scott Wood
On Thu, Jul 30, 2015 at 10:33:55AM +0530, Priyanka Jain wrote:
> T1040D4RDB/T1042D4RDB are Freescale Reference Design Board
> which can support T1040/T1042 QorIQ Power
> Architectureâ„¢ processor respectively

What is the actual name of this board? 
http://patchwork.ozlabs.org/patch/504944/ changes the name in U-Boot from
"T1040D4RDB" to "T1040RDB_DDR4".

Is it really a different board, or just different RAM?  If the latter, we
don't specify the RAM type in the device tree, so why do we need separate
device trees?

-Scott
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev