Re: [PATCH v5 00/12] KVM: introduce readonly memslot

2012-08-15 Thread Xiao Guangrong
On 08/14/2012 11:25 PM, Marcelo Tosatti wrote:
> On Tue, Aug 14, 2012 at 10:58:07AM +0800, Xiao Guangrong wrote:
>> On 08/14/2012 01:39 AM, Marcelo Tosatti wrote:
>>> On Sat, Aug 11, 2012 at 11:36:20AM +0800, Xiao Guangrong wrote:
 On 08/11/2012 02:14 AM, Marcelo Tosatti wrote:
> On Tue, Aug 07, 2012 at 05:47:15PM +0800, Xiao Guangrong wrote:
>> Changelog:
>> - introduce KVM_PFN_ERR_RO_FAULT instead of dummy page
>> - introduce KVM_HVA_ERR_BAD and optimize error hva indicators
>>
>> The test case can be found at:
>> http://lkml.indiana.edu/hypermail/linux/kernel/1207.2/00819/migrate-perf.tar.bz2
>>
>> In current code, if we map a readonly memory space from host to guest
>> and the page is not currently mapped in the host, we will get a fault-pfn
>> and async is not allowed, then the vm will crash.
>>
>> As Avi's suggestion, We introduce readonly memory region to map ROM/ROMD
>> to the guest, read access is happy for readonly memslot, write access on
>> readonly memslot will cause KVM_EXIT_MMIO exit.
>
> Memory slots whose QEMU mapping is write protected is supported
> today, as long as there are no write faults.
>
> What prevents the use of mmap(!MAP_WRITE) to handle read-only memslots
> again?
>

 It is happy to map !write host memory space to the readonly memslot,
 and they can coexist as well.

 readonly memslot checks the write-permission by seeing slot->flags and
 !write memory checks the write-permission in hva_to_pfn() function
 which checks vma->flags. It is no conflict.
>>>
>>> Yes, there is no conflict. The point is, if you can use the
>>> mmap(PROT_READ) interface (supporting read faults on read-only slots)
>>> for this behavior, what is the advantage of a new memslot flag?
>>>
>>
>> You can get the discussion at:
>> https://lkml.org/lkml/2012/5/22/228
>>
>>> I'm not saying mmap(PROT_READ) is the best interface, i am just asking
>>> why it is not.
>>
>> My fault. :(
>>
>>>
> The initial objective was to fix a vm crash, can you explain that
> initial problem?
>

 The issue was trigged by this code:

 } else {
 if (async && (vma->vm_flags & VM_WRITE))
 *async = true;
 pfn = KVM_PFN_ERR_FAULT;
 }

 If the host memory region is readonly (!vma->vm_flags & VM_WRITE) and
 its physical page is swapped out (or the file data does not be read in),
 get_user_page_nowait will fail, above code reject to set async,
 then we will get a fault pfn and async=false.

 I guess this issue also exists in "QEMU write protected mapping" as
 you mentioned above.
>>>
>>> Yes, it does. As far as i understand, what that check does from a high
>>> level pov is:
>>>
>>> - Did get_user_pages_nowait() fail due to a swapped out page (in which 
>>> case we should try to swappin the page asynchronously), or due to 
>>> another reason (for which case an error should be returned).
>>>
>>> Using vma->vm_flags VM_WRITE for that is trying to guess why
>>> get_user_pages_nowait() failed, because it (gup_nowait return values) 
>>> does not provide sufficient information by itself.
>>>
>>
>> That is exactly what i did in the first version. :)
>>
>> You can see it and the reason why it switched to the new way (readonly 
>> memslot)
>> in the above website (the first message in thread).
> 
> Userspace can create multiple mappings for the same memory region, for
> example via shared memory (shm_open), and have different protections for
> the two (or more) regions. I had old patch doing this, its attached.
> 

In this way, if guest try to write a readonly gfn, the vm will be crashed since
it will return FAULT_PFN on the page-fault path. VMM can not detect this kind
of fault, we have these problems:
- even if guest try to write ROM on a PCI device, the guest will die, but
  we'd ignore this write, it looks more like the real machine.

- can not implement ROMD beacuse write to a ROMD is MMIO access

Yes, we can rework get_user_page_nowait and get_user_pages_fast, let them
tell us the fault reason, but it is more complex i think.

>>> Can't that be fixed separately? 
>>>
>>> Another issue which is also present with the mmap(PROT_READ) scheme is
>>> interaction with reexecute_instruction. That is, unless i am mistaken,
>>> reexecute_instruction can succeed (return true) on a region that is
>>> write protected. This breaks the "write faults on read-only slots exit
>>> to userspace via EXIT_MMIO" behaviour.
>>
>> Sorry, Why? After re-entry to the guest, it can not generate a correct MMIO?
> 
> reexecute_instruction validates presence of GPA by looking at registered
> memslots. But if the access is a write, and userspace memory map is
> read-only, reexecute_instruction should exit via MMIO.
> 
> That is, reexecute_instruction must validate GPA 

Re: [patch net-next v2 01/15] net: introduce upper device lists

2012-08-15 Thread Jiri Pirko
Thu, Aug 16, 2012 at 12:15:49AM CEST, da...@davemloft.net wrote:
>From: Jiri Pirko 
>Date: Wed, 15 Aug 2012 09:46:12 +0200
>
>> You are probably right. I'm not sure how to handle this correctly
>> though. Adding some hard limit number might not be correct.
>
>I would just use a hard limit of something like 8 for now, and if we
>need to expand this limit we can consider how to do so with real known
>usage in mind rather than pure speculation.

Okay. I will repost the set soon.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [PATCH] rtc: tps65910: Add RTC driver for TPS65910 PMIC RTC

2012-08-15 Thread Venu Byravarasu
Hi Andrew,

Already an updated patch v3 (http://lkml.org/lkml/2012/8/8/221 ) was pushed to 
fix these issues.
Plz review and merged that.

Thanks,
Venu


> -Original Message-
> From: Andrew Morton [mailto:a...@linux-foundation.org]
> Sent: Wednesday, August 15, 2012 5:22 AM
> To: Venu Byravarasu
> Cc: a.zu...@towertech.it; sa...@linux.intel.com;
> broo...@opensource.wolfsonmicro.com; Laxman Dewangan;
> kyle.ma...@fuel7.com; rtc-li...@googlegroups.com; linux-
> ker...@vger.kernel.org
> Subject: Re: [PATCH] rtc: tps65910: Add RTC driver for TPS65910 PMIC RTC
> 
> On Thu, 26 Jul 2012 12:05:19 +0530
> Venu Byravarasu  wrote:
> 
> > TPS65910 PMIC is a MFD with RTC as one of the device.
> > Adding RTC driver for supporting RTC device present
> > inside TPS65910 PMIC.
> >
> > Only support for RTC alarm is implemented as part of this patch.
> 
> It needs a build fix:
> 
> drivers/rtc/rtc-tps65910.c: In function 'tps65910_rtc_suspend':
> drivers/rtc/rtc-tps65910.c:313: error: request for member 'irqstat' in
> something not a structure or union
> drivers/rtc/rtc-tps65910.c: In function 'tps65910_rtc_resume':
> drivers/rtc/rtc-tps65910.c:327: error: request for member 'irqstat' in
> something not a structure or union
> 
> --- a/drivers/rtc/rtc-tps65910.c~rtc-tps65910-add-rtc-driver-for-tps65910-
> pmic-rtc-fix
> +++ a/drivers/rtc/rtc-tps65910.c
> @@ -310,7 +310,7 @@ static int tps65910_rtc_suspend(struct p
> 
>   /* Store current list of enabled interrupts*/
>   ret = regmap_read(tps->regmap, TPS65910_RTC_INTERRUPTS,
> - >rtc.irqstat);
> + >rtc->irqstat);
>   if (ret < 0)
>   return ret;
> 
> @@ -324,7 +324,7 @@ static int tps65910_rtc_resume(struct pl
> 
>   /* Restore list of enabled interrupts before suspend */
>   return regmap_write(tps->regmap, TPS65910_RTC_INTERRUPTS,
> - tps->rtc.irqstat);
> + tps->rtc->irqstat);
>  }
> 
>  static const struct dev_pm_ops tps65910_rtc_pm_ops = {
> 
> 
> but it still has problems:
> 
> drivers/rtc/rtc-tps65910.c:331: warning: initialization from incompatible
> pointer type
> drivers/rtc/rtc-tps65910.c:332: warning: initialization from incompatible
> pointer type
> 
> fix and resend, please?
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [discussion]sched: a rough proposal to enable power saving in scheduler

2012-08-15 Thread Matthew Garrett
On Thu, Aug 16, 2012 at 01:39:36PM +0800, Alex Shi wrote:
> On 08/16/2012 01:31 PM, Matthew Garrett wrote:
> > will tend to split them across packages?
> 
> 
> No, there is still has balance idea in this rough proposal. If a domain
> is not overload, it is better to left old tasks unchanged. I should say,
> current scheduler is the 'performance' trend scheme.

The current process isn't necessarily ideal for all workloads - that's 
one of the reasons for letting workspace modify process affinity. I 
agree that the "performance" mode will tend to provide better 
performance than the "power" mode for an arbitrary workload, but if 
there are workloads that would perform better in "power" then it's a 
poor naming scheme.

-- 
Matthew Garrett | mj...@srcf.ucam.org
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [discussion]sched: a rough proposal to enable power saving in scheduler

2012-08-15 Thread Alex Shi
On 08/16/2012 01:31 PM, Matthew Garrett wrote:

> On Thu, Aug 16, 2012 at 01:03:32PM +0800, Alex Shi wrote:
>> On 08/16/2012 12:19 AM, Matthew Garrett wrote:
>>> Are there workloads in which "power" might provide more performance than 
>>> "performance"? If so, don't use these terms.
>>
>> Power scheme should no chance has better performance in design.
> 
> Power will tend to concentrate processes on packages, 


yes.

while performance 
> will tend to split them across packages?


No, there is still has balance idea in this rough proposal. If a domain
is not overload, it is better to left old tasks unchanged. I should say,
current scheduler is the 'performance' trend scheme.

 What if two cooperating 
> processes gain from being on the same package and sharing cache 
> locality?
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


linux-next: Tree for Aug 16

2012-08-15 Thread Stephen Rothwell
Hi all,

Changes since 20120814:

The infiniband tree gained a build failure so I used the version from
next-20120814.

The regulator tree gained a build failure for which I applied a patch.

The l2-mtd tree lost its conflict.

The hid tree gained a build failure for which I applied a patch.

The tip tree gained a build failure so I used the version from
next-20120814.

The kvm tree gained a conflict against the s390 tree.

I have still reverted 3 commits from the signal tree at the request of the
arm maintainer.

The akpm tree lost 3 patches that turned up elsewhere.



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

You can see which trees have been included by looking in the Next/Trees
file in the source.  There are also quilt-import.log and merge.log files
in the Next directory.  Between each merge, the tree was built with
a ppc64_defconfig for powerpc and an allmodconfig for x86_64. After the
final fixups (if any), it is also built with powerpc allnoconfig (32 and
64 bit), ppc44x_defconfig and allyesconfig (minus
CONFIG_PROFILE_ALL_BRANCHES - this fails its final link) and i386, sparc,
sparc64 and arm defconfig. These builds also have
CONFIG_ENABLE_WARN_DEPRECATED, CONFIG_ENABLE_MUST_CHECK and
CONFIG_DEBUG_INFO disabled when necessary.

Below is a summary of the state of the merge.

We are up to 195 trees (counting Linus' and 26 trees of patches pending
for Linus' tree), more are welcome (even if they are currently empty).
Thanks to those who have contributed, and to those who haven't, please do.

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

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

There is a wiki covering stuff to do with linux-next at
http://linux.f-seidel.de/linux-next/pmwiki/ .  Thanks to Frank Seidel.

-- 
Cheers,
Stephen Rothwells...@canb.auug.org.au

$ git checkout master
$ git reset --hard stable
Merging origin/master (ddf343f Merge branch 'for-linus' of 
git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux)
Merging fixes/master (9023a40 Merge tag 'mmc-fixes-for-3.5-rc4' of 
git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc)
Merging kbuild-current/rc-fixes (f8f5701 Linux 3.5-rc1)
Merging arm-current/fixes (8986873 ARM: 7490/1: Drop duplicate select for 
GENERIC_IRQ_PROBE)
Merging m68k-current/for-linus (9e2760d m68k: Make sys_atomic_cmpxchg_32 work 
on classic m68k)
Merging powerpc-merge/merge (ad36cb0 powerpc/kvm/book3s_32: Fix MTMSR_EERI 
macro)
Merging sparc/master (2856cc2 sparc64: Be less verbose during vmemmap 
population.)
Merging net/master (e3bc4ff vmxnet3: Fix race between dev_open() and 
register_netdev())
Merging sound-current/for-linus (3bdcff7 ALSA: lx6464es: Add a missing error 
check)
Merging pci-current/for-linus (9f6445a Merge branch 'pci/rafael-3.6-fixes' into 
for-linus)
Merging wireless/master (7dd6753 ath5k: fix spin_lock_irqsave/spin_lock_bh 
nesting in mesh)
Merging driver-core.current/driver-core-linus (0d7614f Linux 3.6-rc1)
Merging tty.current/tty-linus (7d9739c serial: ifx6x60: fix paging fault on 
spi_register_driver)
Merging usb.current/usb-linus (1e65848 USB: serial: Fix mos7840 timeout)
Merging staging.current/staging-linus (8607dcb staging: csr: add INET 
dependancy)
Merging char-misc.current/char-misc-linus (0d7614f Linux 3.6-rc1)
Merging input-current/for-linus (cf45b5a Merge branch 'next' into for-linus)
Merging md-current/for-linus (58e94ae md/raid1: close some possible races on 
write errors during resync)
Merging audit-current/for-linus (c158a35 audit: no leading space in 
audit_log_d_path prefix)
Merging crypto-current/master (76f16f8 crypto: hifn_795x - fix 64bit division 
and undefined __divdi3 on 32bit archs)
Merging ide/master (39a50b4 Merge branch 'hfsplus')
Merging dwmw2/master (244dc4e Merge 
git://git.infradead.org/users/dwmw2/random-2.6)
Merging sh-current/sh-fixes-for-linus (4403310 SH: Convert out[bwl] macros to 
inline functions)
Merging irqdomain-current/irqdomain/merge (15e06bf irqdomain: Fix debugfs 
formatting)
Merging devicetree-current/devicetree/merge (4e8383b of: release node fix for 
of_parse_phandle_with_args)
Merging spi-current/spi/merge (d1c185b of/spi: Fix SPI module loading by using 
proper "spi:" modalias prefixes.)
Merging gpio-current/gpio/merge (96b7064 gpio/tca6424: merge I2C transactions, 
remove cast)
Merging arm/for-next (22018e9 Merge branches 

RE: [PATCH v2] iio: adc: add new lp8788 adc driver

2012-08-15 Thread Jonathan Cameron


"Kim, Milo"  wrote:

>> > +  switch (mask) {
>> > +  case IIO_CHAN_INFO_RAW:
>> > +  *val = result;
>> > +  return IIO_VAL_INT;
>> > +  case IIO_CHAN_INFO_SCALE:
>> > +  *val = adc_const[id] * ((result * 1000 + 500) / 1000);
>> 
>> This looks wrong. The IIO_CHAN_INFO_SCALE attribute is the factor by
>> which
>> IIO_CHAN_INFO_RAW needs to be multiplied to get the value in the
>proper
>> unit,
>> which is specified in the IIO ABI spec. E.g. milli volts for
>voltages.
>> 
>> What you return here seems to be the IIO_CHAN_INFO_PROCESSED
>attribute.
>> Which
>> basically is raw * scale.
>
>Thanks a lot for your review.
>
>Any way to get the result with offset value in the iio-consumer side?
>What I need is as below.
>
>  result = raw * scale + offset
>
>At this moment, there are two apis() for reading the iio channel
>- iio_read_channel_raw() and iio_read_channel_scale().
>
>Does it sound good if I add iio_read_channel_offset() consumer api
>using IIO_CHAN_INFO_OFFSET?

Yes. Please add that.
>
>Best Regards,
>Milo

-- 
Sent from my Android phone with K-9 Mail. Please excuse my brevity.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [discussion]sched: a rough proposal to enable power saving in scheduler

2012-08-15 Thread Matthew Garrett
On Thu, Aug 16, 2012 at 01:03:32PM +0800, Alex Shi wrote:
> On 08/16/2012 12:19 AM, Matthew Garrett wrote:
> > Are there workloads in which "power" might provide more performance than 
> > "performance"? If so, don't use these terms.
> 
> Power scheme should no chance has better performance in design.

Power will tend to concentrate processes on packages, while performance 
will tend to split them across packages? What if two cooperating 
processes gain from being on the same package and sharing cache 
locality?

-- 
Matthew Garrett | mj...@srcf.ucam.org
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [discussion]sched: a rough proposal to enable power saving in scheduler

2012-08-15 Thread Alex Shi
On 08/15/2012 10:55 PM, Peter Zijlstra wrote:

> On Wed, 2012-08-15 at 20:24 +0600, Rakib Mullick wrote:
>> How do you plan to test this power saving scheme? Using powertop? Or,
>> is there any other tools? 
> 
> We should start out simple enough that we can validate it by looking at
> task placement by hand, eg. 4 tasks on a dual socket quad-core, should
> only keep one socket awake.
> 
> We can also add an power aware evaluator to Linsched (another one of
> those things that needs getting sorted).
> 
> And yeah, someone running with a power meter is of course king.
> 
> _BUT_ we shouldn't go off the wall with power meters as that very
> quickly gets very specific to the system being measured.
> 
> We should really keep this thing as simple as possible while still
> providing some benefit for all various architectures without tons of per
> arch knobs and knowhow.


Definitely agree all!
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


linux-next: build failure after merge of the final tree (hid tree related)

2012-08-15 Thread Stephen Rothwell
Hi all,

After merging the final tree, today's linux-next build (powerpc
allyesconfig) failed like this:

drivers/hid/hid-picolcd_fb.c: In function 'picolcd_fb_destroy':
drivers/hid/hid-picolcd_fb.c:350:2: error: implicit declaration of function 
'vfree' [-Werror=implicit-function-declaration]
drivers/hid/hid-picolcd_fb.c: In function 'picolcd_init_framebuffer':
drivers/hid/hid-picolcd_fb.c:508:2: error: implicit declaration of function 
'vmalloc' [-Werror=implicit-function-declaration]
drivers/hid/hid-picolcd_fb.c:508:12: warning: assignment makes pointer from 
integer without a cast [enabled by default]

Caused by commit fabdbf2fd22f ("HID: picoLCD: split driver code") from
the hid tree.

I added the following patch for today:

From: Stephen Rothwell 
Date: Thu, 16 Aug 2012 15:20:10 +1000
Subject: [PATCH] HID: using vmalloc() requires the include of vmalloc.h

Fixes thes build errors:

drivers/hid/hid-picolcd_fb.c: In function 'picolcd_fb_destroy':
drivers/hid/hid-picolcd_fb.c:350:2: error: implicit declaration of function 
'vfree' [-Werror=implicit-function-declaration]
drivers/hid/hid-picolcd_fb.c: In function 'picolcd_init_framebuffer':
drivers/hid/hid-picolcd_fb.c:508:2: error: implicit declaration of function 
'vmalloc' [-Werror=implicit-function-declaration]
drivers/hid/hid-picolcd_fb.c:508:12: warning: assignment makes pointer from 
integer without a cast [enabled by default]

Signed-off-by: Stephen Rothwell 
---
 drivers/hid/hid-picolcd_fb.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/hid/hid-picolcd_fb.c b/drivers/hid/hid-picolcd_fb.c
index 4d8e22c..cf295c5 100644
--- a/drivers/hid/hid-picolcd_fb.c
+++ b/drivers/hid/hid-picolcd_fb.c
@@ -18,6 +18,7 @@
  ***/
 
 #include 
+#include 
 #include "usbhid/usbhid.h"
 #include 
 
-- 
1.7.10.280.gaa39

-- 
Cheers,
Stephen Rothwells...@canb.auug.org.au


pgpaN7pE7eHPk.pgp
Description: PGP signature


[PATCH v4] mmc: card: Skip secure option for MoviNAND.

2012-08-15 Thread IAN CHEN
For several MoviNAND, there are some known issue with secure option.
For these specific MoviNAND device, we skip secure option.

You could refer this discussion in XDA developers.
http://forum.xda-developers.com/showthread.php?t=1644364
https://plus.google.com/111398485184813224730/posts/21pTYfTsCkB#111398485184813224730/posts/21pTYfTsCkB

Signed-off-by: Ian Chen 
---
 drivers/mmc/card/block.c |   24 +++-
 include/linux/mmc/card.h |1 +
 2 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index f1c84de..0377885 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -1411,7 +1411,8 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq,
struct request *req)
/* complete ongoing async transfer before issuing discard */
if (card->host->areq)
mmc_blk_issue_rw_rq(mq, NULL);
-   if (req->cmd_flags & REQ_SECURE)
+   if (req->cmd_flags & REQ_SECURE &&
+   !(card->quirks & MMC_QUIRK_SEC_ERASE_TRIM_BROKEN))
ret = mmc_blk_issue_secdiscard_rq(mq, req);
else
ret = mmc_blk_issue_discard_rq(mq, req);
@@ -1716,6 +1717,7 @@ force_ro_fail:
 #define CID_MANFID_SANDISK 0x2
 #define CID_MANFID_TOSHIBA 0x11
 #define CID_MANFID_MICRON  0x13
+#define CID_MANFID_SAMSUNG 0x15

 static const struct mmc_fixup blk_fixups[] =
 {
@@ -1752,6 +1754,26 @@ static const struct mmc_fixup blk_fixups[] =
MMC_FIXUP(CID_NAME_ANY, CID_MANFID_MICRON, 0x200, add_quirk_mmc,
  MMC_QUIRK_LONG_READ_TIME),

+   /*
+* Some issue about secure erase/secure trim for Samsung MoviNAND
+*/
+   MMC_FIXUP("M8G2FA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
+ MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
+   MMC_FIXUP("MAG4FA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
+ MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
+   MMC_FIXUP("MBG8FA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
+ MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
+   MMC_FIXUP("MCGAFA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
+ MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
+   MMC_FIXUP("VAL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
+ MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
+   MMC_FIXUP("VYL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
+ MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
+   MMC_FIXUP("KYL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
+ MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
+   MMC_FIXUP("VZL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
+ MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
+
END_FIXUP
 };

diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h
index 111aca5..4b27f9f 100644
--- a/include/linux/mmc/card.h
+++ b/include/linux/mmc/card.h
@@ -239,6 +239,7 @@ struct mmc_card {
 #define MMC_QUIRK_BLK_NO_CMD23 (1<<7)  /* Avoid CMD23 for regular
multiblock */
 #define MMC_QUIRK_BROKEN_BYTE_MODE_512 (1<<8)  /* Avoid sending 512
bytes in */
 #define MMC_QUIRK_LONG_READ_TIME (1<<9)/* Data read time > CSD 
says */
+#define MMC_QUIRK_SEC_ERASE_TRIM_BROKEN (1<<10)/* Skip secure for
erase/trim */
/* byte mode */
unsigned intpoweroff_notify_state;  /* eMMC4.5 notify feature */
 #define MMC_NO_POWER_NOTIFICATION  0
-- 
1.7.0.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


linux-next: build failure after merge of the final tree (regulator tree related)

2012-08-15 Thread Stephen Rothwell
Hi all,

After merging the final tree, today's linux-next build (powerpc
allyesconfig) failed like this:

drivers/regulator/twl-regulator.c: In function 'twlreg_probe':
drivers/regulator/twl-regulator.c:1229:3: error: implicit declaration of 
function 'kfree' [-Werror=implicit-function-declaration]

Caused by commit 537fbe92d723 ("regulator: twl: make twl_info tables
const") from the regulator tree.

I have added the following patch for today:

From: Stephen Rothwell 
Date: Thu, 16 Aug 2012 15:11:22 +1000
Subject: [PATCH] regulator: using kfree() requires including slab.h

Fixes this build error:

drivers/regulator/twl-regulator.c: In function 'twlreg_probe':
drivers/regulator/twl-regulator.c:1229:3: error: implicit declaration of 
function 'kfree' [-Werror=implicit-function-declaration]

Also added string.h for kmemdup().

Signed-off-by: Stephen Rothwell 
---
 drivers/regulator/twl-regulator.c |2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/regulator/twl-regulator.c 
b/drivers/regulator/twl-regulator.c
index a836522..564acae 100644
--- a/drivers/regulator/twl-regulator.c
+++ b/drivers/regulator/twl-regulator.c
@@ -10,6 +10,8 @@
  */
 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
-- 
1.7.10.280.gaa39

-- 
Cheers,
Stephen Rothwells...@canb.auug.org.au


pgpZRLL4txbFI.pgp
Description: PGP signature


Re: [PATCH] add support bluetooth usb 0489:e046 Foxconn / Hon Hai

2012-08-15 Thread Gustavo Padovan
Hi,

* koko Aborigines <7aborigin...@gmail.com> [2012-08-16 10:12:44 +0700]:

> Hi, Gustavo
> 
> i have error with your patch
> 
>  CC [M]  drivers/bluetooth/btusb.o
> drivers/bluetooth/btusb.c:113:2: error: implicit declaration of function
> ‘USB_VENDOR_AND_INTERFACE_INFO’ [-Werror=implicit-function-declaration]
> drivers/bluetooth/btusb.c:113:2: error: initializer element is not constant
> drivers/bluetooth/btusb.c:113:2: error: (near initialization for
> ‘btusb_table[22].match_flags’)

You need to apply it against the bluetooth-next tree (or linux-next).

Gustavo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [discussion]sched: a rough proposal to enable power saving in scheduler

2012-08-15 Thread Alex Shi
On 08/16/2012 12:19 AM, Matthew Garrett wrote:

> On Mon, Aug 13, 2012 at 08:21:00PM +0800, Alex Shi wrote:
> 
>> power aware scheduling), this proposal will adopt the
>> sched_balance_policy concept and use 2 kind of policy: performance, power.
> 
> Are there workloads in which "power" might provide more performance than 
> "performance"? If so, don't use these terms.
> 


Power scheme should no chance has better performance in design.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[git pull] more drm fixes

2012-08-15 Thread Dave Airlie

Just some intel and nouveau ones this time, intel has more edp panel fixes 
for macbooks and nouveau has a suspend/resume regression fix in there.

Dave.

The following changes since commit 7bac6b46607f2f44075cb45dd5b0b4d2e7c80695:

  Merge branch 'drm-fixes-3.6' of git://people.freedesktop.org/~agd5f/linux 
into drm-fixes (2012-08-14 09:25:01 +1000)

are available in the git repository at:


  git://people.freedesktop.org/~airlied/linux.git drm-fixes

for you to fetch changes up to 2e26c73a1e410448fbd2c0fbd34f06d98eaf8e48:

  Merge branch 'drm-nouveau-fixes' of 
git://git.freedesktop.org/git/nouveau/linux-2.6 into drm-fixes (2012-08-15 
20:31:22 +1000)



Ben Skeggs (2):
  drm/nve0/fifo: add support for the flip completion swmthd
  drm/nouveau/aux: mask off higher bits of auxch index in i2c table entry

Chris Wilson (1):
  drm/i915: Apply post-sync write for pipe control invalidates

Christoph Bumiller (1):
  drm/nvd0/disp: mask off high 16 bit of negative cursor x-coordinate

Daniel Vetter (2):
  drm/i915: ignore eDP bpc settings from vbt
  drm/i915: reorder edp disabling to fix ivb MacBook Air

Dave Airlie (2):
  Merge branch 'drm-intel-fixes' of 
git://people.freedesktop.org/~danvet/drm-intel into drm-fixes
  Merge branch 'drm-nouveau-fixes' of 
git://git.freedesktop.org/git/nouveau/linux-2.6 into drm-fixes

Henrik Rydberg (1):
  drm/nouveau: disable copy engine on NVAF

Jani Nikula (1):
  drm/i915: ensure i2c adapter is all set before adding it

Maarten Lankhorst (1):
  nouveau: fixup scanout enable in nvc0_pm

Maxim Levitsky (1):
  drm/nv86/fifo: suspend fix

Takashi Iwai (1):
  drm/i915: Fix blank panel at reopening lid

 drivers/gpu/drm/i915/intel_display.c|   11 -
 drivers/gpu/drm/i915/intel_dp.c |   14 +--
 drivers/gpu/drm/i915/intel_i2c.c|7 +++---
 drivers/gpu/drm/i915/intel_panel.c  |   13 +++---
 drivers/gpu/drm/i915/intel_ringbuffer.c |   41 +--
 drivers/gpu/drm/nouveau/nouveau_i2c.c   |2 +-
 drivers/gpu/drm/nouveau/nouveau_state.c |1 -
 drivers/gpu/drm/nouveau/nv84_fifo.c |9 +++
 drivers/gpu/drm/nouveau/nvc0_pm.c   |2 +-
 drivers/gpu/drm/nouveau/nvd0_display.c  |2 +-
 drivers/gpu/drm/nouveau/nve0_fifo.c |   37 +---
 11 files changed, 88 insertions(+), 51 deletions(-)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 2/2] powerpc: Uprobes port to powerpc

2012-08-15 Thread Ananth N Mavinakayanahalli
On Thu, Aug 16, 2012 at 07:41:53AM +1000, Benjamin Herrenschmidt wrote:
> On Wed, 2012-08-15 at 18:59 +0200, Oleg Nesterov wrote:
> > On 07/26, Ananth N Mavinakayanahalli wrote:
> > >
> > > From: Ananth N Mavinakayanahalli 
> > >
> > > This is the port of uprobes to powerpc. Usage is similar to x86.
> > 
> > I am just curious why this series was ignored by powerpc maintainers...
> 
> Because it arrived too late for the previous merge window considering my
> limited bandwidth for reviewing things and that nobody else seems to
> have reviewed it :-)
> 
> It's still on track for the next one, and I'm hoping to dedicate most of
> next week going through patches & doing a powerpc -next.

Thanks Ben!

> > Of course I can not review this code, I know nothing about powerpc,
> > but the patches look simple/straightforward.
> > 
> > Paul, Benjamin?
> > 
> > Just one question... Shouldn't arch_uprobe_pre_xol() forbid to probe
> > UPROBE_SWBP_INSN (at least) ?
> > 
> > (I assume that emulate_step() can't handle this case but of course I
> >  do not understand arch/powerpc/lib/sstep.c)
> > 
> > Note that uprobe_pre_sstep_notifier() sets utask->state = UTASK_BP_HIT
> > without any checks. This doesn't look right if it was UTASK_SSTEP...
> > 
> > But again, I do not know what powepc will actually do if we try to
> > single-step over UPROBE_SWBP_INSN.
> 
> Ananth ?

set_swbp() will return -EEXIST to install_breakpoint if we are trying to
put a breakpoint on UPROBE_SWBP_INSN. So, the arch agnostic code itself
takes care of this case... or am I missing something?

However, I see that we need a powerpc specific is_swbp_insn()
implementation since we will have to take care of all the trap variants.

I will need to update the patches based on changes being made by Oleg
and Sebastien for the single-step issues. Will incorporate the powerpc
specific is_swbp_insn() change along with the changes required for the
single-step part and send out the next version.

Ananth

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [discussion]sched: a rough proposal to enable power saving in scheduler

2012-08-15 Thread Alex Shi
On 08/15/2012 10:24 PM, Rakib Mullick wrote:

> On 8/13/12, Alex Shi  wrote:
>> Since there is no power saving consideration in scheduler CFS, I has a
>> very rough idea for enabling a new power saving schema in CFS.
>>
>> It bases on the following assumption:
>> 1, If there are many task crowd in system, just let few domain cpus
>> running and let other cpus idle can not save power. Let all cpu take the
>> load, finish tasks early, and then get into idle. will save more power
>> and have better user experience.
>>
> This assumption indirectly point towards the scheme when performance
> is enabled, isn't it? Cause you're trying to spread the load equally
> amongst all the CPUs.


It is.

> 
>>
>> select_task_rq_fair()
>> {

int powersaving = 0;

>>  for_each_domain(cpu, tmp) {
>>  if (policy == power && tmp_has_capacity &&
>>   tmp->flags & sd_flag) {
>>  sd = tmp;
>>  //It is fine to got cpu in the domain

powersaving = 1;

>>  break;
>>  }
>>  }
>>
>>  while(sd) {
if (policy == power && powersaving == 1)
>>  find_busiest_and_capable_group()
> 
> I'm not sure what find_busiest_and_capable_group() would really be, it
> seems it'll find the busiest and capable group, but isn't it a
> conflict with the first assumption you proposed on your proposal?


This pseudo code missed a power saving workable flag , adding it into
above code should solved your concern.

> 
> Thanks,
> Rakib.


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 00/14] net: info leaks and other bugs

2012-08-15 Thread David Miller
From: Mathias Krause 
Date: Wed, 15 Aug 2012 23:31:43 +0200

> this series fixes quite a bunch of info leaks under net/. There is also
> one NULL pointer deref fix ("dccp: check ccid before..") that could be
> abused for privilege escalation.
> 
> The info leak fixes might be material for stable, too. But I leave the
> decision up to you.
> 
> On request, test code for all (but one) of the issues can be provided.

All applied and queued up for -stable, thanks a lot.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: + lib-vsprintf-optimize-division-by-10000.patch added to -mm tree

2012-08-15 Thread George Spelvin
Thanks for picking this up.  (I'm kind of amazed you found it!)
I was hoping for an ack from Denys Vlasenko, but he hasn't made
any appearances in a while.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] regulator: max8907: Fix n_voltages for MAX8907B SD1

2012-08-15 Thread Axel Lin
For linear voltage mapping, the n_voltages is (max - min) / step + 1

Signed-off-by: Axel Lin 
---
 drivers/regulator/max8907-regulator.c |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/regulator/max8907-regulator.c 
b/drivers/regulator/max8907-regulator.c
index bd3b28b..bdf21a1 100644
--- a/drivers/regulator/max8907-regulator.c
+++ b/drivers/regulator/max8907-regulator.c
@@ -286,7 +286,8 @@ static __devinit int max8907_regulator_probe(struct 
platform_device *pdev)
MAX8907_II2RR_VERSION_REV_B) {
pmic->desc[MAX8907_SD1].min_uV = 637500;
pmic->desc[MAX8907_SD1].uV_step = 12500;
-   pmic->desc[MAX8907_SD1].n_voltages = (1425000 - 637500) / 12500;
+   pmic->desc[MAX8907_SD1].n_voltages =
+   (1425000 - 637500) / 12500 + 1;
}
 
for (i = 0; i < MAX8907_NUM_REGULATORS; i++) {
-- 
1.7.9.5



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] sched: Support compiling out real-time scheduling with REALTIME_SCHED.

2012-08-15 Thread Mike Galbraith
On Wed, 2012-08-15 at 08:10 -0700, Josh Triplett wrote: 
> On Wed, Aug 15, 2012 at 09:12:20AM +0200, Mike Galbraith wrote:
> > On Tue, 2012-08-14 at 13:50 -0700, Trevor Brandt wrote:
> > > diff --git a/init/Kconfig b/init/Kconfig
> > > index 3f42cd6..768dc76 100644
> > > --- a/init/Kconfig
> > > +++ b/init/Kconfig
> > > @@ -27,6 +27,13 @@ config IRQ_WORK
> > >   bool
> > >   depends on HAVE_IRQ_WORK
> > >  
> > > +config REALTIME_SCHED
> > > + bool "Realtime Scheduler" if EXPERT
> > > + default y
> > > + help
> > > +   This option enables support for the realtime scheduler and the
> > > +   corresponding scheduling classes SCHED_FIFO and SCHED_RR.
> > > +
> > >  menu "General setup"
> > >  
> > >  config EXPERIMENTAL
> > 
> > If you inverted that, it could be a proper default n new feature [1].
> 
> Huh.  You mean, DISABLE_REALTIME_SCHED?  How would that help?
> DISABLE_REALTIME_SCHED=n seems like an unnecessary double negative, and
> I see very little precedent for that in Kconfig options.

No, it doesn't change anything.

> > (that SMP could select to greatly simplify RT)
> 
> I hope this isn't a serious suggestion. :)  In any case, that doesn't
> seem like something that should happen in *this* patch, if it should
> happen at all.

Slightly deformed funny-bone.

> > However, if weight loss is the goal, why not go whole hog, and create
> > sched/thin.c containing no lard... or just integrate an existing thin
> > scheduler as a config option?
> 
> Historically, the response to configurable/modular/selectable schedulers
> has been entirely negative, with most responses amounting to "we should
> fix the scheduler we have to work for all workloads", which doesn't seem
> like an unreasonable response to me.
> 
> The kernel also has a *large* number of dependencies on the workings of
> the fair scheduler, and as this patch shows, far fewer on the real-time
> scheduler.
> 
> Given both of the above, writing and integrating an entirely new
> scheduler (*and* dealing with the repeats of old flamewars that would
> ensue after posting it) seems a bit much to ask for a student project.
> :)

I think you could make something more generally useful to size extra
dinky boxen by doing that regardless.  But yeah, the bar for inclusion
might be a _tad_ high ;-)

Maintainers certainly wouldn't find it lovely, but there is some
utility.  I can imagine a single array version of the O(1) scheduler
saving lots of space.  If you made it single queue like BFS (or for that
matter maybe just uses BFS out of the box, dunno) you'd get rid of the
load balancing code as well, so would probably have a small footprint
scheduler without having to axe standard classes that may well be needed
in even size extra dinky boxen.

-Mike

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] sched: Remove AFFINE_WAKEUPS feature flag

2012-08-15 Thread Namhyung Kim
From: Namhyung Kim 

Commit beac4c7e4a1c ("sched: Remove AFFINE_WAKEUPS feature") removed
use of the flag but left the definition. Get rid of it.

Cc: Mike Galbraith 
Signed-off-by: Namhyung Kim 
---
 kernel/sched/features.h | 8 
 1 file changed, 8 deletions(-)

diff --git a/kernel/sched/features.h b/kernel/sched/features.h
index de00a486c5c6..c38f52ea53dd 100644
--- a/kernel/sched/features.h
+++ b/kernel/sched/features.h
@@ -12,14 +12,6 @@ SCHED_FEAT(GENTLE_FAIR_SLEEPERS, true)
 SCHED_FEAT(START_DEBIT, true)
 
 /*
- * Based on load and program behaviour, see if it makes sense to place
- * a newly woken task on the same cpu as the task that woke it --
- * improve cache locality. Typically used with SYNC wakeups as
- * generated by pipes and the like, see also SYNC_WAKEUPS.
- */
-SCHED_FEAT(AFFINE_WAKEUPS, true)
-
-/*
  * Prefer to schedule the task we woke last (assuming it failed
  * wakeup-preemption), since its likely going to consume data we
  * touched, increases cache locality.
-- 
1.7.11.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [v2.6.34-stable 035/165] md: Fix handling for devices from 2TB to 4TB in 0.90 metadata.

2012-08-15 Thread Ben Hutchings
On Thu, 2012-08-16 at 06:46 +1000, NeilBrown wrote:
> On Wed, 15 Aug 2012 15:46:19 -0400 Paul Gortmaker
>  wrote:
> 
> > From: NeilBrown 
> > 
> >---
> > This is a commit scheduled for the next v2.6.34 longterm release.
> > 
> > http://git.kernel.org/?p=linux/kernel/git/paulg/longterm-queue-2.6.34.git
> > If you see a problem with using this for longterm, please comment.
> 
> This patch fixes one problem but unfortunately introduces another.
> The patch for that 'other' should get sent to linus in the next day or so
> after it has had a chance to sit in -next for a bit.
> 
> It can be found at:
>  
> http://neil.brown.name/git?p=md;a=commitdiff;h=30b798a352052b07c924956dda4ce720b00af711
> 
> you could either add that patch, or drop this patch until the next cycle.
[...]

This was already backported to 2.6.32, 2.6.33 and 3.0.  So please change
the last sentence of the commit message for your following fix; it will
be needed for all active stable series.

Ben.

-- 
Ben Hutchings
I say we take off; nuke the site from orbit.  It's the only way to be sure.


signature.asc
Description: This is a digitally signed message part


powerpc/perf: hw breakpoints return ENOSPC

2012-08-15 Thread Michael Neuling
Hi,

I've been trying to get hardware breakpoints with perf to work on POWER7
but I'm getting the following:

  % perf record -e mem:0x1000 true

Error: sys_perf_event_open() syscall returned with 28 (No space left on 
device).  /bin/dmesg may provide additional information.

Fatal: No CONFIG_PERF_EVENTS=y kernel support configured?

  true: Terminated

(FWIW adding -a and it works fine)

Debugging it seems that __reserve_bp_slot() is returning ENOSPC because
it thinks there are no free breakpoint slots on this CPU.

I have a 2 CPUs, so perf userspace is doing two perf_event_open syscalls
to add a counter to each CPU [1].  The first syscall succeeds but the
second is failing.

On this second syscall, fetch_bp_busy_slots() sets slots.pinned to be 1,
despite there being no breakpoint on this CPU.  This is because the call
the task_bp_pinned, checks all CPUs, rather than just the current CPU.
POWER7 only has one hardware breakpoint per CPU (ie. HBP_NUM=1), so we
return ENOSPC.

The following patch fixes this by checking the associated CPU for each
breakpoint in task_bp_pinned.  I'm not familiar with this code, so it's
provided as a reference to the above issue.

Mikey

1. not sure why it doesn't just do one syscall and specify all CPUs, but
that's another issue.  Using two syscalls should work.

diff --git a/kernel/events/hw_breakpoint.c b/kernel/events/hw_breakpoint.c
index bb38c4d..e092daa 100644
--- a/kernel/events/hw_breakpoint.c
+++ b/kernel/events/hw_breakpoint.c
@@ -111,14 +111,16 @@ static unsigned int max_task_bp_pinned(int cpu, enum 
bp_type_idx type)
  * Count the number of breakpoints of the same type and same task.
  * The given event must be not on the list.
  */
-static int task_bp_pinned(struct perf_event *bp, enum bp_type_idx type)
+static int task_bp_pinned(int cpu, struct perf_event *bp, enum bp_type_idx 
type)
 {
struct task_struct *tsk = bp->hw.bp_target;
struct perf_event *iter;
int count = 0;
 
list_for_each_entry(iter, _task_head, hw.bp_list) {
-   if (iter->hw.bp_target == tsk && find_slot_idx(iter) == type)
+   if (iter->hw.bp_target == tsk &&
+   find_slot_idx(iter) == type &&
+   cpu == iter->cpu)
count += hw_breakpoint_weight(iter);
}
 
@@ -141,7 +143,7 @@ fetch_bp_busy_slots(struct bp_busy_slots *slots, struct 
perf_event *bp,
if (!tsk)
slots->pinned += max_task_bp_pinned(cpu, type);
else
-   slots->pinned += task_bp_pinned(bp, type);
+   slots->pinned += task_bp_pinned(cpu, bp, type);
slots->flexible = per_cpu(nr_bp_flexible[type], cpu);
 
return;
@@ -154,7 +156,7 @@ fetch_bp_busy_slots(struct bp_busy_slots *slots, struct 
perf_event *bp,
if (!tsk)
nr += max_task_bp_pinned(cpu, type);
else
-   nr += task_bp_pinned(bp, type);
+   nr += task_bp_pinned(cpu, bp, type);
 
if (nr > slots->pinned)
slots->pinned = nr;
@@ -188,7 +190,7 @@ static void toggle_bp_task_slot(struct perf_event *bp, int 
cpu, bool enable,
int old_idx = 0;
int idx = 0;
 
-   old_count = task_bp_pinned(bp, type);
+   old_count = task_bp_pinned(cpu, bp, type);
old_idx = old_count - 1;
idx = old_idx + weight;
 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3] mmc: card: Skip secure option for MoviNAND.

2012-08-15 Thread Jaehoon Chung
On 08/16/2012 01:09 PM, IAN CHEN wrote:
> MMC_QUIRK_SEC_ERASE_TRIM_BROKEN seems quite clear but I might not use "SEC"
> due to it could be Samsung Electronics Corporation.
I didn't think so.
MMC developers didn't think that SEC means Samsung Electronics Corporation.
Already we used the flags with "_SEC_"
It's no problem.

Best Regards,
Jaehoon Chung
> So, how about MMC_QUIRK_SECDISCARD_BROKEN which was used in
> mmc_blk_issue_secdiscard_rq() naming, the function we skip.
> Or, MMC_QUIRK_SECERASE_SECTRIM_BROKEN?
> 
> Regards,
> Ian
> -Original Message-
> From: Linus Walleij [mailto:linus.wall...@linaro.org] 
> Sent: Tuesday, August 14, 2012 5:07 PM
> To: IAN CHEN
> Cc: c...@laptop.org; linkinj...@gmail.com; adrian.hun...@intel.com;
> subha...@codeaurora.org; linux-...@vger.kernel.org;
> linux-kernel@vger.kernel.org; d.j.s...@samsung.com;
> jongtae22@samsung.com; kyungmin.p...@samsung.com; jh80.ch...@samsung.com
> Subject: Re: [PATCH v3] mmc: card: Skip secure option for MoviNAND.
> 
> On Tue, Aug 14, 2012 at 9:06 AM, IAN CHEN  wrote:
> 
>> +#define MMC_QUIRK_SECURE_MODE_BROKEN (1<<10)   /* Skip secure for
>> erase/trim */
> 
> OK this will work and sorry for being picky, but we are working with RPMB
> support and that's some other "secure mode" so to avoid any
> misuderstandings it's better to name the flag like I proposed,
> MMC_QUIRK_SEC_ERASE_TRIM_BROKEN
> 
> I won't die if this goes in though :-)
> 
> Yours,
> Linus Walleij
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[ANNOUNCE} 3.5-ck1, BFS scheduler v0.24 for linux-3.5

2012-08-15 Thread Con Kolivas
These are patches designed to improve system responsiveness and
interactivity with specific emphasis on the desktop, but suitable to
any commodity hardware workload.

Apply to 3.5.x:
http://ck.kolivas.org/patches/3.0/3.5/3.5-ck1/patch-3.5-ck1.bz2
or
http://ck.kolivas.org/patches/3.0/3.5/3.5-ck1/patch-3.5-ck1.lrz

Broken out tarball:
http://ck.kolivas.org/patches/3.0/3.5/3.5-ck1/3.5-ck1-broken-out.tar.bz2
or
http://ck.kolivas.org/patches/3.0/3.5/3.5-ck1/3.5-ck1-broken-out.tar.lrz

Discrete patches:
http://ck.kolivas.org/patches/3.0/3.5/3.5-ck1/patches/

Latest BFS by itself:
http://ck.kolivas.org/patches/bfs/3.5.0/3.5-sched-bfs-424.patch

Web:
http://kernel.kolivas.org

Code blog when I feel like it:
http://ck-hack.blogspot.com/


This is a resync from 3.4-ck3. However, the broken out tarballs above also 
include the upgradeable rwlocks patch, and a modification of the global 
runqueue in BFS to use the urwlocks. These are NOT applied in the -ck1 patch, 
but can be applied manually at the  end of the series as indicated by the 
series file. It is currently of no demonstrable performance advantage OR 
detriment in its current state, but is code for future development.

Enjoy!
お楽しみください

-- 
-ck
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [PATCH v3] mmc: card: Skip secure option for MoviNAND.

2012-08-15 Thread IAN CHEN
MMC_QUIRK_SEC_ERASE_TRIM_BROKEN seems quite clear but I might not use "SEC"
due to it could be Samsung Electronics Corporation.
So, how about MMC_QUIRK_SECDISCARD_BROKEN which was used in
mmc_blk_issue_secdiscard_rq() naming, the function we skip.
Or, MMC_QUIRK_SECERASE_SECTRIM_BROKEN?

Regards,
Ian
-Original Message-
From: Linus Walleij [mailto:linus.wall...@linaro.org] 
Sent: Tuesday, August 14, 2012 5:07 PM
To: IAN CHEN
Cc: c...@laptop.org; linkinj...@gmail.com; adrian.hun...@intel.com;
subha...@codeaurora.org; linux-...@vger.kernel.org;
linux-kernel@vger.kernel.org; d.j.s...@samsung.com;
jongtae22@samsung.com; kyungmin.p...@samsung.com; jh80.ch...@samsung.com
Subject: Re: [PATCH v3] mmc: card: Skip secure option for MoviNAND.

On Tue, Aug 14, 2012 at 9:06 AM, IAN CHEN  wrote:

> +#define MMC_QUIRK_SECURE_MODE_BROKEN (1<<10)   /* Skip secure for
> erase/trim */

OK this will work and sorry for being picky, but we are working with RPMB
support and that's some other "secure mode" so to avoid any
misuderstandings it's better to name the flag like I proposed,
MMC_QUIRK_SEC_ERASE_TRIM_BROKEN

I won't die if this goes in though :-)

Yours,
Linus Walleij

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


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

2012-08-15 Thread Roland Dreier
On Wed, Aug 15, 2012 at 6:44 PM, Stephen Rothwell  wrote:
> After merging the infiniband tree, today's linux-next build (powerpc
> ppc64_defconfig) failed like this:
>
> drivers/net/ethernet/mellanox/mlx4/mr.c: In function 'mlx4_buddy_init':
> drivers/net/ethernet/mellanox/mlx4/mr.c:134:4: error: implicit declaration of 
> function 'vzalloc' [-Werror=implicit-function-declaration]
> drivers/net/ethernet/mellanox/mlx4/mr.c:134:19: warning: assignment makes 
> pointer from integer without a cast [enabled by default]
> drivers/net/ethernet/mellanox/mlx4/mr.c:148:4: error: implicit declaration of 
> function 'vfree' [-Werror=implicit-function-declaration]
> cc1: some warnings being treated as errors

Thanks, should be fixed in tomorrow's for-next (added include of
).

> See Rule 1 in Documentation/SubmitChecklist.

Heh, but it compiles fine on x86!

 - R.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] SGI XPC fails to load when cpu 0 is out of IRQ resources. -v2

2012-08-15 Thread Robin Holt

On many of our larger systems, CPU 0 has had all of its IRQ resources
consumed before XPC loads.  Worst cases on machines with multiple
10 GigE cards and multiple IB cards have depleted the entire first
socket of IRQs.  This patch makes selecting the node upon which
IRQs are allocated (as well as all the other GRU Message Queue
structures) specifiable as a module load param and has a default
behavior of searching all nodes/cpus for an available resources.

Signed-off-by: Robin Holt 
Cc: sta...@vger.kernel.org

---

-v2 - incorporate review comments from Andrew Morton.

 drivers/misc/sgi-xp/xpc_uv.c |   82 --
 1 files changed, 63 insertions(+), 19 deletions(-)

diff --git a/drivers/misc/sgi-xp/xpc_uv.c b/drivers/misc/sgi-xp/xpc_uv.c
index 87b251a..57a53c1 100644
--- a/drivers/misc/sgi-xp/xpc_uv.c
+++ b/drivers/misc/sgi-xp/xpc_uv.c
@@ -59,6 +59,8 @@ static struct xpc_heartbeat_uv *xpc_heartbeat_uv;
 XPC_NOTIFY_MSG_SIZE_UV)
 #define XPC_NOTIFY_IRQ_NAME"xpc_notify"
 
+static int xpc_mq_node = -1;
+
 static struct xpc_gru_mq_uv *xpc_activate_mq_uv;
 static struct xpc_gru_mq_uv *xpc_notify_mq_uv;
 
@@ -109,11 +111,8 @@ xpc_get_gru_mq_irq_uv(struct xpc_gru_mq_uv *mq, int cpu, 
char *irq_name)
 #if defined CONFIG_X86_64
mq->irq = uv_setup_irq(irq_name, cpu, mq->mmr_blade, mq->mmr_offset,
UV_AFFINITY_CPU);
-   if (mq->irq < 0) {
-   dev_err(xpc_part, "uv_setup_irq() returned error=%d\n",
-   -mq->irq);
+   if (mq->irq < 0)
return mq->irq;
-   }
 
mq->mmr_value = uv_read_global_mmr64(mmr_pnode, mq->mmr_offset);
 
@@ -238,8 +237,9 @@ xpc_create_gru_mq_uv(unsigned int mq_size, int cpu, char 
*irq_name,
mq->mmr_blade = uv_cpu_to_blade_id(cpu);
 
nid = cpu_to_node(cpu);
-   page = alloc_pages_exact_node(nid, GFP_KERNEL | __GFP_ZERO | 
GFP_THISNODE,
-   pg_order);
+   page = alloc_pages_exact_node(nid,
+ GFP_KERNEL | __GFP_ZERO | GFP_THISNODE,
+ pg_order);
if (page == NULL) {
dev_err(xpc_part, "xpc_create_gru_mq_uv() failed to alloc %d "
"bytes of memory on nid=%d for GRU mq\n", mq_size, nid);
@@ -1731,9 +1731,50 @@ static struct xpc_arch_operations xpc_arch_ops_uv = {
.notify_senders_of_disconnect = xpc_notify_senders_of_disconnect_uv,
 };
 
+static int
+xpc_init_mq_node(int nid)
+{
+   int cpu;
+
+   get_online_cpus();
+
+   for_each_cpu(cpu, cpumask_of_node(nid)) {
+   xpc_activate_mq_uv =
+   xpc_create_gru_mq_uv(XPC_ACTIVATE_MQ_SIZE_UV, nid,
+XPC_ACTIVATE_IRQ_NAME,
+xpc_handle_activate_IRQ_uv);
+   if (!IS_ERR(xpc_activate_mq_uv))
+   break;
+   }
+   if (IS_ERR(xpc_activate_mq_uv)) {
+   put_online_cpus();
+   return PTR_ERR(xpc_activate_mq_uv);
+   }
+
+   for_each_cpu(cpu, cpumask_of_node(nid)) {
+   xpc_notify_mq_uv =
+   xpc_create_gru_mq_uv(XPC_NOTIFY_MQ_SIZE_UV, nid,
+XPC_NOTIFY_IRQ_NAME,
+xpc_handle_notify_IRQ_uv);
+   if (!IS_ERR(xpc_notify_mq_uv))
+   break;
+   }
+   if (IS_ERR(xpc_notify_mq_uv)) {
+   xpc_destroy_gru_mq_uv(xpc_activate_mq_uv);
+   put_online_cpus();
+   return PTR_ERR(xpc_notify_mq_uv);
+   }
+
+   put_online_cpus();
+   return 0;
+}
+
 int
 xpc_init_uv(void)
 {
+   int nid;
+   int ret = 0;
+
xpc_arch_ops = xpc_arch_ops_uv;
 
if (sizeof(struct xpc_notify_mq_msghdr_uv) > XPC_MSG_HDR_MAX_SIZE) {
@@ -1742,21 +1783,21 @@ xpc_init_uv(void)
return -E2BIG;
}
 
-   xpc_activate_mq_uv = xpc_create_gru_mq_uv(XPC_ACTIVATE_MQ_SIZE_UV, 0,
- XPC_ACTIVATE_IRQ_NAME,
- xpc_handle_activate_IRQ_uv);
-   if (IS_ERR(xpc_activate_mq_uv))
-   return PTR_ERR(xpc_activate_mq_uv);
+   if (xpc_mq_node < 0)
+   for_each_online_node(nid) {
+   ret = xpc_init_mq_node(nid);
 
-   xpc_notify_mq_uv = xpc_create_gru_mq_uv(XPC_NOTIFY_MQ_SIZE_UV, 0,
-   XPC_NOTIFY_IRQ_NAME,
-   xpc_handle_notify_IRQ_uv);
-   if (IS_ERR(xpc_notify_mq_uv)) {
-   xpc_destroy_gru_mq_uv(xpc_activate_mq_uv);
-   return PTR_ERR(xpc_notify_mq_uv);
-   }
+   if (!ret)
+   break;
+   }
+   else
+  

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

2012-08-15 Thread Stephen Rothwell
Hi all,

Today's linux-next merge of the kvm tree got a conflict in
arch/s390/include/asm/processor.h between commit 3c011c612acb
("s390/bpf,jit: BPF Just In Time compiler for s390") from the s390 tree
and commit 9b7fb990e080 ("s390, /dis: Instruction decoding interface") from
the kvm tree.

Just context changes.  I fixed it up (see below) and can carry the fix as
necessary.
-- 
Cheers,
Stephen Rothwells...@canb.auug.org.au

diff --cc arch/s390/include/asm/processor.h
index d4477ba,eac4fb5..000
--- a/arch/s390/include/asm/processor.h
+++ b/arch/s390/include/asm/processor.h
@@@ -140,7 -140,7 +140,8 @@@ extern int kernel_thread(int (*fn)(voi
  extern unsigned long thread_saved_pc(struct task_struct *t);
  
  extern void show_code(struct pt_regs *regs);
 +extern void print_fn_code(unsigned char *code, unsigned long len);
+ extern int insn_to_mnemonic(unsigned char *instruction, char buf[8]);
  
  unsigned long get_wchan(struct task_struct *p);
  #define task_pt_regs(tsk) ((struct pt_regs *) \


pgpkcd7l08Tpw.pgp
Description: PGP signature


Re: [PATCH V2] MIPS: Fix poweroff failure when HOTPLUG_CPU configured.

2012-08-15 Thread Huacai Chen
On Tue, Aug 14, 2012 at 7:48 PM, Ralf Baechle  wrote:
> On Mon, Aug 13, 2012 at 08:52:24PM +0800, Huacai Chen wrote:
>
>> When poweroff machine, kernel_power_off() call disable_nonboot_cpus().
>> And if we have HOTPLUG_CPU configured, disable_nonboot_cpus() is not an
>> empty function but attempt to actually disable the nonboot cpus. Since
>> system state is SYSTEM_POWER_OFF, play_dead() won't be called and thus
>> disable_nonboot_cpus() hangs. Therefore, we make this patch to avoid
>> poweroff failure.
>
>> diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
>> index e9a5fd7..69b17a9 100644
>> --- a/arch/mips/kernel/process.c
>> +++ b/arch/mips/kernel/process.c
>> @@ -72,9 +72,7 @@ void __noreturn cpu_idle(void)
>>   }
>>   }
>>  #ifdef CONFIG_HOTPLUG_CPU
>> - if (!cpu_online(cpu) && !cpu_isset(cpu, cpu_callin_map) &&
>> - (system_state == SYSTEM_RUNNING ||
>> -  system_state == SYSTEM_BOOTING))
>> + if (!cpu_online(cpu) && !cpu_isset(cpu, cpu_callin_map))
>
> Looks good - but I'm wondering if the "!cpu_isset(cpu, cpu_callin_map)"
> can be removed as well?
I removed "!cpu_isset(cpu, cpu_callin_map)" and it works well on
Loongson, but I don't know whether it will affect cavium-octeon...

>
> Also, which -stable branches is this patch applicable?
>
>   Ralf
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2 06/11] memcg: kmem controller infrastructure

2012-08-15 Thread Greg Thelen
On Wed, Aug 15 2012, Glauber Costa wrote:

> On 08/15/2012 09:12 PM, Greg Thelen wrote:
>> On Wed, Aug 15 2012, Glauber Costa wrote:
>> 
>>> On 08/15/2012 08:38 PM, Greg Thelen wrote:
 On Wed, Aug 15 2012, Glauber Costa wrote:

> On 08/14/2012 10:58 PM, Greg Thelen wrote:
>> On Mon, Aug 13 2012, Glauber Costa wrote:
>>
>> +WARN_ON(mem_cgroup_is_root(memcg));
>> +size = (1 << order) << PAGE_SHIFT;
>> +memcg_uncharge_kmem(memcg, size);
>> +mem_cgroup_put(memcg);
 Why do we need ref-counting here ? kmem res_counter cannot work as
 reference ?
>>> This is of course the pair of the mem_cgroup_get() you commented on
>>> earlier. If we need one, we need the other. If we don't need one, we
>>> don't need the other =)
>>>
>>> The guarantee we're trying to give here is that the memcg structure will
>>> stay around while there are dangling charges to kmem, that we decided
>>> not to move (remember: moving it for the stack is simple, for the slab
>>> is very complicated and ill-defined, and I believe it is better to treat
>>> all kmem equally here)
>>
>> By keeping memcg structures hanging around until the last referring kmem
>> page is uncharged do such zombie memcg each consume a css_id and thus
>> put pressure on the 64k css_id space?  I imagine in pathological cases
>> this would prevent creation of new cgroups until these zombies are
>> dereferenced.
>
> Yes, but although this patch makes it more likely, it doesn't introduce
> that. If the tasks, for instance, grab a reference to the cgroup dentry
> in the filesystem (like their CWD, etc), they will also keep the cgroup
> around.

 Fair point.  But this doesn't seems like a feature.  It's probably not
 needed initially, but what do you think about creating a
 memcg_kernel_context structure which is allocated when memcg is
 allocated?  Kernel pages charged to a memcg would have
 page_cgroup->mem_cgroup=memcg_kernel_context rather than memcg.  This
 would allow the mem_cgroup and its css_id to be deleted when the cgroup
 is unlinked from cgroupfs while allowing for the active kernel pages to
 continue pointing to a valid memcg_kernel_context.  This would be a
 reference counted structure much like you are doing with memcg.  When a
 memcg is deleted the memcg_kernel_context would be linked into its
 surviving parent memcg.  This would avoid needing to visit each kernel
 page.
>>>
>>> You need more, you need at the res_counters to stay around as well. And
>>> probably other fields.
>> 
>> I am not sure the res_counters would need to stay around.  Once a
>> memcg_kernel_context has been reparented, then any future kernel page
>> uncharge calls will uncharge the parent res_counter.
>
> Well, if you hold the memcg due to a reference, like in the dentry case,
> then fine. But if this is a dangling charge, as will be the case with
> the slab, then you have to uncharge it.
>
> An arbitrary number of parents might have been deleted as well, so you
> need to transverse them all until you reach a live parent to uncharge from.

I was thinking that each time a memcg is deleted move the
memcg_kernel_context from the victim memcg to its parent.  When moving,
also update the context to refer to the parent and link context to
parent:
  for_each_kernel_context(kernel_context, memcg) {
kernel_context->memcg = memcg->parent;
list_add(_context->list, >parent->kernel_contexts);
  }

Whenever pages referring to a memcg_kernel_context are uncharged they
will uncharge the nearest surviving parent memcg.

> To do that, your counters have to be still alive.

The counters of nearest surviving parent will be alive and pointed to by
memcg_kernel_context->memcg.

>>> So my fear here is that as you add fields to that structure, you can
>>> defeat a bit the goal of reducing memory consumption. Still leaves the
>>> css space, yes. But by doing this we can introduce some subtle bugs by
>>> having a field in the wrong structure.
>>>
>>> Did you observe that to be a big problem in your systems?
>> 
>> No I have not seen this yet.  But our past solutions have reparented
>> kmem_cache's to root memcg so we have been avoiding zombie memcg.  My
>> concerns with your approach are just a suspicion because we have been
>> experimenting with accounting of even more kernel memory (e.g. vmalloc,
>> kernel stacks, page tables).  As the scope of such accounting grows the
>> chance of long lived charged pages grows and thus the chance of zombies
>> which exhaust the css_id space grows.
>
> Well, since we agree this can all be done under the hood, I'd say let's
> wait until a problem actually exists, since the solution is likely to be
> a bit convoluted...
>
> I personally believe that if won't have a lot of task movement, most of
> the data will go away as the cgroup dies. The remainder 

Re: [discussion]sched: a rough proposal to enable power saving in scheduler

2012-08-15 Thread Alex Shi
On 08/15/2012 10:43 PM, Peter Zijlstra wrote:

> On Wed, 2012-08-15 at 15:15 +0200, Borislav Petkov wrote:
>> On Wed, Aug 15, 2012 at 01:05:38PM +0200, Peter Zijlstra wrote:
>>> On Mon, 2012-08-13 at 20:21 +0800, Alex Shi wrote:
 Since there is no power saving consideration in scheduler CFS, I has a
 very rough idea for enabling a new power saving schema in CFS.
>>>
>>> Adding Thomas, he always delights poking holes in power schemes.
>>>
 It bases on the following assumption:
 1, If there are many task crowd in system, just let few domain cpus
 running and let other cpus idle can not save power. Let all cpu take the
 load, finish tasks early, and then get into idle. will save more power
 and have better user experience.
>>>
>>> I'm not sure this is a valid assumption. I've had it explained to me by
>>> various people that race-to-idle isn't always the best thing. It has to
>>> do with the cost of switching power states and the duration of execution
>>> and other such things.
>>
>> I think what he means here is that we might want to let all cores on
>> the node (i.e., domain) finish and then power down the whole node which
>> should bring much more power savings than letting a subset of the cores
>> idle. Alex?
> 
> Sure we can do that.
> 
>>> So I'd leave the currently implemented scheme as performance, and I
>>> don't think the above describes the current state.
>>>
} else if (schedule policy == power)
move tasks from busiest group to
idlest group until busiest is just full
of capacity.
//the busiest group can balance
//internally after next time LB,
>>>
>>> There's another thing we need to do, and that is collect tasks in a
>>> minimal amount of power domains.
>>
>> Yep.
>>
>> Btw, what heuristic would tell here when a domain overflows and another
>> needs to get woken? Combined load of the whole domain?
>>
>> And if I absolutely positively don't want a node to wake up, do I
>> hotplug its cores off or are we going to have a way to tell the
>> scheduler to overcommit the non-idle domains and spread the tasks only
>> among them.
>>
>> I'm thinking of short bursts here where it would be probably beneficial
>> to let the tasks rather wait runnable for a while then wake up the next
>> node and waste power...
> 
> I was thinking of a utilization measure made of per-task weighted
> runnable averages. This should indeed cover that case and we'll overflow
> when on average there is no (significant) idle time over a period longer
> than the averaging period.


It's also a good idea. :)

> 
> Anyway, I'm not too set on this and I'm very sure we can tweak this ad
> infinitum, so starting with something relatively simple that works for
> most is preferred.
> 
> As already stated, I think some of the Linaro people actually played
> around with something like this based on PJTs patches.


Vincent, would you like to introduce more?
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH V5 13/18] drm: Define SAREA_MAX for Loongson (PageSize = 16KB).

2012-08-15 Thread Huacai Chen
On Thu, Aug 16, 2012 at 9:58 AM, Matt Turner  wrote:
> On Sat, Aug 11, 2012 at 2:32 AM, Huacai Chen  wrote:
>> Signed-off-by: Huacai Chen 
>> Signed-off-by: Hongliang Tao 
>> Signed-off-by: Hua Yan 
>> Cc: dri-de...@lists.freedesktop.org
>> ---
>>  include/drm/drm_sarea.h |2 ++
>>  1 files changed, 2 insertions(+), 0 deletions(-)
>>
>> diff --git a/include/drm/drm_sarea.h b/include/drm/drm_sarea.h
>> index ee5389d..1d1a858 100644
>> --- a/include/drm/drm_sarea.h
>> +++ b/include/drm/drm_sarea.h
>> @@ -37,6 +37,8 @@
>>  /* SAREA area needs to be at least a page */
>>  #if defined(__alpha__)
>>  #define SAREA_MAX   0x2000U
>> +#elif defined(__mips__)
>> +#define SAREA_MAX   0x4000U
>>  #elif defined(__ia64__)
>>  #define SAREA_MAX   0x1U   /* 64kB */
>>  #else
>> --
>> 1.7.7.3
>
> SAREA is a DRI-1 concept. The Radeon drivers you're using is DRI-2, so
> what do you need this for? All the DRI-1 drivers have been removed
> from Mesa, so I think the answer is nothing.

This patch will be drop, thank you.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH V5 09/18] MIPS: Loongson: Add swiotlb to support big memory (>4GB).

2012-08-15 Thread Huacai Chen
On Thu, Aug 16, 2012 at 4:24 AM, Ralf Baechle  wrote:
> On Mon, Aug 13, 2012 at 01:54:47PM -0400, Konrad Rzeszutek Wilk wrote:
>
>> > +static void *loongson_dma_alloc_coherent(struct device *dev, size_t size,
>> > +   dma_addr_t *dma_handle, gfp_t gfp, struct 
>> > dma_attrs *attrs)
>> > +{
>> > +   void *ret;
>> > +
>> > +   if (dma_alloc_from_coherent(dev, size, dma_handle, ))
>> > +   return ret;
>> > +
>> > +   /* ignore region specifiers */
>> > +   gfp &= ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM);
>> > +
>> > +#ifdef CONFIG_ZONE_DMA
>> > +   if (dev == NULL)
>> > +   gfp |= __GFP_DMA;
>>
>> When would this happen? dev == NULL?
>
> A legacy (ISA) device driver.  Some of the Loongsons have some kind of
> southbridge which incorporates legacy devices though of the top of my
> head I'm not sure which if any of these are actually being used.  Huacai?
ISA driver isn't used now, but I think keep "dev == NULL" here has no
side effect.
BTW, "dev == NULL" only happend in ISA case?  I use "grep
pci_alloc_consistent drivers/ -rwI | grep NULL" and also get some
lines.

>
>> > +   else if (dev->coherent_dma_mask <= DMA_BIT_MASK(24))
>> > +   gfp |= __GFP_DMA;
>> > +   else
>> > +#endif
>> > +#ifdef CONFIG_ZONE_DMA32
>> > +   if (dev->coherent_dma_mask <= DMA_BIT_MASK(32))
>> > +   gfp |= __GFP_DMA32;
>> > +   else
>>
>> Why the 'else'
>> > +#endif
>> > +   ;
>>
>> why?
>> > +   gfp |= __GFP_NORETRY;
>> > +
>> > +   ret = swiotlb_alloc_coherent(dev, size, dma_handle, gfp);
>> > +   mb();
>>
>> Why the 'mb()' ? Can you just do
>>   return swiotlb_alloc_coherent(...)
>>
>> > +   return ret;
>> > +}
>> > +
>> > +static void loongson_dma_free_coherent(struct device *dev, size_t size,
>> > +   void *vaddr, dma_addr_t dma_handle, struct 
>> > dma_attrs *attrs)
>> > +{
>> > +   int order = get_order(size);
>> > +
>> > +   if (dma_release_from_coherent(dev, order, vaddr))
>> > +   return;
>> > +
>> > +   swiotlb_free_coherent(dev, size, vaddr, dma_handle);
>> > +}
>> > +
>> > +static dma_addr_t loongson_dma_map_page(struct device *dev, struct page 
>> > *page,
>> > +   unsigned long offset, size_t size,
>> > +   enum dma_data_direction dir,
>> > +   struct dma_attrs *attrs)
>> > +{
>> > +   dma_addr_t daddr = swiotlb_map_page(dev, page, offset, size,
>> > +   dir, attrs);
>> > +   mb();
>>
>> Please do 'return swiotlb_map_page(..)'..
>>
>> But if you are doing that why don't you just set the dma_ops.map_page = 
>> swiotlb_map_page
>> ?
>>
>>
>> > +   return daddr;
>> > +}
>> > +
>> > +static int loongson_dma_map_sg(struct device *dev, struct scatterlist *sg,
>> > +   int nents, enum dma_data_direction dir,
>> > +   struct dma_attrs *attrs)
>> > +{
>> > +   int r = swiotlb_map_sg_attrs(dev, sg, nents, dir, NULL);
>> > +   mb();
>> > +
>> > +   return r;
>> > +}
>> > +
>> > +static void loongson_dma_sync_single_for_device(struct device *dev,
>> > +   dma_addr_t dma_handle, size_t size,
>> > +   enum dma_data_direction dir)
>> > +{
>> > +   swiotlb_sync_single_for_device(dev, dma_handle, size, dir);
>> > +   mb();
>> > +}
>> > +
>> > +static void loongson_dma_sync_sg_for_device(struct device *dev,
>> > +   struct scatterlist *sg, int nents,
>> > +   enum dma_data_direction dir)
>> > +{
>> > +   swiotlb_sync_sg_for_device(dev, sg, nents, dir);
>> > +   mb();
>> > +}
>> > +
>>
>> I am not really sure why you have these extra functions, when you could
>> just modify the dma_ops to point to the swiotlb ones
>>
>> > +static dma_addr_t loongson_unity_phys_to_dma(struct device *dev, 
>> > phys_addr_t paddr)
>> > +{
>> > +   return (paddr < 0x1000) ?
>> > +   (paddr | 0x8000) : paddr;
>> > +}
>> > +
>> > +static phys_addr_t loongson_unity_dma_to_phys(struct device *dev, 
>> > dma_addr_t daddr)
>> > +{
>> > +   return (daddr < 0x9000 && daddr >= 0x8000) ?
>> > +   (daddr & 0x0fff) : daddr;
>> > +}
>> > +
>> > +struct loongson_dma_map_ops {
>> > +   struct dma_map_ops dma_map_ops;
>> > +   dma_addr_t (*phys_to_dma)(struct device *dev, phys_addr_t paddr);
>> > +   phys_addr_t (*dma_to_phys)(struct device *dev, dma_addr_t daddr);
>> > +};
>> > +
>> > +dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
>> > +{
>> > +   struct loongson_dma_map_ops *ops = container_of(get_dma_ops(dev),
>> > +   struct loongson_dma_map_ops, 
>> > dma_map_ops);
>> > +
>> > +   return ops->phys_to_dma(dev, paddr);
>> > +}
>> > +
>> > +phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
>> > +{
>> > +   struct loongson_dma_map_ops *ops = container_of(get_dma_ops(dev),
>> > +   struct 

Repeated fork() causes SLAB to grow without bound

2012-08-15 Thread Daniel Forrest
I'm hoping someone has seen this before...

I've been trying to track down a performance problem with Linux 3.0.4.
The symptom is system-mode load increasing over time while user-mode
load remains constant while running a data ingest/processing program.

Looking at /proc/meminfo I noticed SUnreclaim increasing steadily.

Looking at /proc/slabinfo I noticed anon_vma and anon_vma_chain also
increasing steadily.

I was able to generate a simple test program that will cause this:

---

#include 

int main(int argc, char *argv[])
{
   pid_t pid;

   while (1) {
  pid = fork();
  if (pid == -1) {
 /* error */
 return 1;
  }
  if (pid) {
 /* parent */
 sleep(2);
 break;
  }
  else {
 /* child */
 sleep(1);
  }
   }
   return 0;
}

---

In the actual program (running as a daemon), a child is reading data
while its parent is processing the previously read data.  At any time
there are only a few processes in existence, with older processes
exiting and new processes being fork()ed.  Killing the program frees
the slab usage.

I patched the kernel to 3.0.40, but the problem remains.  I also
compiled with slab debugging and can see that the growth of anon_vma
and anon_vma_chain is due to anon_vma_clone/anon_vma_fork.

Is this a known issue?  Is it fixed in a later release?

Thanks,

-- 
Daniel K. Forrest   Space Science and
dan.forr...@ssec.wisc.edu   Engineering Center
(608) 890 - 0558University of Wisconsin, Madison
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


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

2012-08-15 Thread Stephen Rothwell
Hi all,

After merging the tip tree, today's linux-next build (powerpc
ppc64_defconfig) failed like this:

drivers/infiniband/hw/ehca/ehca_irq.c: In function 'find_next_online_cpu':
drivers/infiniband/hw/ehca/ehca_irq.c:672:2: error: expected ';' before 
'spin_unlock_irqrestore'

Caused by commit 81942621bd6b ("infiniband: Ehca: Use hotplug thread
infrastructure").

I have used the tip tree from next-20120814 for today.
-- 
Cheers,
Stephen Rothwells...@canb.auug.org.au


pgpsOxDfJLcsq.pgp
Description: PGP signature


Re: [discussion]sched: a rough proposal to enable power saving in scheduler

2012-08-15 Thread Alex Shi
On 08/15/2012 09:15 PM, Borislav Petkov wrote:

> On Wed, Aug 15, 2012 at 01:05:38PM +0200, Peter Zijlstra wrote:
>> On Mon, 2012-08-13 at 20:21 +0800, Alex Shi wrote:
>>> Since there is no power saving consideration in scheduler CFS, I has a
>>> very rough idea for enabling a new power saving schema in CFS.
>>
>> Adding Thomas, he always delights poking holes in power schemes.
>>
>>> It bases on the following assumption:
>>> 1, If there are many task crowd in system, just let few domain cpus
>>> running and let other cpus idle can not save power. Let all cpu take the
>>> load, finish tasks early, and then get into idle. will save more power
>>> and have better user experience.
>>
>> I'm not sure this is a valid assumption. I've had it explained to me by
>> various people that race-to-idle isn't always the best thing. It has to
>> do with the cost of switching power states and the duration of execution
>> and other such things.
> 
> I think what he means here is that we might want to let all cores on
> the node (i.e., domain) finish and then power down the whole node which
> should bring much more power savings than letting a subset of the cores
> idle. Alex?


Yes, that is my assumption. If my memory service me well. The idea get
from Suresh when introducing the old power saving schema.

> 
> [ … ]
> 
>> So I'd leave the currently implemented scheme as performance, and I
>> don't think the above describes the current state.
>>
>>> } else if (schedule policy == power)
>>> move tasks from busiest group to
>>> idlest group until busiest is just full
>>> of capacity.
>>> //the busiest group can balance
>>> //internally after next time LB,
>>
>> There's another thing we need to do, and that is collect tasks in a
>> minimal amount of power domains.
> 
> Yep.
> 
> Btw, what heuristic would tell here when a domain overflows and another
> needs to get woken? Combined load of the whole domain?
> 
> And if I absolutely positively don't want a node to wake up, do I
> hotplug its cores off or are we going to have a way to tell the
> scheduler to overcommit the non-idle domains and spread the tasks only
> among them.


You are right. here using the least load non-idle group is better than
idlest.

> 
> I'm thinking of short bursts here where it would be probably beneficial
> to let the tasks rather wait runnable for a while then wake up the next
> node and waste power...


True. Maybe that is Peter mentioned '2*capacity' reason?

> 
> Thanks.
> 


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [discussion]sched: a rough proposal to enable power saving in scheduler

2012-08-15 Thread Alex Shi

Appreciate for your so detailed review and comments!

On 08/15/2012 07:05 PM, Peter Zijlstra wrote:

> On Mon, 2012-08-13 at 20:21 +0800, Alex Shi wrote:
>> Since there is no power saving consideration in scheduler CFS, I has a
>> very rough idea for enabling a new power saving schema in CFS.
> 
> Adding Thomas, he always delights poking holes in power schemes.
> 
>> It bases on the following assumption:
>> 1, If there are many task crowd in system, just let few domain cpus
>> running and let other cpus idle can not save power. Let all cpu take the
>> load, finish tasks early, and then get into idle. will save more power
>> and have better user experience.
> 
> I'm not sure this is a valid assumption. I've had it explained to me by
> various people that race-to-idle isn't always the best thing. It has to
> do with the cost of switching power states and the duration of execution
> and other such things.


Uh, the info will be kept in my mind. Thanks!

> 
>> 2, schedule domain, schedule group perfect match the hardware, and
>> the power consumption unit. So, pull tasks out of a domain means
>> potentially this power consumption unit idle.
> 
> I'm not sure I understand what you're saying, sorry.


Sorry.
this assumption is that power domain can be matched into current SDs.

So the 'pack' power scheme can simply minimise the active power domain
via minimise active scheduler domains.

> 
>> So, according Peter mentioned in commit 8e7fbcbc22c(sched: Remove stale
>> power aware scheduling), this proposal will adopt the
>> sched_balance_policy concept and use 2 kind of policy: performance, power.
> 
> Yay, ideally we'd also provide a 3rd option: auto, which simply switches
> between the two based on AC/BAT, UPS status and simple things like that.
> But this seems like a later concern, you have to have something to pick
> between before you can pick :-)


Sure. let's build up the performance/power first. :)

> 
>> And in scheduling, 2 place will care the policy, load_balance() and in
>> task fork/exec: select_task_rq_fair().
> 
> ack


Thanks!

> 
>> Here is some pseudo code try to explain the proposal behaviour in
>> load_balance() and select_task_rq_fair();
> 
> Oh man.. A few words outlining the general idea would've been nice.
> 
>> load_balance() {
>>  update_sd_lb_stats(); //get busiest group, idlest group data.
>>
>>  if (sd->nr_running > sd's capacity) {
>>  //power saving policy is not suitable for
>>  //this scenario, it runs like performance policy
>>  mv tasks from busiest cpu in busiest group to
>>  idlest  cpu in idlest group;
> 
> Once upon a time we talked about adding a factor to the capacity for
> this. So say you'd allow 2*capacity before overflowing and waking
> another power group.


Sorry, I missed this. and didn't find detailed in lkml and google. Could
any one like to give the related URL if convenience?

> 
> But I think we should not go on nr_running here, PJTs per-entity load
> tracking stuff gives us much better measures -- also, repost that series
> already Paul! :-)


Agree for the better solution, will study Paul's post. :)

> 
> Also, I'm not sure this is entirely correct, the thing you want to do
> for power aware stuff is to minimize the number of active power domains,
> this means you don't want idlest, you want least busy non-idle.


Sure. the least busy non-idle is better target.

> 
>>  } else {// the sd has enough capacity to hold all tasks.
>>  if (sg->nr_running > sg's capacity) {
>>  //imbalanced between groups
>>  if (schedule policy == performance) {
>>  //when 2 busiest group at same busy
>>  //degree, need to prefer the one has
>>  // softest group??
>>  move tasks from busiest group to
>>  idletest group;
> 
> So I'd leave the currently implemented scheme as performance, and I
> don't think the above describes the current state.


Sure. it's better to keep current state as performance. Here is a little
difference is it try to find the more suitable balance cpu in idlest
group the usual this_cpu.

But maybe the current solution is better.

> 
>>  } else if (schedule policy == power)
>>  move tasks from busiest group to
>>  idlest group until busiest is just full
>>  of capacity.
>>  //the busiest group can balance
>>  //internally after next time LB,
> 
> There's another thing we need to do, and that is collect tasks in a
> minimal amount of power domains. The old code (that got deleted) did
> something like that, you can revive some of the that code if needed -- I
> just killed everything to be able to start with a clean slate.


Thanks for reminder.
And 

[PATCH V3 5/5] arm: mmp: make all SOCs use common clock by default

2012-08-15 Thread Chao Xie
From: Chao Xie 

Signed-off-by: Chao Xie 
---
 arch/arm/mach-mmp/Kconfig |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-mmp/Kconfig b/arch/arm/mach-mmp/Kconfig
index 7fddd01..d697d07 100644
--- a/arch/arm/mach-mmp/Kconfig
+++ b/arch/arm/mach-mmp/Kconfig
@@ -108,18 +108,21 @@ endmenu
 config CPU_PXA168
bool
select CPU_MOHAWK
+   select COMMON_CLK
help
  Select code specific to PXA168
 
 config CPU_PXA910
bool
select CPU_MOHAWK
+   select COMMON_CLK
help
  Select code specific to PXA910
 
 config CPU_MMP2
bool
select CPU_PJ4
+   select COMMON_CLK
help
  Select code specific to MMP2. MMP2 is ARMv7 compatible.
 
-- 
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH V3 4/5] clk: mmp: add clock definition for mmp2

2012-08-15 Thread Chao Xie
From: Chao Xie 

Initialize the clocks for mmp2

Signed-off-by: Chao Xie 
---
 drivers/clk/mmp/Makefile   |1 +
 drivers/clk/mmp/clk-mmp2.c |  544 
 2 files changed, 545 insertions(+), 0 deletions(-)
 create mode 100644 drivers/clk/mmp/clk-mmp2.c

diff --git a/drivers/clk/mmp/Makefile b/drivers/clk/mmp/Makefile
index 6160ac2..392d780 100644
--- a/drivers/clk/mmp/Makefile
+++ b/drivers/clk/mmp/Makefile
@@ -6,3 +6,4 @@ obj-y += clk-apbc.o clk-apmu.o clk-frac.o
 
 obj-$(CONFIG_CPU_PXA168) += clk-pxa168.o
 obj-$(CONFIG_CPU_PXA910) += clk-pxa910.o
+obj-$(CONFIG_CPU_MMP2) += clk-mmp2.o
diff --git a/drivers/clk/mmp/clk-mmp2.c b/drivers/clk/mmp/clk-mmp2.c
new file mode 100644
index 000..13f30f8
--- /dev/null
+++ b/drivers/clk/mmp/clk-mmp2.c
@@ -0,0 +1,544 @@
+/*
+ * mmp clock framework source file
+ *
+ * Copyright (C) 2012 Marvell
+ * Chao Xie 
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include "clk.h"
+
+#define APBC_RTC   0x0
+#define APBC_TWSI0 0x4
+#define APBC_TWSI1 0x8
+#define APBC_TWSI2 0xc
+#define APBC_TWSI3 0x10
+#define APBC_TWSI4 0x7c
+#define APBC_TWSI5 0x80
+#define APBC_KPC   0x18
+#define APBC_UART0 0x2c
+#define APBC_UART1 0x30
+#define APBC_UART2 0x34
+#define APBC_UART3 0x88
+#define APBC_GPIO  0x38
+#define APBC_PWM0  0x3c
+#define APBC_PWM1  0x40
+#define APBC_PWM2  0x44
+#define APBC_PWM3  0x48
+#define APBC_SSP0  0x50
+#define APBC_SSP1  0x54
+#define APBC_SSP2  0x58
+#define APBC_SSP3  0x5c
+#define APMU_SDH0  0x54
+#define APMU_SDH1  0x58
+#define APMU_SDH2  0xe8
+#define APMU_SDH3  0xec
+#define APMU_USB   0x5c
+#define APMU_DISP0 0x4c
+#define APMU_DISP1 0x110
+#define APMU_CCIC0 0x50
+#define APMU_CCIC1 0xf4
+#define MPMU_UART_PLL  0x14
+
+static DEFINE_SPINLOCK(clk_lock);
+
+enum {
+   clk32, vctcxo, pll1, usb_pll, pll2, pll1_2, pll1_4, pll1_8, pll1_16,
+   pll1_20, pll1_3, pll1_6, pll1_12, pll2_2, pll2_4, pll2_8, pll2_16,
+   pll2_3, pll2_6, pll2_12, vctcxo_2, vctcxo_4, uart_pll, twsi0, twsi1,
+   twsi2, twsi3, twsi4, twsi5, gpio, kpc, rtc, pwm0, pwm1, pwm2, pwm3,
+   uart0_mux, uart0, uart1_mux, uart1, uart2_mux, uart2, uart3_mux,
+   uart3, ssp0_mux, ssp0, ssp1_mux, ssp1, ssp2_mux, ssp2, ssp3_mux,
+   ssp3, sdh_mux, sdh_div, sdh0, sdh1, sdh2, sdh3, usb, disp0_mux,
+   disp0_div, disp0, disp0_sphy_div, disp0_sphy, disp1_mux, disp1_div,
+   disp1, ccic_arbiter, ccic0_mux, ccic0_div, ccic0, ccic0_phy,
+   ccic0_sphy_div, ccic0_sphy, ccic1_mux, ccic1_div, ccic1, ccic1_phy,
+   ccic1_sphy_div, ccic1_sphy, clk_max
+};
+
+static struct clk_factor_masks uart_factor_masks = {
+   .factor = 2,
+   .num_mask = 0x1fff,
+   .den_mask = 0x1fff,
+   .num_shift = 16,
+   .den_shift = 0,
+};
+
+static struct clk_factor_tbl uart_factor_tbl[] = {
+   {.num = 14634, .den = 2165},/*14.745MHZ */
+   {.num = 3521, .den = 689},  /*19.23MHZ */
+   {.num = 9679, .den = 5728}, /*58.9824MHZ */
+   {.num = 15850, .den = 9451},/*59.429MHZ */
+};
+
+static const char *uart_parent[] = {"uart_pll", "vctcxo"};
+static const char *ssp_parent[] =
+   {"vctcxo_4", "vctcxo_2", "vctcxo", "pll1_16"};
+static const char *sdh_parent[] = {"pll1_4", "pll2", "usb_pll", "pll1"};
+static const char *disp_parent[] = {"pll1", "pll1_16", "pll2", "vctcxo"};
+static const char *ccic_parent[] = {"pll1_2", "pll1_16", "vctcxo"};
+
+void __init mmp2_clk_init(void)
+{
+   struct clk *clocks[clk_max];
+   void __iomem *mpmu_base;
+   void __iomem *apmu_base;
+   void __iomem *apbc_base;
+
+   mpmu_base = ioremap(APB_PHYS_BASE + 0x5, SZ_4K);
+   if (mpmu_base == NULL) {
+   pr_err("error to ioremap MPMU base\n");
+   return;
+   }
+
+   apmu_base = ioremap(AXI_PHYS_BASE + 0x82800, SZ_4K);
+   if (apmu_base == NULL) {
+   pr_err("error to ioremap APMU base\n");
+   return;
+   }
+
+   apbc_base = ioremap(APB_PHYS_BASE + 0x15000, SZ_4K);
+   if (apbc_base == NULL) {
+   pr_err("error to ioremap APBC base\n");
+   return;
+   }
+
+   clocks[clk32] =
+   clk_register_fixed_rate(NULL, "clk32", NULL, CLK_IS_ROOT, 3200);
+   clk_register_clkdev(clocks[clk32], "clk32", NULL);
+
+   clocks[vctcxo] =
+   clk_register_fixed_rate(NULL, "vctcxo", NULL, CLK_IS_ROOT,
+   2600);
+   clk_register_clkdev(clocks[vctcxo], "vctcxo", NULL);
+
+   clocks[pll1] =
+   clk_register_fixed_rate(NULL, "pll1", NULL, CLK_IS_ROOT, 8);
+   

[PATCH V3 3/5] clk: mmp: add clock definition for pxa910

2012-08-15 Thread Chao Xie
From: Chao Xie 

Initialize the clocks for pxa910

Signed-off-by: Chao Xie 
---
 drivers/clk/mmp/Makefile |1 +
 drivers/clk/mmp/clk-pxa910.c |  380 ++
 2 files changed, 381 insertions(+), 0 deletions(-)
 create mode 100644 drivers/clk/mmp/clk-pxa910.c

diff --git a/drivers/clk/mmp/Makefile b/drivers/clk/mmp/Makefile
index a0e69ed..6160ac2 100644
--- a/drivers/clk/mmp/Makefile
+++ b/drivers/clk/mmp/Makefile
@@ -5,3 +5,4 @@
 obj-y += clk-apbc.o clk-apmu.o clk-frac.o
 
 obj-$(CONFIG_CPU_PXA168) += clk-pxa168.o
+obj-$(CONFIG_CPU_PXA910) += clk-pxa910.o
diff --git a/drivers/clk/mmp/clk-pxa910.c b/drivers/clk/mmp/clk-pxa910.c
new file mode 100644
index 000..6f121e7
--- /dev/null
+++ b/drivers/clk/mmp/clk-pxa910.c
@@ -0,0 +1,380 @@
+/*
+ * pxa910 clock framework source file
+ *
+ * Copyright (C) 2012 Marvell
+ * Chao Xie 
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include "clk.h"
+
+#define APBC_RTC   0x28
+#define APBC_TWSI0 0x2c
+#define APBC_KPC   0x18
+#define APBC_UART0 0x0
+#define APBC_UART1 0x4
+#define APBC_GPIO  0x8
+#define APBC_PWM0  0xc
+#define APBC_PWM1  0x10
+#define APBC_PWM2  0x14
+#define APBC_PWM3  0x18
+#define APBC_SSP0  0x1c
+#define APBC_SSP1  0x20
+#define APBC_SSP2  0x4c
+#define APBCP_TWSI10x28
+#define APBCP_UART20x1c
+#define APMU_SDH0  0x54
+#define APMU_SDH1  0x58
+#define APMU_USB   0x5c
+#define APMU_DISP0 0x4c
+#define APMU_CCIC0 0x50
+#define APMU_DFC   0x60
+#define MPMU_UART_PLL  0x14
+
+static DEFINE_SPINLOCK(clk_lock);
+
+enum {
+   clk32, vctcxo, pll1, pll1_2, pll1_4, pll1_8, pll1_16, pll1_6, pll1_12,
+   pll1_24, pll1_48, pll1_96, pll1_13, pll1_13_1_5, pll1_2_1_5,
+   pll1_3_16, uart_pll, twsi0, twsi1, gpio, kpc, rtc, pwm0, pwm1, pwm2,
+   pwm3, uart0_mux, uart0, uart1_mux, uart1, uart2_mux, uart2,
+   ssp0_mux, ssp0, ssp1_mux, ssp1, dfc, sdh0_mux, sdh0, sdh1_mux, sdh1,
+   usb, sph, disp0_mux, disp0, ccic0_mux, ccic0, ccic0_phy_mux,
+   ccic0_phy, ccic0_sphy_div, ccic0_sphy, clk_max
+};
+
+static struct clk_factor_masks uart_factor_masks = {
+   .factor = 2,
+   .num_mask = 0x1fff,
+   .den_mask = 0x1fff,
+   .num_shift = 16,
+   .den_shift = 0,
+};
+
+static struct clk_factor_tbl uart_factor_tbl[] = {
+   {.num = 8125, .den = 1536}, /*14.745MHZ */
+};
+
+static const char *uart_parent[] = {"pll1_3_16", "uart_pll"};
+static const char *ssp_parent[] =
+   {"pll1_96", "pll1_48", "pll1_24", "pll1_12"};
+static const char *sdh_parent[] = {"pll1_12", "pll1_13"};
+static const char *disp_parent[] = {"pll1_2", "pll1_12"};
+static const char *ccic_parent[] = {"pll1_2", "pll1_12"};
+static const char *ccic_phy_parent[] = {"pll1_6", "pll1_12"};
+
+void __init pxa910_clk_init(void)
+{
+   struct clk *clocks[clk_max];
+   void __iomem *mpmu_base;
+   void __iomem *apmu_base;
+   void __iomem *apbcp_base;
+   void __iomem *apbc_base;
+
+   mpmu_base = ioremap(APB_PHYS_BASE + 0x5, SZ_4K);
+   if (mpmu_base == NULL) {
+   pr_err("error to ioremap MPMU base\n");
+   return;
+   }
+
+   apmu_base = ioremap(AXI_PHYS_BASE + 0x82800, SZ_4K);
+   if (apmu_base == NULL) {
+   pr_err("error to ioremap APMU base\n");
+   return;
+   }
+
+   apbcp_base = ioremap(APB_PHYS_BASE + 0x3b000, SZ_4K);
+   if (apbcp_base == NULL) {
+   pr_err("error to ioremap APBC extension base\n");
+   return;
+   }
+
+   apbc_base = ioremap(APB_PHYS_BASE + 0x15000, SZ_4K);
+   if (apbc_base == NULL) {
+   pr_err("error to ioremap APBC base\n");
+   return;
+   }
+
+   clocks[clk32] =
+   clk_register_fixed_rate(NULL, "clk32", NULL, CLK_IS_ROOT, 3200);
+   clk_register_clkdev(clocks[clk32], "clk32", NULL);
+
+   clocks[vctcxo] =
+   clk_register_fixed_rate(NULL, "vctcxo", NULL, CLK_IS_ROOT,
+   2600);
+   clk_register_clkdev(clocks[vctcxo], "vctcxo", NULL);
+
+   clocks[pll1] =
+   clk_register_fixed_rate(NULL, "pll1", NULL, CLK_IS_ROOT, 62400);
+   clk_register_clkdev(clocks[pll1], "pll1", NULL);
+
+   clocks[pll1_2] =
+   clk_register_fixed_factor(NULL, "pll1_2", "pll1",
+ CLK_SET_RATE_PARENT, 1, 2);
+   clk_register_clkdev(clocks[pll1_2], "pll1_2", NULL);
+
+   clocks[pll1_4] =
+   clk_register_fixed_factor(NULL, "pll1_4", "pll1_2",
+ CLK_SET_RATE_PARENT, 1, 2);
+   clk_register_clkdev(clocks[pll1_4], "pll1_4", NULL);
+
+   

[PATCH V3 2/5] clk: mmp: add clock definition for pxa168

2012-08-15 Thread Chao Xie
From: Chao Xie 

Initialize the clocks for pxa168

Signed-off-by: Chao Xie 
---
 drivers/clk/mmp/Makefile |2 +
 drivers/clk/mmp/clk-pxa168.c |  414 ++
 2 files changed, 416 insertions(+), 0 deletions(-)
 create mode 100644 drivers/clk/mmp/clk-pxa168.c

diff --git a/drivers/clk/mmp/Makefile b/drivers/clk/mmp/Makefile
index b5bc88c..a0e69ed 100644
--- a/drivers/clk/mmp/Makefile
+++ b/drivers/clk/mmp/Makefile
@@ -3,3 +3,5 @@
 #
 
 obj-y += clk-apbc.o clk-apmu.o clk-frac.o
+
+obj-$(CONFIG_CPU_PXA168) += clk-pxa168.o
diff --git a/drivers/clk/mmp/clk-pxa168.c b/drivers/clk/mmp/clk-pxa168.c
new file mode 100644
index 000..1b04deb
--- /dev/null
+++ b/drivers/clk/mmp/clk-pxa168.c
@@ -0,0 +1,414 @@
+/*
+ * pxa168 clock framework source file
+ *
+ * Copyright (C) 2012 Marvell
+ * Chao Xie 
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include "clk.h"
+
+#define APBC_RTC   0x28
+#define APBC_TWSI0 0x2c
+#define APBC_KPC   0x30
+#define APBC_UART0 0x0
+#define APBC_UART1 0x4
+#define APBC_GPIO  0x8
+#define APBC_PWM0  0xc
+#define APBC_PWM1  0x10
+#define APBC_PWM2  0x14
+#define APBC_PWM3  0x18
+#define APBC_SSP0  0x81c
+#define APBC_SSP1  0x820
+#define APBC_SSP2  0x84c
+#define APBC_SSP3  0x858
+#define APBC_SSP4  0x85c
+#define APBC_TWSI1 0x6c
+#define APBC_UART2 0x70
+#define APMU_SDH0  0x54
+#define APMU_SDH1  0x58
+#define APMU_USB   0x5c
+#define APMU_DISP0 0x4c
+#define APMU_CCIC0 0x50
+#define APMU_DFC   0x60
+#define MPMU_UART_PLL  0x14
+
+static DEFINE_SPINLOCK(clk_lock);
+
+enum {
+   clk32, vctcxo, pll1, pll1_2, pll1_4, pll1_8, pll1_16, pll1_6, pll1_12,
+   pll1_24, pll1_48, pll1_96, pll1_13, pll1_13_1_5, pll1_2_1_5,
+   pll1_3_16, uart_pll, twsi0, twsi1, gpio, kpc, rtc, pwm0, pwm1, pwm2,
+   pwm3, uart0_mux, uart0, uart1_mux, uart1, uart2_mux, uart2,
+   ssp0_mux, ssp0, ssp1_mux, ssp1, ssp2_mux, ssp2, ssp3_mux, ssp3,
+   ssp4_mux, ssp4, dfc, sdh0_mux, sdh0, sdh1_mux, sdh1, usb, sph,
+   disp0_mux, disp0, disp0_hclk, ccic0_mux, ccic0, ccic0_phy_mux,
+   ccic0_phy, ccic0_sphy_div, ccic0_sphy, clk_max
+};
+
+static struct clk_factor_masks uart_factor_masks = {
+   .factor = 2,
+   .num_mask = 0x1fff,
+   .den_mask = 0x1fff,
+   .num_shift = 16,
+   .den_shift = 0,
+};
+
+static struct clk_factor_tbl uart_factor_tbl[] = {
+   {.num = 8125, .den = 1536}, /*14.745MHZ */
+};
+
+static const char *uart_parent[] = {"pll1_3_16", "uart_pll"};
+static const char *ssp_parent[] =
+   {"pll1_96", "pll1_48", "pll1_24", "pll1_12" };
+static const char *sdh_parent[] = {"pll1_12", "pll1_13"};
+static const char *disp_parent[] = {"pll1_2", "pll1_12"};
+static const char *ccic_parent[] = {"pll1_2", "pll1_12"};
+static const char *ccic_phy_parent[] = {"pll1_6", "pll1_12"};
+
+void __init pxa168_clk_init(void)
+{
+   struct clk *clocks[clk_max];
+   void __iomem *mpmu_base;
+   void __iomem *apmu_base;
+   void __iomem *apbc_base;
+
+   mpmu_base = ioremap(APB_PHYS_BASE + 0x5, SZ_4K);
+   if (mpmu_base == NULL) {
+   pr_err("error to ioremap MPMU base\n");
+   return;
+   }
+
+   apmu_base = ioremap(AXI_PHYS_BASE + 0x82800, SZ_4K);
+   if (apmu_base == NULL) {
+   pr_err("error to ioremap APMU base\n");
+   return;
+   }
+
+   apbc_base = ioremap(APB_PHYS_BASE + 0x15000, SZ_4K);
+   if (apbc_base == NULL) {
+   pr_err("error to ioremap APBC base\n");
+   return;
+   }
+
+   clocks[clk32] =
+   clk_register_fixed_rate(NULL, "clk32", NULL, CLK_IS_ROOT, 3200);
+   clk_register_clkdev(clocks[clk32], "clk32", NULL);
+
+   clocks[vctcxo] =
+   clk_register_fixed_rate(NULL, "vctcxo", NULL, CLK_IS_ROOT,
+   2600);
+   clk_register_clkdev(clocks[vctcxo], "vctcxo", NULL);
+
+   clocks[pll1] =
+   clk_register_fixed_rate(NULL, "pll1", NULL, CLK_IS_ROOT, 62400);
+   clk_register_clkdev(clocks[pll1], "pll1", NULL);
+
+   clocks[pll1_2] =
+   clk_register_fixed_factor(NULL, "pll1_2", "pll1",
+ CLK_SET_RATE_PARENT, 1, 2);
+   clk_register_clkdev(clocks[pll1_2], "pll1_2", NULL);
+
+   clocks[pll1_4] =
+   clk_register_fixed_factor(NULL, "pll1_4", "pll1_2",
+ CLK_SET_RATE_PARENT, 1, 2);
+   clk_register_clkdev(clocks[pll1_4], "pll1_4", NULL);
+
+   clocks[pll1_8] =
+   clk_register_fixed_factor(NULL, "pll1_8", "pll1_4",
+ CLK_SET_RATE_PARENT, 

[PATCH V3 1/5] clk: mmp: add mmp specific clocks

2012-08-15 Thread Chao Xie
From: Chao Xie 

add mmp specific clocks including apbc cloks, apmu clocks,
and pll2, fraction clocks

Signed-off-by: Chao Xie 
---
 drivers/clk/Makefile   |3 +
 drivers/clk/mmp/Makefile   |5 ++
 drivers/clk/mmp/clk-apbc.c |  152 +++
 drivers/clk/mmp/clk-apmu.c |   97 
 drivers/clk/mmp/clk-frac.c |  153 
 drivers/clk/mmp/clk.h  |   35 ++
 6 files changed, 445 insertions(+), 0 deletions(-)
 create mode 100644 drivers/clk/mmp/Makefile
 create mode 100644 drivers/clk/mmp/clk-apbc.c
 create mode 100644 drivers/clk/mmp/clk-apmu.c
 create mode 100644 drivers/clk/mmp/clk-frac.c
 create mode 100644 drivers/clk/mmp/clk.h

diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index 5869ea3..58590c8 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -10,6 +10,9 @@ obj-$(CONFIG_ARCH_SOCFPGA)+= socfpga/
 obj-$(CONFIG_PLAT_SPEAR)   += spear/
 obj-$(CONFIG_ARCH_U300)+= clk-u300.o
 obj-$(CONFIG_ARCH_INTEGRATOR)  += versatile/
+ifeq ($(CONFIG_COMMON_CLK), y)
+obj-$(CONFIG_ARCH_MMP) += mmp/
+endif
 
 # Chip specific
 obj-$(CONFIG_COMMON_CLK_WM831X) += clk-wm831x.o
diff --git a/drivers/clk/mmp/Makefile b/drivers/clk/mmp/Makefile
new file mode 100644
index 000..b5bc88c
--- /dev/null
+++ b/drivers/clk/mmp/Makefile
@@ -0,0 +1,5 @@
+#
+# Makefile for mmp specific clk
+#
+
+obj-y += clk-apbc.o clk-apmu.o clk-frac.o
diff --git a/drivers/clk/mmp/clk-apbc.c b/drivers/clk/mmp/clk-apbc.c
new file mode 100644
index 000..be3b154
--- /dev/null
+++ b/drivers/clk/mmp/clk-apbc.c
@@ -0,0 +1,152 @@
+/*
+ * mmp APB clock operation source file
+ *
+ * Copyright (C) 2012 Marvell
+ * Chao Xie 
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "clk.h"
+
+/* Common APB clock register bit definitions */
+#define APBC_APBCLK(1 << 0)  /* APB Bus Clock Enable */
+#define APBC_FNCLK (1 << 1)  /* Functional Clock Enable */
+#define APBC_RST   (1 << 2)  /* Reset Generation */
+#define APBC_POWER (1 << 7)  /* Reset Generation */
+
+#define to_clk_apbc(hw) container_of(hw, struct clk_apbc, hw)
+struct clk_apbc {
+   struct clk_hw   hw;
+   void __iomem*base;
+   unsigned intdelay;
+   unsigned intflags;
+   spinlock_t  *lock;
+};
+
+static int clk_apbc_prepare(struct clk_hw *hw)
+{
+   struct clk_apbc *apbc = to_clk_apbc(hw);
+   unsigned int data;
+   unsigned long flags = 0;
+
+   /*
+* It may share same register as MUX clock,
+* and it will impact FNCLK enable. Spinlock is needed
+*/
+   if (apbc->lock)
+   spin_lock_irqsave(apbc->lock, flags);
+
+   data = __raw_readl(apbc->base);
+   if (apbc->flags & APBC_POWER_CTRL)
+   data |= APBC_POWER;
+   data |= APBC_FNCLK;
+   __raw_writel(data, apbc->base);
+
+   if (apbc->lock)
+   spin_unlock_irqrestore(apbc->lock, flags);
+
+   udelay(apbc->delay);
+
+   if (apbc->lock)
+   spin_lock_irqsave(apbc->lock, flags);
+
+   data = __raw_readl(apbc->base);
+   data |= APBC_APBCLK;
+   __raw_writel(data, apbc->base);
+
+   if (apbc->lock)
+   spin_unlock_irqrestore(apbc->lock, flags);
+
+   udelay(apbc->delay);
+
+   if (!(apbc->flags & APBC_NO_BUS_CTRL)) {
+   if (apbc->lock)
+   spin_lock_irqsave(apbc->lock, flags);
+
+   data = __raw_readl(apbc->base);
+   data &= ~APBC_RST;
+   __raw_writel(data, apbc->base);
+
+   if (apbc->lock)
+   spin_unlock_irqrestore(apbc->lock, flags);
+   }
+
+   return 0;
+}
+
+static void clk_apbc_unprepare(struct clk_hw *hw)
+{
+   struct clk_apbc *apbc = to_clk_apbc(hw);
+   unsigned long data;
+   unsigned long flags = 0;
+
+   if (apbc->lock)
+   spin_lock_irqsave(apbc->lock, flags);
+
+   data = __raw_readl(apbc->base);
+   if (apbc->flags & APBC_POWER_CTRL)
+   data &= ~APBC_POWER;
+   data &= ~APBC_FNCLK;
+   __raw_writel(data, apbc->base);
+
+   if (apbc->lock)
+   spin_unlock_irqrestore(apbc->lock, flags);
+
+   udelay(10);
+
+   if (apbc->lock)
+   spin_lock_irqsave(apbc->lock, flags);
+
+   data = __raw_readl(apbc->base);
+   data &= ~APBC_APBCLK;
+   __raw_writel(data, apbc->base);
+
+   if (apbc->lock)
+   spin_unlock_irqrestore(apbc->lock, flags);
+}
+
+struct clk_ops clk_apbc_ops = {
+   .prepare = clk_apbc_prepare,
+   .unprepare = clk_apbc_unprepare,
+};
+
+struct clk 

[PATCH V3 0/5] clk: mmp: add clock framework for mmp

2012-08-15 Thread Chao Xie
From: Chao Xie 

v1->v2:
replace __raw_xxx with xxx_relax
use ioremap to remap the registers. Finaly it will use device tree to
get the physical address.
do not use macro to register clocks, and directly call the functions.

v2->v3:
pxa910 will have APB extension clock, so some peripharals will have
clocks in APB extension base.
change pxa168-pwm to be pxa910-pwm for pxa910. It will fit the current
pwm driver.

Chao Xie (5):
  clk: mmp: add mmp specific clocks
  clk: mmp: add clock definition for pxa168
  clk: mmp: add clock definition for pxa910
  clk: mmp: add clock definition for mmp2
  arm: mmp: make all SOCs use common clock by default

 arch/arm/mach-mmp/Kconfig|3 +
 drivers/clk/Makefile |3 +
 drivers/clk/mmp/Makefile |9 +
 drivers/clk/mmp/clk-apbc.c   |  152 
 drivers/clk/mmp/clk-apmu.c   |   97 
 drivers/clk/mmp/clk-frac.c   |  153 
 drivers/clk/mmp/clk-mmp2.c   |  544 ++
 drivers/clk/mmp/clk-pxa168.c |  414 
 drivers/clk/mmp/clk-pxa910.c |  361 
 drivers/clk/mmp/clk.h|   35 +++
 10 files changed, 1771 insertions(+), 0 deletions(-)
 create mode 100644 drivers/clk/mmp/Makefile
 create mode 100644 drivers/clk/mmp/clk-apbc.c
 create mode 100644 drivers/clk/mmp/clk-apmu.c
 create mode 100644 drivers/clk/mmp/clk-frac.c
 create mode 100644 drivers/clk/mmp/clk-mmp2.c
 create mode 100644 drivers/clk/mmp/clk-pxa168.c
 create mode 100644 drivers/clk/mmp/clk-pxa910.c
 create mode 100644 drivers/clk/mmp/clk.h

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH 0/5] net: socket bind to file descriptor introduced

2012-08-15 Thread Eric W. Biederman
Stanislav Kinsbursky  writes:

> This patch set introduces new socket operation and new system call:
> sys_fbind(), which allows to bind socket to opened file.
> File to bind to can be created by sys_mknod(S_IFSOCK) and opened by
> open(O_PATH).
>
> This system call is especially required for UNIX sockets, which has name
> lenght limitation.
>
> The following series implements...

Hmm.  I just realized this patchset is even sillier than I thought.

Stanislav is the problem you are ultimately trying to solve nfs clients
in a container connecting to the wrong user space rpciod?

Aka net/sunrpc/xprtsock.c:xs_setup_local only taking an absolute path
and then creating a delayed work item to actually open the unix domain
socket?

The straight correct and straight forward thing to do appears to be:
- Capture the root from current->fs in xs_setup_local.
- In xs_local_finish_connect change current->fs.root to the captured
  version of root before kernel_connect, and restore current->fs.root
  after kernel_connect.

It might not be a bad idea to implement open on unix domain sockets in
a filesystem as create(AF_LOCAL)+connect() which would allow you to
replace __sock_create + kernel_connect with a simple file_open_root.

But I think the simple scheme of:
struct path old_root;
old_root = current->fs.root;
kernel_connect(...);
current->fs.root = old_root;

Is more than sufficient and will remove the need for anything
except a purely local change to get nfs clients to connect from
containers.

Eric
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: NULL pointer dereference in ext4_ext_remove_space on 3.5.1

2012-08-15 Thread Theodore Ts'o
On Wed, Aug 15, 2012 at 09:33:29PM +0300, Marti Raudsepp wrote:
> I was moving and deleting some files between two of my ext4 partitions
> when it suddenly crashed and dropped me into an kernel oops screen
> (below). I'm using ext4 on kernel 3.5.1 (Arch Linux). 

> BUG: unable to handle kernel NULL pointer dereference at 000...00028
> IP: [...] ext4_ext_remove_space+0xaa4/0xef0 [ext4]

Someone else has reported a similar crash, but we don't yet have
enough information to narrow it down quite yet.

If you could try applying the following debugging patch, and then try
to reproduce the failure, it would be really helpful.

Thanks!!

- Ted

diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 769151d..3394d52 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -2432,6 +2432,10 @@ ext4_ext_rm_leaf(handle_t *handle, struct inode *inode,
 
/* the header must be checked already in ext4_ext_remove_space() */
ext_debug("truncate since %u in leaf to %u\n", start, end);
+   if (!path[depth].p_hdr && !path[depth].p_bh) {
+   EXT4_ERROR_INODE(inode, "depth %d", depth);
+   BUG_ON(1);
+   }
if (!path[depth].p_hdr)
path[depth].p_hdr = ext_block_hdr(path[depth].p_bh);
eh = path[depth].p_hdr;
@@ -2730,6 +2734,10 @@ cont:
/* this is index block */
if (!path[i].p_hdr) {
ext_debug("initialize header\n");
+   if (!path[i].p_hdr && !path[i].p_bh) {
+   EXT4_ERROR_INODE(inode, "i=%d", i);
+   BUG_ON(1);
+   }
path[i].p_hdr = ext_block_hdr(path[i].p_bh);
}
 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [PATCH] net: add new QCA alx ethernet driver

2012-08-15 Thread Ren, Cloud
From: Stephen Hemminger [mailto:shemmin...@vyatta.com]
Sent: Wednesday, August 15, 2012 11:02 PM

>>  +   strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) -
>1);
>>  ...
>>  +   strcpy(netdev->name, "eth%d");
>>  +   retval = register_netdev(netdev);
>> >>>
>> >>>The strcpy is unnecessary, alloc_etherdev already sets that.
>> >>
>> >> The strcpy is useful. netdev->name is set as pci_name in front. So the 
>> >> strcpy
>> >restores it.
>> >
>> >Are you doing this just to influence the initial driver log messages?
>>
>>  Yes.
>>
>> >
>> >Don't do that, it's gross.
>>
>> Ok, I will remove it.
>
>Before the driver is registered, use dev_info() type of logging.

Ok, I will do.



 


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] sched: Add time unit suffix to sched sysctl knobs

2012-08-15 Thread Namhyung Kim
From: Namhyung Kim 

Unlike others, sched_migration_cost, sched_time_avg and
sched_shares_window doesn't have time unit as suffix. Add them.

Signed-off-by: Namhyung Kim 
---
 kernel/sysctl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 87174ef59161..81c7b1a1a307 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -307,7 +307,7 @@ static struct ctl_table kern_table[] = {
.extra2 = _sched_tunable_scaling,
},
{
-   .procname   = "sched_migration_cost",
+   .procname   = "sched_migration_cost_ns",
.data   = _sched_migration_cost,
.maxlen = sizeof(unsigned int),
.mode   = 0644,
@@ -321,14 +321,14 @@ static struct ctl_table kern_table[] = {
.proc_handler   = proc_dointvec,
},
{
-   .procname   = "sched_time_avg",
+   .procname   = "sched_time_avg_ms",
.data   = _sched_time_avg,
.maxlen = sizeof(unsigned int),
.mode   = 0644,
.proc_handler   = proc_dointvec,
},
{
-   .procname   = "sched_shares_window",
+   .procname   = "sched_shares_window_ns",
.data   = _sched_shares_window,
.maxlen = sizeof(unsigned int),
.mode   = 0644,
-- 
1.7.11.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] MAINTAINERS: update address for Dan Williams

2012-08-15 Thread Dan Williams
Moved to d...@fb.com

Cc: Dave Jiang 
Cc: Vinod Koul 
Signed-off-by: Dan Williams 
---
 MAINTAINERS |   25 -
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 94b823f..a728dc0 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -827,24 +827,24 @@ F:arch/arm/mach-pxa/colibri-pxa270-income.c
 
 ARM/INTEL IOP32X ARM ARCHITECTURE
 M: Lennert Buytenhek 
-M: Dan Williams 
+M: Dan Williams 
 L: linux-arm-ker...@lists.infradead.org (moderated for non-subscribers)
 S: Maintained
 
 ARM/INTEL IOP33X ARM ARCHITECTURE
-M: Dan Williams 
+M: Dan Williams 
 L: linux-arm-ker...@lists.infradead.org (moderated for non-subscribers)
 S: Maintained
 
 ARM/INTEL IOP13XX ARM ARCHITECTURE
 M: Lennert Buytenhek 
-M: Dan Williams 
+M: Dan Williams 
 L: linux-arm-ker...@lists.infradead.org (moderated for non-subscribers)
 S: Maintained
 
 ARM/INTEL IQ81342EX MACHINE SUPPORT
 M: Lennert Buytenhek 
-M: Dan Williams 
+M: Dan Williams 
 L: linux-arm-ker...@lists.infradead.org (moderated for non-subscribers)
 S: Maintained
 
@@ -869,7 +869,7 @@ F:  drivers/pcmcia/pxa2xx_stargate2.c
 
 ARM/INTEL XSC3 (MANZANO) ARM CORE
 M: Lennert Buytenhek 
-M: Dan Williams 
+M: Dan Williams 
 L: linux-arm-ker...@lists.infradead.org (moderated for non-subscribers)
 S: Maintained
 
@@ -1227,9 +1227,9 @@ S:Maintained
 F: drivers/hwmon/asb100.c
 
 ASYNCHRONOUS TRANSFERS/TRANSFORMS (IOAT) API
-M: Dan Williams 
+M: Dan Williams 
 W: http://sourceforge.net/projects/xscaleiop
-S: Supported
+S: Maintained
 F: Documentation/crypto/async-tx-api.txt
 F: crypto/async_tx/
 F: drivers/dma/
@@ -2359,7 +2359,7 @@ T:git 
git://git.linaro.org/people/sumitsemwal/linux-dma-buf.git
 
 DMA GENERIC OFFLOAD ENGINE SUBSYSTEM
 M: Vinod Koul 
-M: Dan Williams 
+M: Dan Williams 
 S: Supported
 F: drivers/dma/
 F: include/linux/dma*
@@ -3547,7 +3547,6 @@ K:\b(ABS|SYN)_MT_
 
 INTEL C600 SERIES SAS CONTROLLER DRIVER
 M: Intel SCU Linux support 
-M: Dan Williams 
 M: Dave Jiang 
 M: Ed Nadolski 
 L: linux-s...@vger.kernel.org
@@ -3590,8 +3589,8 @@ F:arch/x86/kernel/microcode_core.c
 F: arch/x86/kernel/microcode_intel.c
 
 INTEL I/OAT DMA DRIVER
-M: Dan Williams 
-S: Supported
+M: Dan Williams 
+S: Maintained
 F: drivers/dma/ioat*
 
 INTEL IOMMU (VT-d)
@@ -3603,8 +3602,8 @@ F:drivers/iommu/intel-iommu.c
 F: include/linux/intel-iommu.h
 
 INTEL IOP-ADMA DMA DRIVER
-M: Dan Williams 
-S: Maintained
+M: Dan Williams 
+S: Odd fixes
 F: drivers/dma/iop-adma.c
 
 INTEL IXP4XX QMGR, NPE, ETHERNET and HSS SUPPORT

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH V2 3/5] clk: mmp: add clock definition for pxa910

2012-08-15 Thread Chao Xie
From: Chao Xie 

Initialize the clocks for pxa910

Signed-off-by: Chao Xie 
---
 drivers/clk/mmp/Makefile |1 +
 drivers/clk/mmp/clk-pxa910.c |  361 ++
 2 files changed, 362 insertions(+), 0 deletions(-)
 create mode 100644 drivers/clk/mmp/clk-pxa910.c

diff --git a/drivers/clk/mmp/Makefile b/drivers/clk/mmp/Makefile
index a0e69ed..6160ac2 100644
--- a/drivers/clk/mmp/Makefile
+++ b/drivers/clk/mmp/Makefile
@@ -5,3 +5,4 @@
 obj-y += clk-apbc.o clk-apmu.o clk-frac.o
 
 obj-$(CONFIG_CPU_PXA168) += clk-pxa168.o
+obj-$(CONFIG_CPU_PXA910) += clk-pxa910.o
diff --git a/drivers/clk/mmp/clk-pxa910.c b/drivers/clk/mmp/clk-pxa910.c
new file mode 100644
index 000..3428c9f
--- /dev/null
+++ b/drivers/clk/mmp/clk-pxa910.c
@@ -0,0 +1,361 @@
+/*
+ * pxa168 clock framework source file
+ *
+ * Copyright (C) 2012 Marvell
+ * Chao Xie 
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include "clk.h"
+
+#define APBC_RTC   0x28
+#define APBC_TWSI0 0x2c
+#define APBC_KPC   0x18
+#define APBC_UART0 0x0
+#define APBC_UART1 0x4
+#define APBC_GPIO  0x8
+#define APBC_PWM0  0xc
+#define APBC_PWM1  0x10
+#define APBC_PWM2  0x14
+#define APBC_PWM3  0x18
+#define APBC_SSP0  0x1c
+#define APBC_SSP1  0x20
+#define APBC_SSP2  0x4c
+#define APBC_TWSI1 0x28
+#define APBC_UART2 0x1c
+#define APMU_SDH0  0x54
+#define APMU_SDH1  0x58
+#define APMU_USB   0x5c
+#define APMU_DISP0 0x4c
+#define APMU_CCIC0 0x50
+#define APMU_DFC   0x60
+#define MPMU_UART_PLL  0x14
+
+static DEFINE_SPINLOCK(clk_lock);
+
+enum {
+   clk32, vctcxo, pll1, pll1_2, pll1_4, pll1_8, pll1_16, pll1_6, pll1_12,
+   pll1_24, pll1_48, pll1_96, pll1_13, pll1_13_1_5, pll1_2_1_5,
+   pll1_3_16, uart_pll, twsi0, twsi1, gpio, kpc, rtc, pwm0, pwm1, pwm2,
+   pwm3, uart0_mux, uart0, uart1_mux, uart1, ssp0_mux, ssp0, ssp1_mux,
+   ssp1, dfc, sdh0_mux, sdh0, sdh1_mux, sdh1, usb, sph, disp0_mux,
+   disp0, ccic0_mux, ccic0, ccic0_phy_mux, ccic0_phy, ccic0_sphy_div,
+   ccic0_sphy, clk_max
+};
+
+static struct clk_factor_masks uart_factor_masks = {
+   .factor = 2,
+   .num_mask = 0x1fff,
+   .den_mask = 0x1fff,
+   .num_shift = 16,
+   .den_shift = 0,
+};
+
+static struct clk_factor_tbl uart_factor_tbl[] = {
+   {.num = 8125, .den = 1536}, /*14.745MHZ */
+};
+
+static const char *uart_parent[] = {"pll1_3_16", "uart_pll"};
+static const char *ssp_parent[] =
+   {"pll1_96", "pll1_48", "pll1_24", "pll1_12"};
+static const char *sdh_parent[] = {"pll1_12", "pll1_13"};
+static const char *disp_parent[] = {"pll1_2", "pll1_12"};
+static const char *ccic_parent[] = {"pll1_2", "pll1_12"};
+static const char *ccic_phy_parent[] = {"pll1_6", "pll1_12"};
+
+void __init pxa910_clk_init(void)
+{
+   struct clk *clocks[clk_max];
+   void __iomem *mpmu_base;
+   void __iomem *apmu_base;
+   void __iomem *apbc_base;
+
+   mpmu_base = ioremap(APB_PHYS_BASE + 0x5, SZ_4K);
+   if (mpmu_base == NULL) {
+   pr_err("error to ioremap MPMU base\n");
+   return;
+   }
+
+   apmu_base = ioremap(AXI_PHYS_BASE + 0x82800, SZ_4K);
+   if (apmu_base == NULL) {
+   pr_err("error to ioremap APMU base\n");
+   return;
+   }
+
+   apbc_base = ioremap(APB_PHYS_BASE + 0x15000, SZ_4K);
+   if (apbc_base == NULL) {
+   pr_err("error to ioremap APBC base\n");
+   return;
+   }
+
+   clocks[clk32] =
+   clk_register_fixed_rate(NULL, "clk32", NULL, CLK_IS_ROOT, 3200);
+   clk_register_clkdev(clocks[clk32], "clk32", NULL);
+
+   clocks[vctcxo] =
+   clk_register_fixed_rate(NULL, "vctcxo", NULL, CLK_IS_ROOT,
+   2600);
+   clk_register_clkdev(clocks[vctcxo], "vctcxo", NULL);
+
+   clocks[pll1] =
+   clk_register_fixed_rate(NULL, "pll1", NULL, CLK_IS_ROOT, 62400);
+   clk_register_clkdev(clocks[pll1], "pll1", NULL);
+
+   clocks[pll1_2] =
+   clk_register_fixed_factor(NULL, "pll1_2", "pll1",
+ CLK_SET_RATE_PARENT, 1, 2);
+   clk_register_clkdev(clocks[pll1_2], "pll1_2", NULL);
+
+   clocks[pll1_4] =
+   clk_register_fixed_factor(NULL, "pll1_4", "pll1_2",
+ CLK_SET_RATE_PARENT, 1, 2);
+   clk_register_clkdev(clocks[pll1_4], "pll1_4", NULL);
+
+   clocks[pll1_8] =
+   clk_register_fixed_factor(NULL, "pll1_8", "pll1_4",
+ CLK_SET_RATE_PARENT, 1, 2);
+   clk_register_clkdev(clocks[pll1_8], "pll1_8", NULL);
+
+   clocks[pll1_16] =
+   

[PATCH V2 4/5] clk: mmp: add clock definition for mmp2

2012-08-15 Thread Chao Xie
From: Chao Xie 

Initialize the clocks for mmp2

Signed-off-by: Chao Xie 
---
 drivers/clk/mmp/Makefile   |1 +
 drivers/clk/mmp/clk-mmp2.c |  544 
 2 files changed, 545 insertions(+), 0 deletions(-)
 create mode 100644 drivers/clk/mmp/clk-mmp2.c

diff --git a/drivers/clk/mmp/Makefile b/drivers/clk/mmp/Makefile
index 6160ac2..392d780 100644
--- a/drivers/clk/mmp/Makefile
+++ b/drivers/clk/mmp/Makefile
@@ -6,3 +6,4 @@ obj-y += clk-apbc.o clk-apmu.o clk-frac.o
 
 obj-$(CONFIG_CPU_PXA168) += clk-pxa168.o
 obj-$(CONFIG_CPU_PXA910) += clk-pxa910.o
+obj-$(CONFIG_CPU_MMP2) += clk-mmp2.o
diff --git a/drivers/clk/mmp/clk-mmp2.c b/drivers/clk/mmp/clk-mmp2.c
new file mode 100644
index 000..410e6a6
--- /dev/null
+++ b/drivers/clk/mmp/clk-mmp2.c
@@ -0,0 +1,544 @@
+/*
+ * pxa168 clock framework source file
+ *
+ * Copyright (C) 2012 Marvell
+ * Chao Xie 
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include "clk.h"
+
+#define APBC_RTC   0x0
+#define APBC_TWSI0 0x4
+#define APBC_TWSI1 0x8
+#define APBC_TWSI2 0xc
+#define APBC_TWSI3 0x10
+#define APBC_TWSI4 0x7c
+#define APBC_TWSI5 0x80
+#define APBC_KPC   0x18
+#define APBC_UART0 0x2c
+#define APBC_UART1 0x30
+#define APBC_UART2 0x34
+#define APBC_UART3 0x88
+#define APBC_GPIO  0x38
+#define APBC_PWM0  0x3c
+#define APBC_PWM1  0x40
+#define APBC_PWM2  0x44
+#define APBC_PWM3  0x48
+#define APBC_SSP0  0x50
+#define APBC_SSP1  0x54
+#define APBC_SSP2  0x58
+#define APBC_SSP3  0x5c
+#define APMU_SDH0  0x54
+#define APMU_SDH1  0x58
+#define APMU_SDH2  0xe8
+#define APMU_SDH3  0xec
+#define APMU_USB   0x5c
+#define APMU_DISP0 0x4c
+#define APMU_DISP1 0x110
+#define APMU_CCIC0 0x50
+#define APMU_CCIC1 0xf4
+#define MPMU_UART_PLL  0x14
+
+static DEFINE_SPINLOCK(clk_lock);
+
+enum {
+   clk32, vctcxo, pll1, usb_pll, pll2, pll1_2, pll1_4, pll1_8, pll1_16,
+   pll1_20, pll1_3, pll1_6, pll1_12, pll2_2, pll2_4, pll2_8, pll2_16,
+   pll2_3, pll2_6, pll2_12, vctcxo_2, vctcxo_4, uart_pll, twsi0, twsi1,
+   twsi2, twsi3, twsi4, twsi5, gpio, kpc, rtc, pwm0, pwm1, pwm2, pwm3,
+   uart0_mux, uart0, uart1_mux, uart1, uart2_mux, uart2, uart3_mux,
+   uart3, ssp0_mux, ssp0, ssp1_mux, ssp1, ssp2_mux, ssp2, ssp3_mux,
+   ssp3, sdh_mux, sdh_div, sdh0, sdh1, sdh2, sdh3, usb, disp0_mux,
+   disp0_div, disp0, disp0_sphy_div, disp0_sphy, disp1_mux, disp1_div,
+   disp1, ccic_arbiter, ccic0_mux, ccic0_div, ccic0, ccic0_phy,
+   ccic0_sphy_div, ccic0_sphy, ccic1_mux, ccic1_div, ccic1, ccic1_phy,
+   ccic1_sphy_div, ccic1_sphy, clk_max
+};
+
+static struct clk_factor_masks uart_factor_masks = {
+   .factor = 2,
+   .num_mask = 0x1fff,
+   .den_mask = 0x1fff,
+   .num_shift = 16,
+   .den_shift = 0,
+};
+
+static struct clk_factor_tbl uart_factor_tbl[] = {
+   {.num = 14634, .den = 2165},/*14.745MHZ */
+   {.num = 3521, .den = 689},  /*19.23MHZ */
+   {.num = 9679, .den = 5728}, /*58.9824MHZ */
+   {.num = 15850, .den = 9451},/*59.429MHZ */
+};
+
+static const char *uart_parent[] = {"uart_pll", "vctcxo"};
+static const char *ssp_parent[] =
+   {"vctcxo_4", "vctcxo_2", "vctcxo", "pll1_16"};
+static const char *sdh_parent[] = {"pll1_4", "pll2", "usb_pll", "pll1"};
+static const char *disp_parent[] = {"pll1", "pll1_16", "pll2", "vctcxo"};
+static const char *ccic_parent[] = {"pll1_2", "pll1_16", "vctcxo"};
+
+void __init mmp2_clk_init(void)
+{
+   struct clk *clocks[clk_max];
+   void __iomem *mpmu_base;
+   void __iomem *apmu_base;
+   void __iomem *apbc_base;
+
+   mpmu_base = ioremap(APB_PHYS_BASE + 0x5, SZ_4K);
+   if (mpmu_base == NULL) {
+   pr_err("error to ioremap MPMU base\n");
+   return;
+   }
+
+   apmu_base = ioremap(AXI_PHYS_BASE + 0x82800, SZ_4K);
+   if (apmu_base == NULL) {
+   pr_err("error to ioremap APMU base\n");
+   return;
+   }
+
+   apbc_base = ioremap(APB_PHYS_BASE + 0x15000, SZ_4K);
+   if (apbc_base == NULL) {
+   pr_err("error to ioremap APBC base\n");
+   return;
+   }
+
+   clocks[clk32] =
+   clk_register_fixed_rate(NULL, "clk32", NULL, CLK_IS_ROOT, 3200);
+   clk_register_clkdev(clocks[clk32], "clk32", NULL);
+
+   clocks[vctcxo] =
+   clk_register_fixed_rate(NULL, "vctcxo", NULL, CLK_IS_ROOT,
+   2600);
+   clk_register_clkdev(clocks[vctcxo], "vctcxo", NULL);
+
+   clocks[pll1] =
+   clk_register_fixed_rate(NULL, "pll1", NULL, CLK_IS_ROOT, 8);
+   

[PATCH V2 2/5] clk: mmp: add clock definition for pxa168

2012-08-15 Thread Chao Xie
From: Chao Xie 

Initialize the clocks for pxa168

Signed-off-by: Chao Xie 
---
 drivers/clk/mmp/Makefile |2 +
 drivers/clk/mmp/clk-pxa168.c |  414 ++
 2 files changed, 416 insertions(+), 0 deletions(-)
 create mode 100644 drivers/clk/mmp/clk-pxa168.c

diff --git a/drivers/clk/mmp/Makefile b/drivers/clk/mmp/Makefile
index b5bc88c..a0e69ed 100644
--- a/drivers/clk/mmp/Makefile
+++ b/drivers/clk/mmp/Makefile
@@ -3,3 +3,5 @@
 #
 
 obj-y += clk-apbc.o clk-apmu.o clk-frac.o
+
+obj-$(CONFIG_CPU_PXA168) += clk-pxa168.o
diff --git a/drivers/clk/mmp/clk-pxa168.c b/drivers/clk/mmp/clk-pxa168.c
new file mode 100644
index 000..83a9e1b
--- /dev/null
+++ b/drivers/clk/mmp/clk-pxa168.c
@@ -0,0 +1,414 @@
+/*
+ * pxa168 clock framework source file
+ *
+ * Copyright (C) 2012 Marvell
+ * Chao Xie 
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include "clk.h"
+
+#define APBC_RTC   0x28
+#define APBC_TWSI0 0x2c
+#define APBC_KPC   0x30
+#define APBC_UART0 0x0
+#define APBC_UART1 0x4
+#define APBC_GPIO  0x8
+#define APBC_PWM0  0xc
+#define APBC_PWM1  0x10
+#define APBC_PWM2  0x14
+#define APBC_PWM3  0x18
+#define APBC_SSP0  0x81c
+#define APBC_SSP1  0x820
+#define APBC_SSP2  0x84c
+#define APBC_SSP3  0x858
+#define APBC_SSP4  0x85c
+#define APBC_TWSI1 0x6c
+#define APBC_UART2 0x70
+#define APMU_SDH0  0x54
+#define APMU_SDH1  0x58
+#define APMU_USB   0x5c
+#define APMU_DISP0 0x4c
+#define APMU_CCIC0 0x50
+#define APMU_DFC   0x60
+#define MPMU_UART_PLL  0x14
+
+static DEFINE_SPINLOCK(clk_lock);
+
+enum {
+   clk32, vctcxo, pll1, pll1_2, pll1_4, pll1_8, pll1_16, pll1_6, pll1_12,
+   pll1_24, pll1_48, pll1_96, pll1_13, pll1_13_1_5, pll1_2_1_5,
+   pll1_3_16, uart_pll, twsi0, twsi1, gpio, kpc, rtc, pwm0, pwm1, pwm2,
+   pwm3, uart0_mux, uart0, uart1_mux, uart1, uart2_mux, uart2,
+   ssp0_mux, ssp0, ssp1_mux, ssp1, ssp2_mux, ssp2, ssp3_mux, ssp3,
+   ssp4_mux, ssp4, dfc, sdh0_mux, sdh0, sdh1_mux, sdh1, usb, sph,
+   disp0_mux, disp0, disp0_hclk, ccic0_mux, ccic0, ccic0_phy_mux,
+   ccic0_phy, ccic0_sphy_div, ccic0_sphy, clk_max
+};
+
+static struct clk_factor_masks uart_factor_masks = {
+   .factor = 2,
+   .num_mask = 0x1fff,
+   .den_mask = 0x1fff,
+   .num_shift = 16,
+   .den_shift = 0,
+};
+
+static struct clk_factor_tbl uart_factor_tbl[] = {
+   {.num = 8125, .den = 1536}, /*14.745MHZ */
+};
+
+static const char *uart_parent[] = {"pll1_3_16", "uart_pll"};
+static const char *ssp_parent[] =
+   {"pll1_96", "pll1_48", "pll1_24", "pll1_12" };
+static const char *sdh_parent[] = {"pll1_12", "pll1_13"};
+static const char *disp_parent[] = {"pll1_2", "pll1_12"};
+static const char *ccic_parent[] = {"pll1_2", "pll1_12"};
+static const char *ccic_phy_parent[] = {"pll1_6", "pll1_12"};
+
+void __init pxa168_clk_init(void)
+{
+   struct clk *clocks[clk_max];
+   void __iomem *mpmu_base;
+   void __iomem *apmu_base;
+   void __iomem *apbc_base;
+
+   mpmu_base = ioremap(APB_PHYS_BASE + 0x5, SZ_4K);
+   if (mpmu_base == NULL) {
+   pr_err("error to ioremap MPMU base\n");
+   return;
+   }
+
+   apmu_base = ioremap(AXI_PHYS_BASE + 0x82800, SZ_4K);
+   if (apmu_base == NULL) {
+   pr_err("error to ioremap APMU base\n");
+   return;
+   }
+
+   apbc_base = ioremap(APB_PHYS_BASE + 0x15000, SZ_4K);
+   if (apbc_base == NULL) {
+   pr_err("error to ioremap APBC base\n");
+   return;
+   }
+
+   clocks[clk32] =
+   clk_register_fixed_rate(NULL, "clk32", NULL, CLK_IS_ROOT, 3200);
+   clk_register_clkdev(clocks[clk32], "clk32", NULL);
+
+   clocks[vctcxo] =
+   clk_register_fixed_rate(NULL, "vctcxo", NULL, CLK_IS_ROOT,
+   2600);
+   clk_register_clkdev(clocks[vctcxo], "vctcxo", NULL);
+
+   clocks[pll1] =
+   clk_register_fixed_rate(NULL, "pll1", NULL, CLK_IS_ROOT, 62400);
+   clk_register_clkdev(clocks[pll1], "pll1", NULL);
+
+   clocks[pll1_2] =
+   clk_register_fixed_factor(NULL, "pll1_2", "pll1",
+ CLK_SET_RATE_PARENT, 1, 2);
+   clk_register_clkdev(clocks[pll1_2], "pll1_2", NULL);
+
+   clocks[pll1_4] =
+   clk_register_fixed_factor(NULL, "pll1_4", "pll1_2",
+ CLK_SET_RATE_PARENT, 1, 2);
+   clk_register_clkdev(clocks[pll1_4], "pll1_4", NULL);
+
+   clocks[pll1_8] =
+   clk_register_fixed_factor(NULL, "pll1_8", "pll1_4",
+ CLK_SET_RATE_PARENT, 

[PATCH V2 5/5] arm: mmp: make all SOCs use common clock by default

2012-08-15 Thread Chao Xie
From: Chao Xie 

Signed-off-by: Chao Xie 
---
 arch/arm/mach-mmp/Kconfig |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-mmp/Kconfig b/arch/arm/mach-mmp/Kconfig
index 7fddd01..d697d07 100644
--- a/arch/arm/mach-mmp/Kconfig
+++ b/arch/arm/mach-mmp/Kconfig
@@ -108,18 +108,21 @@ endmenu
 config CPU_PXA168
bool
select CPU_MOHAWK
+   select COMMON_CLK
help
  Select code specific to PXA168
 
 config CPU_PXA910
bool
select CPU_MOHAWK
+   select COMMON_CLK
help
  Select code specific to PXA910
 
 config CPU_MMP2
bool
select CPU_PJ4
+   select COMMON_CLK
help
  Select code specific to MMP2. MMP2 is ARMv7 compatible.
 
-- 
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH V2 1/5] clk: mmp: add mmp specific clocks

2012-08-15 Thread Chao Xie
From: Chao Xie 

add mmp specific clocks including apbc cloks, apmu clocks,
and pll2, fraction clocks

Signed-off-by: Chao Xie 
---
 drivers/clk/Makefile   |3 +
 drivers/clk/mmp/Makefile   |5 ++
 drivers/clk/mmp/clk-apbc.c |  152 +++
 drivers/clk/mmp/clk-apmu.c |   97 
 drivers/clk/mmp/clk-frac.c |  153 
 drivers/clk/mmp/clk.h  |   35 ++
 6 files changed, 445 insertions(+), 0 deletions(-)
 create mode 100644 drivers/clk/mmp/Makefile
 create mode 100644 drivers/clk/mmp/clk-apbc.c
 create mode 100644 drivers/clk/mmp/clk-apmu.c
 create mode 100644 drivers/clk/mmp/clk-frac.c
 create mode 100644 drivers/clk/mmp/clk.h

diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index 5869ea3..58590c8 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -10,6 +10,9 @@ obj-$(CONFIG_ARCH_SOCFPGA)+= socfpga/
 obj-$(CONFIG_PLAT_SPEAR)   += spear/
 obj-$(CONFIG_ARCH_U300)+= clk-u300.o
 obj-$(CONFIG_ARCH_INTEGRATOR)  += versatile/
+ifeq ($(CONFIG_COMMON_CLK), y)
+obj-$(CONFIG_ARCH_MMP) += mmp/
+endif
 
 # Chip specific
 obj-$(CONFIG_COMMON_CLK_WM831X) += clk-wm831x.o
diff --git a/drivers/clk/mmp/Makefile b/drivers/clk/mmp/Makefile
new file mode 100644
index 000..b5bc88c
--- /dev/null
+++ b/drivers/clk/mmp/Makefile
@@ -0,0 +1,5 @@
+#
+# Makefile for mmp specific clk
+#
+
+obj-y += clk-apbc.o clk-apmu.o clk-frac.o
diff --git a/drivers/clk/mmp/clk-apbc.c b/drivers/clk/mmp/clk-apbc.c
new file mode 100644
index 000..be3b154
--- /dev/null
+++ b/drivers/clk/mmp/clk-apbc.c
@@ -0,0 +1,152 @@
+/*
+ * mmp APB clock operation source file
+ *
+ * Copyright (C) 2012 Marvell
+ * Chao Xie 
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "clk.h"
+
+/* Common APB clock register bit definitions */
+#define APBC_APBCLK(1 << 0)  /* APB Bus Clock Enable */
+#define APBC_FNCLK (1 << 1)  /* Functional Clock Enable */
+#define APBC_RST   (1 << 2)  /* Reset Generation */
+#define APBC_POWER (1 << 7)  /* Reset Generation */
+
+#define to_clk_apbc(hw) container_of(hw, struct clk_apbc, hw)
+struct clk_apbc {
+   struct clk_hw   hw;
+   void __iomem*base;
+   unsigned intdelay;
+   unsigned intflags;
+   spinlock_t  *lock;
+};
+
+static int clk_apbc_prepare(struct clk_hw *hw)
+{
+   struct clk_apbc *apbc = to_clk_apbc(hw);
+   unsigned int data;
+   unsigned long flags = 0;
+
+   /*
+* It may share same register as MUX clock,
+* and it will impact FNCLK enable. Spinlock is needed
+*/
+   if (apbc->lock)
+   spin_lock_irqsave(apbc->lock, flags);
+
+   data = __raw_readl(apbc->base);
+   if (apbc->flags & APBC_POWER_CTRL)
+   data |= APBC_POWER;
+   data |= APBC_FNCLK;
+   __raw_writel(data, apbc->base);
+
+   if (apbc->lock)
+   spin_unlock_irqrestore(apbc->lock, flags);
+
+   udelay(apbc->delay);
+
+   if (apbc->lock)
+   spin_lock_irqsave(apbc->lock, flags);
+
+   data = __raw_readl(apbc->base);
+   data |= APBC_APBCLK;
+   __raw_writel(data, apbc->base);
+
+   if (apbc->lock)
+   spin_unlock_irqrestore(apbc->lock, flags);
+
+   udelay(apbc->delay);
+
+   if (!(apbc->flags & APBC_NO_BUS_CTRL)) {
+   if (apbc->lock)
+   spin_lock_irqsave(apbc->lock, flags);
+
+   data = __raw_readl(apbc->base);
+   data &= ~APBC_RST;
+   __raw_writel(data, apbc->base);
+
+   if (apbc->lock)
+   spin_unlock_irqrestore(apbc->lock, flags);
+   }
+
+   return 0;
+}
+
+static void clk_apbc_unprepare(struct clk_hw *hw)
+{
+   struct clk_apbc *apbc = to_clk_apbc(hw);
+   unsigned long data;
+   unsigned long flags = 0;
+
+   if (apbc->lock)
+   spin_lock_irqsave(apbc->lock, flags);
+
+   data = __raw_readl(apbc->base);
+   if (apbc->flags & APBC_POWER_CTRL)
+   data &= ~APBC_POWER;
+   data &= ~APBC_FNCLK;
+   __raw_writel(data, apbc->base);
+
+   if (apbc->lock)
+   spin_unlock_irqrestore(apbc->lock, flags);
+
+   udelay(10);
+
+   if (apbc->lock)
+   spin_lock_irqsave(apbc->lock, flags);
+
+   data = __raw_readl(apbc->base);
+   data &= ~APBC_APBCLK;
+   __raw_writel(data, apbc->base);
+
+   if (apbc->lock)
+   spin_unlock_irqrestore(apbc->lock, flags);
+}
+
+struct clk_ops clk_apbc_ops = {
+   .prepare = clk_apbc_prepare,
+   .unprepare = clk_apbc_unprepare,
+};
+
+struct clk 

[PATCH V2 0/5] clk: mmp: add clock framework for mmp

2012-08-15 Thread Chao Xie
From: Chao Xie 

v1->v2:
replace __raw_xxx with xxx_relax
use ioremap to remap the registers. Finaly it will use device tree to
get the physical address.
do not use macro to register clocks, and directly call the functions.

Chao Xie (5):
  clk: mmp: add mmp specific clocks
  clk: mmp: add clock definition for pxa168
  clk: mmp: add clock definition for pxa910
  clk: mmp: add clock definition for mmp2
  arm: mmp: make all SOCs use common clock by default

 arch/arm/mach-mmp/Kconfig|3 +
 drivers/clk/Makefile |3 +
 drivers/clk/mmp/Makefile |9 +
 drivers/clk/mmp/clk-apbc.c   |  152 
 drivers/clk/mmp/clk-apmu.c   |   97 
 drivers/clk/mmp/clk-frac.c   |  153 
 drivers/clk/mmp/clk-mmp2.c   |  544 ++
 drivers/clk/mmp/clk-pxa168.c |  414 
 drivers/clk/mmp/clk-pxa910.c |  361 
 drivers/clk/mmp/clk.h|   35 +++
 10 files changed, 1771 insertions(+), 0 deletions(-)
 create mode 100644 drivers/clk/mmp/Makefile
 create mode 100644 drivers/clk/mmp/clk-apbc.c
 create mode 100644 drivers/clk/mmp/clk-apmu.c
 create mode 100644 drivers/clk/mmp/clk-frac.c
 create mode 100644 drivers/clk/mmp/clk-mmp2.c
 create mode 100644 drivers/clk/mmp/clk-pxa168.c
 create mode 100644 drivers/clk/mmp/clk-pxa910.c
 create mode 100644 drivers/clk/mmp/clk.h

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH V5 13/18] drm: Define SAREA_MAX for Loongson (PageSize = 16KB).

2012-08-15 Thread Matt Turner
On Sat, Aug 11, 2012 at 2:32 AM, Huacai Chen  wrote:
> Signed-off-by: Huacai Chen 
> Signed-off-by: Hongliang Tao 
> Signed-off-by: Hua Yan 
> Cc: dri-de...@lists.freedesktop.org
> ---
>  include/drm/drm_sarea.h |2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
>
> diff --git a/include/drm/drm_sarea.h b/include/drm/drm_sarea.h
> index ee5389d..1d1a858 100644
> --- a/include/drm/drm_sarea.h
> +++ b/include/drm/drm_sarea.h
> @@ -37,6 +37,8 @@
>  /* SAREA area needs to be at least a page */
>  #if defined(__alpha__)
>  #define SAREA_MAX   0x2000U
> +#elif defined(__mips__)
> +#define SAREA_MAX   0x4000U
>  #elif defined(__ia64__)
>  #define SAREA_MAX   0x1U   /* 64kB */
>  #else
> --
> 1.7.7.3

SAREA is a DRI-1 concept. The Radeon drivers you're using is DRI-2, so
what do you need this for? All the DRI-1 drivers have been removed
from Mesa, so I think the answer is nothing.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


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

2012-08-15 Thread Stephen Rothwell
Hi all,

After merging the infiniband tree, today's linux-next build (powerpc
ppc64_defconfig) failed like this:

drivers/net/ethernet/mellanox/mlx4/mr.c: In function 'mlx4_buddy_init':
drivers/net/ethernet/mellanox/mlx4/mr.c:134:4: error: implicit declaration of 
function 'vzalloc' [-Werror=implicit-function-declaration]
drivers/net/ethernet/mellanox/mlx4/mr.c:134:19: warning: assignment makes 
pointer from integer without a cast [enabled by default]
drivers/net/ethernet/mellanox/mlx4/mr.c:148:4: error: implicit declaration of 
function 'vfree' [-Werror=implicit-function-declaration]
cc1: some warnings being treated as errors

Caused by commit 2354c0904331 ("mlx4_core: Allow large mlx4_buddy
bitmaps") which added the vmalloc call (which was changed to vzalloc by
commit 09e22f30018b ("mlx4_core: Clean up buddy bitmap allocation").  The
include of vmalloc.h is missing.  See Rule 1 in
Documentation/SubmitChecklist.

I have used the infiniband tree from next-20120814 for today.
-- 
Cheers,
Stephen Rothwells...@canb.auug.org.au


pgpkjaeEiRGCy.pgp
Description: PGP signature


[PATCH 01/25] KEYS: Add payload preparsing opportunity prior to key instantiate or update

2012-08-15 Thread David Howells
Give the key type the opportunity to preparse the payload prior to the
instantiation and update routines being called.  This is done with the
provision of two new key type operations:

int (*preparse)(struct key_preparsed_payload *prep);
void (*free_preparse)(struct key_preparsed_payload *prep);

If the first operation is present, then it is called before key creation (in
the add/update case) or before the key semaphore is taken (in the update and
instantiate cases).  The second operation is called to clean up if the first
was called.

preparse() is given the opportunity to fill in the following structure:

struct key_preparsed_payload {
char*description;
void*type_data[2];
void*payload;
const void  *data;
size_t  datalen;
size_t  quotalen;
};

Before the preparser is called, the first three fields will have been cleared,
the payload pointer and size will be stored in data and datalen and the default
quota size from the key_type struct will be stored into quotalen.

The preparser may parse the payload in any way it likes and may store data in
the type_data[] and payload fields for use by the instantiate() and update()
ops.

The preparser may also propose a description for the key by attaching it as a
string to the description field.  This can be used by passing a NULL or ""
description to the add_key() system call or the key_create_or_update()
function.  This cannot work with request_key() as that required the description
to tell the upcall about the key to be created.

This, for example permits keys that store PGP public keys to generate their own
name from the user ID and public key fingerprint in the key.

The instantiate() and update() operations are then modified to look like this:

int (*instantiate)(struct key *key, struct key_preparsed_payload *prep);
int (*update)(struct key *key, struct key_preparsed_payload *prep);

and the new payload data is passed in *prep, whether or not it was preparsed.

Signed-off-by: David Howells 
---

 Documentation/security/keys.txt  |   50 ++
 fs/cifs/cifs_spnego.c|6 +-
 fs/cifs/cifsacl.c|8 +-
 include/keys/user-type.h |6 +-
 include/linux/key-type.h |   35 +-
 net/ceph/crypto.c|9 +--
 net/dns_resolver/dns_key.c   |6 +-
 net/rxrpc/ar-key.c   |   40 ++-
 security/keys/encrypted-keys/encrypted.c |   16 +++-
 security/keys/key.c  |  108 +-
 security/keys/keyctl.c   |   18 -
 security/keys/keyring.c  |6 +-
 security/keys/request_key_auth.c |8 +-
 security/keys/trusted.c  |   16 +++-
 security/keys/user_defined.c |   14 ++--
 15 files changed, 245 insertions(+), 101 deletions(-)


diff --git a/Documentation/security/keys.txt b/Documentation/security/keys.txt
index aa0dbd7..7d9ca92 100644
--- a/Documentation/security/keys.txt
+++ b/Documentation/security/keys.txt
@@ -412,6 +412,10 @@ The main syscalls are:
  to the keyring. In this case, an error will be generated if the process
  does not have permission to write to the keyring.
 
+ If the key type supports it, if the description is NULL or an empty
+ string, the key type will try and generate a description from the content
+ of the payload.
+
  The payload is optional, and the pointer can be NULL if not required by
  the type. The payload is plen in size, and plen can be zero for an empty
  payload.
@@ -1114,12 +1118,53 @@ The structure has a number of fields, some of which are 
mandatory:
  it should return 0.
 
 
- (*) int (*instantiate)(struct key *key, const void *data, size_t datalen);
+ (*) int (*preparse)(struct key_preparsed_payload *prep);
+
+ This optional method permits the key type to attempt to parse payload
+ before a key is created (add key) or the key semaphore is taken (update or
+ instantiate key).  The structure pointed to by prep looks like:
+
+   struct key_preparsed_payload {
+   char*description;
+   void*type_data[2];
+   void*payload;
+   const void  *data;
+   size_t  datalen;
+   size_t  quotalen;
+   };
+
+ Before calling the method, the caller will fill in data and datalen with
+ the payload blob parameters; quotalen will be filled in with the default
+ quota size from the key type and the rest will be cleared.
+
+ If a description can be proposed from the payload contents, that should be
+ attached as a string to the description field.  This will be used for the
+ key description 

[PATCH 06/25] MPILIB: Reinstate mpi_cmp[_ui]() and export for RSA signature verification

2012-08-15 Thread David Howells
Reinstate and export mpi_cmp() and mpi_cmp_ui() from the MPI library for use by
RSA signature verification as per RFC3447 section 5.2.2 step 1.

Signed-off-by: David Howells 
---

 lib/mpi/Makefile  |1 +
 lib/mpi/mpi-cmp.c |   70 +
 2 files changed, 71 insertions(+)
 create mode 100644 lib/mpi/mpi-cmp.c


diff --git a/lib/mpi/Makefile b/lib/mpi/Makefile
index 45ca90a..019a68c 100644
--- a/lib/mpi/Makefile
+++ b/lib/mpi/Makefile
@@ -14,6 +14,7 @@ mpi-y = \
generic_mpih-add1.o \
mpicoder.o  \
mpi-bit.o   \
+   mpi-cmp.o   \
mpih-cmp.o  \
mpih-div.o  \
mpih-mul.o  \
diff --git a/lib/mpi/mpi-cmp.c b/lib/mpi/mpi-cmp.c
new file mode 100644
index 000..1871e7b
--- /dev/null
+++ b/lib/mpi/mpi-cmp.c
@@ -0,0 +1,70 @@
+/* mpi-cmp.c  -  MPI functions
+ * Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+ *
+ * This file is part of GnuPG.
+ *
+ * GnuPG is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuPG is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#include "mpi-internal.h"
+
+int mpi_cmp_ui(MPI u, unsigned long v)
+{
+   mpi_limb_t limb = v;
+
+   mpi_normalize(u);
+   if (!u->nlimbs && !limb)
+   return 0;
+   if (u->sign)
+   return -1;
+   if (u->nlimbs > 1)
+   return 1;
+
+   if (u->d[0] == limb)
+   return 0;
+   else if (u->d[0] > limb)
+   return 1;
+   else
+   return -1;
+}
+EXPORT_SYMBOL_GPL(mpi_cmp_ui);
+
+int mpi_cmp(MPI u, MPI v)
+{
+   mpi_size_t usize, vsize;
+   int cmp;
+
+   mpi_normalize(u);
+   mpi_normalize(v);
+   usize = u->nlimbs;
+   vsize = v->nlimbs;
+   if (!u->sign && v->sign)
+   return 1;
+   if (u->sign && !v->sign)
+   return -1;
+   if (usize != vsize && !u->sign && !v->sign)
+   return usize - vsize;
+   if (usize != vsize && u->sign && v->sign)
+   return vsize + usize;
+   if (!usize)
+   return 0;
+   cmp = mpihelp_cmp(u->d, v->d, usize);
+   if (!cmp)
+   return 0;
+   if ((cmp < 0 ? 1 : 0) == (u->sign ? 1 : 0))
+   return 1;
+   return -1;
+}
+EXPORT_SYMBOL_GPL(mpi_cmp);

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 09/25] PGPLIB: PGP definitions (RFC 4880)

2012-08-15 Thread David Howells
Provide some useful PGP definitions from RFC 4880.  These describe details of
public key crypto as used by crypto keys for things like signature
verification.

Signed-off-by: David Howells 
---

 include/linux/pgp.h |  206 +++
 1 file changed, 206 insertions(+)
 create mode 100644 include/linux/pgp.h


diff --git a/include/linux/pgp.h b/include/linux/pgp.h
new file mode 100644
index 000..1359f64
--- /dev/null
+++ b/include/linux/pgp.h
@@ -0,0 +1,206 @@
+/* PGP definitions (RFC 4880)
+ *
+ * Copyright (C) 2011 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowe...@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _LINUX_PGP_H
+#define _LINUX_PGP_H
+
+#include 
+
+struct pgp_key_ID {
+   u8 id[8];
+};
+
+struct pgp_time {
+   u8 time[4];
+};
+
+/*
+ * PGP public-key algorithm identifiers [RFC4880: 9.1]
+ */
+enum pgp_pubkey_algo {
+   PGP_PUBKEY_RSA_ENC_OR_SIG   = 1,
+   PGP_PUBKEY_RSA_ENC_ONLY = 2,
+   PGP_PUBKEY_RSA_SIG_ONLY = 3,
+   PGP_PUBKEY_ELGAMAL  = 16,
+   PGP_PUBKEY_DSA  = 17,
+   PGP_PUBKEY__LAST
+};
+
+/*
+ * PGP symmetric-key algorithm identifiers [RFC4880: 9.2]
+ */
+enum pgp_symkey_algo {
+   PGP_SYMKEY_PLAINTEXT= 0,
+   PGP_SYMKEY_IDEA = 1,
+   PGP_SYMKEY_3DES = 2,
+   PGP_SYMKEY_CAST5= 3,
+   PGP_SYMKEY_BLOWFISH = 4,
+   PGP_SYMKEY_AES_128KEY   = 7,
+   PGP_SYMKEY_AES_192KEY   = 8,
+   PGP_SYMKEY_AES_256KEY   = 9,
+   PGP_SYMKEY_TWOFISH_256KEY   = 10,
+};
+
+/*
+ * PGP compression algorithm identifiers [RFC4880: 9.3]
+ */
+enum pgp_compr_algo {
+   PGP_COMPR_UNCOMPRESSED  = 0,
+   PGP_COMPR_ZIP   = 1,
+   PGP_COMPR_ZLIB  = 2,
+   PGP_COMPR_BZIP2 = 3,
+};
+
+/*
+ * PGP hash algorithm identifiers [RFC4880: 9.4]
+ */
+enum pgp_hash_algo {
+   PGP_HASH_MD5= 1,
+   PGP_HASH_SHA1   = 2,
+   PGP_HASH_RIPE_MD_160= 3,
+   PGP_HASH_SHA256 = 8,
+   PGP_HASH_SHA384 = 9,
+   PGP_HASH_SHA512 = 10,
+   PGP_HASH_SHA224 = 11,
+   PGP_HASH__LAST
+};
+
+extern const char *const pgp_hash_algorithms[PGP_HASH__LAST];
+
+/*
+ * PGP packet type tags [RFC4880: 4.3].
+ */
+enum pgp_packet_tag {
+   PGP_PKT_RESERVED= 0,
+   PGP_PKT_PUBKEY_ENC_SESSION_KEY  = 1,
+   PGP_PKT_SIGNATURE   = 2,
+   PGP_PKT_SYMKEY_ENC_SESSION_KEY  = 3,
+   PGP_PKT_ONEPASS_SIGNATURE   = 4,
+   PGP_PKT_SECRET_KEY  = 5,
+   PGP_PKT_PUBLIC_KEY  = 6,
+   PGP_PKT_SECRET_SUBKEY   = 7,
+   PGP_PKT_COMPRESSED_DATA = 8,
+   PGP_PKT_SYM_ENC_DATA= 9,
+   PGP_PKT_MARKER  = 10,
+   PGP_PKT_LITERAL_DATA= 11,
+   PGP_PKT_TRUST   = 12,
+   PGP_PKT_USER_ID = 13,
+   PGP_PKT_PUBLIC_SUBKEY   = 14,
+   PGP_PKT_USER_ATTRIBUTE  = 17,
+   PGP_PKT_SYM_ENC_AND_INTEG_DATA  = 18,
+   PGP_PKT_MODIFY_DETECT_CODE  = 19,
+   PGP_PKT_PRIVATE_0   = 60,
+   PGP_PKT_PRIVATE_3   = 63,
+   PGP_PKT__HIGHEST= 63
+};
+
+/*
+ * Signature (tag 2) packet [RFC4880: 5.2].
+ */
+enum pgp_signature_version {
+   PGP_SIG_VERSION_3   = 3,
+   PGP_SIG_VERSION_4   = 4,
+};
+
+enum pgp_signature_type {
+   PGP_SIG_BINARY_DOCUMENT_SIG = 0x00,
+   PGP_SIG_CANONICAL_TEXT_DOCUMENT_SIG = 0x01,
+   PGP_SIG_STANDALONE_SIG  = 0x02,
+   PGP_SIG_GENERAL_CERT_OF_UID_PUBKEY  = 0x10,
+   PGP_SIG_PERSONAL_CERT_OF_UID_PUBKEY = 0x11,
+   PGP_SIG_CASUAL_CERT_OF_UID_PUBKEY   = 0x12,
+   PGP_SIG_POSTITIVE_CERT_OF_UID_PUBKEY= 0x13,
+   PGP_SIG_SUBKEY_BINDING_SIG  = 0x18,
+   PGP_SIG_PRIMARY_KEY_BINDING_SIG = 0x19,
+   PGP_SIG_DIRECTLY_ON_KEY = 0x1F,
+   PGP_SIG_KEY_REVOCATION_SIG  = 0x20,
+   PGP_SIG_SUBKEY_REVOCATION_SIG   = 0x28,
+   PGP_SIG_CERT_REVOCATION_SIG = 0x30,
+   PGP_SIG_TIMESTAMP_SIG   = 0x40,
+   PGP_SIG_THIRD_PARTY_CONFIRM_SIG = 0x50,
+};
+
+struct pgp_signature_v3_packet {
+   enum pgp_signature_version version : 8; /* == PGP_SIG_VERSION_3 */
+   u8  length_of_hashed;   /* == 5 */
+   struct {
+   enum 

[PATCH 02/25] MPILIB: Provide count_leading/trailing_zeros() based on arch functions

2012-08-15 Thread David Howells
Provide count_leading/trailing_zeros() macros based on extant arch bit scanning
functions rather than reimplementing from scratch in MPILIB.

Whilst we're at it, turn count_foo_zeros(n, x) into n = count_foo_zeros(x).

Also move the definition to asm-generic as other people may be interested in
using it.

Signed-off-by: David Howells 
Cc: David S. Miller 
Cc: Dmitry Kasatkin 
Cc: Arnd Bergmann 
---

 include/asm-generic/bitops/count_zeros.h |   57 
 lib/mpi/longlong.h   |  138 --
 lib/mpi/mpi-bit.c|2 
 lib/mpi/mpi-pow.c|4 -
 4 files changed, 62 insertions(+), 139 deletions(-)
 create mode 100644 include/asm-generic/bitops/count_zeros.h


diff --git a/include/asm-generic/bitops/count_zeros.h 
b/include/asm-generic/bitops/count_zeros.h
new file mode 100644
index 000..97520d2
--- /dev/null
+++ b/include/asm-generic/bitops/count_zeros.h
@@ -0,0 +1,57 @@
+/* Count leading and trailing zeros functions
+ *
+ * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowe...@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _ASM_GENERIC_BITOPS_COUNT_ZEROS_H_
+#define _ASM_GENERIC_BITOPS_COUNT_ZEROS_H_
+
+#include 
+
+/**
+ * count_leading_zeros - Count the number of zeros from the MSB back
+ * @x: The value
+ *
+ * Count the number of leading zeros from the MSB going towards the LSB in @x.
+ *
+ * If the MSB of @x is set, the result is 0.
+ * If only the LSB of @x is set, then the result is BITS_PER_LONG-1.
+ * If @x is 0 then the result is COUNT_LEADING_ZEROS_0.
+ */
+static inline int count_leading_zeros(unsigned long x)
+{
+   if (sizeof(x) == 4)
+   return BITS_PER_LONG - fls(x);
+   else
+   return BITS_PER_LONG - fls64(x);
+}
+
+#define COUNT_LEADING_ZEROS_0 BITS_PER_LONG
+
+/**
+ * count_trailing_zeros - Count the number of zeros from the LSB forwards
+ * @x: The value
+ *
+ * Count the number of trailing zeros from the LSB going towards the MSB in @x.
+ *
+ * If the LSB of @x is set, the result is 0.
+ * If only the MSB of @x is set, then the result is BITS_PER_LONG-1.
+ * If @x is 0 then the result is COUNT_TRAILING_ZEROS_0.
+ */
+static inline int count_trailing_zeros(unsigned long x)
+{
+#define COUNT_TRAILING_ZEROS_0 (-1)
+
+   if (sizeof(x) == 4)
+   return ffs(x);
+   else
+   return (x != 0) ? __ffs(x) : COUNT_TRAILING_ZEROS_0;
+}
+
+#endif /* _ASM_GENERIC_BITOPS_COUNT_ZEROS_H_ */
diff --git a/lib/mpi/longlong.h b/lib/mpi/longlong.h
index 29f9862..678ce4f 100644
--- a/lib/mpi/longlong.h
+++ b/lib/mpi/longlong.h
@@ -19,6 +19,8 @@
  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  * MA 02111-1307, USA. */
 
+#include 
+
 /* You have to define the following before including this file:
  *
  * UWtype -- An unsigned type, default type for operations (typically a "word")
@@ -146,12 +148,6 @@ do { \
: "1" ((USItype)(n1)), \
"r" ((USItype)(n0)), \
"r" ((USItype)(d)))
-
-#define count_leading_zeros(count, x) \
-   __asm__ ("clz %0,%1" \
-   : "=r" ((USItype)(count)) \
-   : "r" ((USItype)(x)))
-#define COUNT_LEADING_ZEROS_0 32
 #endif /* __a29k__ */
 
 #if defined(__alpha) && W_TYPE_SIZE == 64
@@ -298,11 +294,6 @@ extern UDItype __udiv_qrnnd();
: "1" ((USItype)(nh)), \
"0" ((USItype)(nl)), \
"g" ((USItype)(d)))
-#define count_leading_zeros(count, x) \
-   __asm__ ("bsch/1 %1,%0" \
-   : "=g" (count) \
-   : "g" ((USItype)(x)), \
-"0" ((USItype)0))
 #endif
 
 /***
@@ -354,27 +345,6 @@ do { USItype __r; \
 } while (0)
 extern USItype __udiv_qrnnd();
 #endif /* LONGLONG_STANDALONE */
-#define count_leading_zeros(count, x) \
-do { \
-   USItype __tmp; \
-   __asm__ ( \
-   "ldi 1,%0\n" \
-   "extru,=%1,15,16,%%r0  ; Bits 31..16 zero?\n" \
-   "extru,tr   %1,15,16,%1; No.  Shift down, skip add.\n" \
-   "ldo16(%0),%0  ; Yes.   Perform add.\n" \
-   "extru,=%1,23,8,%%r0   ; Bits 15..8 zero?\n" \
-   "extru,tr   %1,23,8,%1 ; No.  Shift down, skip add.\n" \
-   "ldo8(%0),%0   ; Yes.   Perform add.\n" \
-   "extru,=%1,27,4,%%r0   ; Bits 7..4 zero?\n" \
-   "extru,tr   %1,27,4,%1 ; No.  Shift down, skip add.\n" \
-   "ldo4(%0),%0   ; Yes.   Perform add.\n" \
-   "extru,=%1,29,2,%%r0   ; Bits 3..2 zero?\n" \
-   "extru,tr   %1,29,2,%1 ; No.  Shift down, skip add.\n" \
-   "ldo2(%0),%0   ; Yes.   Perform 

[PATCH 25/25] MODSIGN: Fix documentation of signed-nokey behavior when not enforcing.

2012-08-15 Thread David Howells
jwboyer's previous commit changes the behavior of module signing when
there's a valid signature but we don't know the public key and are in
permissive mode.  This updates the documentation to match.

Signed-off-by: Peter Jones 
Acked-by: Josh Boyer 
Signed-off-by: David Howells 
---

 Documentation/module-signing.txt |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


diff --git a/Documentation/module-signing.txt b/Documentation/module-signing.txt
index b355aa2..2549536 100644
--- a/Documentation/module-signing.txt
+++ b/Documentation/module-signing.txt
@@ -174,7 +174,7 @@ This table indicates the behaviours of the various 
situations:
MODULE STATEPERMISSIVE MODE ENFORCING MODE
=== === ===
UnsignedOk  EKEYREJECTED
-   Signed, no public key   ENOKEY  ENOKEY
+   Signed, no public key   Ok  ENOKEY
Validly signed, public key  Ok  Ok
Invalidly signed, public keyEKEYREJECTEDEKEYREJECTED
Validly signed, expired key EKEYEXPIRED EKEYEXPIRED

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 24/25] MODSIGN: Allow modules to be signed with an unknown key unless enforcing

2012-08-15 Thread David Howells
Currently we fail the loading of modules that are signed with a public key
that is not in the modsign keyring even if we are not in enforcing mode.
This is somewhat at odds with the fact that we allow a completely unsigned
module to load in such a case.

We should allow modules signed with an unknown key to load in cases
where we are not enforcing and not in FIPS mode.

Signed-off-by: Josh Boyer 
Signed-off-by: David Howells 
---

 kernel/module-verify.c |7 +++
 1 file changed, 7 insertions(+)


diff --git a/kernel/module-verify.c b/kernel/module-verify.c
index 070d730..c02d2e5 100644
--- a/kernel/module-verify.c
+++ b/kernel/module-verify.c
@@ -124,6 +124,13 @@ int module_verify(const void *data, size_t size, bool 
*_gpgsig_ok)
break;
case -ENOKEY:   /* Signed, but we don't have the public key */
pr_err("Module signed with unknown public key\n");
+   if (!modsign_signedonly) {
+   /* Allow a module to be signed with an unknown public
+* key unless we're enforcing.
+*/
+   pr_info("Allowing\n");
+   ret = 0;
+   }
break;
default:/* Other error (probably ENOMEM) */
break;

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 23/25] MODSIGN: Panic the kernel if FIPS is enabled upon module signing failure

2012-08-15 Thread David Howells
If module signing fails when the kernel is running with FIPS enabled then the
kernel should panic lest the crypto layer be compromised.  Possibly a panic
shouldn't happen on cases like ENOMEM.

Reported-by: Stephan Mueller 
Signed-off-by: David Howells 
---

 kernel/module-verify.c |5 +
 1 file changed, 5 insertions(+)


diff --git a/kernel/module-verify.c b/kernel/module-verify.c
index 6684e24..070d730 100644
--- a/kernel/module-verify.c
+++ b/kernel/module-verify.c
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include "module-verify.h"
 
@@ -97,6 +98,10 @@ int module_verify(const void *data, size_t size, bool 
*_gpgsig_ok)
 
pr_devel("module_verify_signature() = %d\n", ret);
 
+if (ret < 0 && fips_enabled)
+panic("Module verification failed with error %d in FIPS 
mode\n",
+  ret);
+
switch (ret) {
case 0: /* Good signature */
*_gpgsig_ok = true;

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 22/25] MODSIGN: Automatically generate module signing keys if missing

2012-08-15 Thread David Howells
Automatically generate keys for module signing if they're absent so that
allyesconfig doesn't break.  The builder should consider generating their own
keyrings, however, so that the keys are appropriately named and any extra keys
required get imported.

Also change the names of the keyring files to modsign.pub and modsign.sec so
that they are then a more obvious what they're about and add a dependency for
the signing rules on the keyring files so that the signatures get regenerated
if the keyrings change.

Signed-off-by: David Howells 
---

 kernel/Makefile |   39 +++
 1 file changed, 39 insertions(+)


diff --git a/kernel/Makefile b/kernel/Makefile
index 895bef0..f612ed0 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -133,4 +133,43 @@ targets += timeconst.h
 $(obj)/timeconst.h: $(src)/timeconst.pl FORCE
$(call if_changed,timeconst)
 
+###
+#
+# If module signing is requested, say by allyesconfig, but a key has not been
+# supplied, then one will need to be generated to make sure the build does not
+# fail and that the kernel may be used afterwards.
+#
+###
+ifeq ($(CONFIG_MODULE_SIG),y)
 kernel/modsign-pubkey.o: modsign.pub
+
+modsign.pub modsign.sec: genkey
+   @echo "###"
+   @echo "### Now generating a PGP key pair to be used for signing 
modules."
+   @echo "###"
+   @echo "### If this takes a long time, you might wish to run rngd in the"
+   @echo "### background to keep the supply of entropy topped up.  It"
+   @echo "### needs to be run as root, and should use a hardware random"
+   @echo "### number generator if one is available, eg:"
+   @echo "###"
+   @echo "### rngd -r /dev/hwrandom"
+   @echo "###"
+   gpg --homedir . --batch --gen-key genkey
+   @echo "###"
+   @echo "### Key pair generated."
+   @echo "###"
+   rm -f pubring.gpg secring.gpg trustdb.gpg
+
+genkey:
+   echo "%pubring modsign.pub" >genkey
+   echo "%secring modsign.sec" >>genkey
+   echo "%no-protection: yes" >> genkey
+   echo "%transient-key: yes" >>genkey
+   echo "Key-Type: RSA" >>genkey
+   echo "Key-Length: 4096" >>genkey
+   echo "Name-Real: Sample kernel key" >>genkey
+   echo "Name-Comment: Sample kernel module signing key" >>genkey
+   echo "%commit" >>genkey
+
+endif
+CLEAN_FILES += modsign.pub modsign.sec genkey random_seed

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 21/25] MODSIGN: Module signature verification

2012-08-15 Thread David Howells
Apply signature checking to modules on module load, checking the signature
against the ring of public keys compiled into the kernel (if enabled by
CONFIG_MODULE_SIG).

There are several reasons why these patches are useful, amongst which are:

 (1) to prevent accidentally corrupted modules from causing damage;

 (2) to prevent maliciously modified modules from causing damage;

 (3) to allow a sysadmin (or more likely an IT department) to enforce a policy
 that only known and approved modules shall be loaded onto machines which
 they're expected to support;

 (4) to allow other support providers to do likewise, or at least to _detect_
 the fact that unsupported modules are loaded;

 (5) to allow the detection of modules replaced by a second-order distro or a
 preloaded Linux purveyor.

These patches have two main appeals: (a) preventing malicious modules from
being loaded, and (b) reducing support workload by pointing out modules on a
crashing box that aren't what they're expected to be.

Note that this is not a complete solution by any means: the core kernel is not
protected, and nor are /dev/mem or /dev/kmem, but it denies (or at least
controls) one relatively simple attack vector.  To protect the kernel image
would be the responsibility of the boot loader or the system BIOS.

This facility is optional: the builder of a kernel is by no means under any
requirement to actually enable it, let alone force the set of loadable modules
to be restricted to just those that the builder provides (there are degrees of
restriction available).

If CONFIG_MODULE_SIG_FORCE is enabled or "enforcemodulesig=1" is supplied on
the kernel command line, the kernel will _only_ load validly signed modules
for which it has a public key.  Otherwise, it will also load modules that are
unsigned.  Any module for which the kernel has a key, but which proves to have
a signature mismatch will not be permitted to load.

This table indicates the behaviours in the various situations:

MODULE STATEPERMISSIVE MODE ENFORCING MODE
=== === ===
UnsignedOk  EKEYREJECTED
Signed, no public key   ENOKEY  ENOKEY
Validly signed, public key  Ok  Ok
Invalidly signed, public keyEKEYREJECTEDEKEYREJECTED
Validly signed, expired key EKEYEXPIRED EKEYEXPIRED
Signed, hash algorithm unavailable  ENOPKG  ENOPKG
Signed, pubkey algorithm unavailableENOPKG  ENOPKG
Signature without sig packetENOMSG  ENOMSG
Corrupt signature   EBADMSG EBADMSG
Corrupt fileELIBBAD ELIBBAD


===
!!!IMPORTANT WARNING!!!
===

Signed modules generated by this kernel very likely CANNOT be used with
existing packaging and installation infrastructure.  For example, in Fedora's
environment, the module is potentially stripped at least twice:

 (1) by rpmbuild when the debuginfo is detached from the module, and

 (2) by the initrd image composer to reduce the module size.

Both of these will potentially result in the module signature being discarded
or rendered unverifiable, resulting in the module load just going ahead if the
signature magic is not found and enforcemodulesig=1 not being supplied or
-EKEYREJECTED being given or a panic being forced if FIPS mode is engaged.

To aid with (2), the module is completely stripped prior to signing as it
cannot be stripped after signing.  Both "strip -x -g" and "eu-strip" are
applied as the use of both of these results in a smaller binary.

That, however, means there is no debug information directly available for the
module.

The original unstripped binary for the foo.ko module can be found as
foo.ko.unsigned in the build tree.  It may be possible to use this as the debug
info source.

Signed-off-by: David Howells 
---

 include/linux/module.h |3 +
 kernel/Makefile|2 -
 kernel/module-verify.c |  136 
 kernel/module-verify.h |6 ++
 kernel/module.c|   26 +++--
 5 files changed, 167 insertions(+), 6 deletions(-)
 create mode 100644 kernel/module-verify.c


diff --git a/include/linux/module.h b/include/linux/module.h
index fbcafe2..7391833 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -227,6 +227,9 @@ struct module
/* Unique handle for this module */
char name[MODULE_NAME_LEN];
 
+   /* Is this module GPG signed */
+   bool gpgsig_ok;
+
/* Sysfs stuff. */
struct module_kobject mkobj;
struct module_attribute *modinfo_attrs;
diff --git a/kernel/Makefile b/kernel/Makefile
index 84f6c04..895bef0 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ 

[PATCH 20/25] MODSIGN: Provide module signing public keys to the kernel

2012-08-15 Thread David Howells
Include a PGP keyring containing the public keys required to perform module
verification in the kernel image during build and create a special keyring
during boot which is then populated with keys of crypto type holding the public
keys found in the PGP keyring.

These can be seen by root:

[root@andromeda ~]# cat /proc/keys
07ad4ee0 I- 1 perm 3f01 0 0 cryptomodsign.0: RSA 
87b9b3bd []
15c7f8c3 I- 1 perm 1f03 0 0 keyring   .module_sign: 1/4
...

It is probably worth permitting root to invalidate these keys, resulting in
their removal and preventing further modules from being loaded with that key.

Signed-off-by: David Howells 
---

 kernel/Makefile |3 ++
 kernel/modsign-pubkey.c |   74 +++
 kernel/module-verify.h  |   14 +
 3 files changed, 91 insertions(+)
 create mode 100644 kernel/modsign-pubkey.c
 create mode 100644 kernel/module-verify.h


diff --git a/kernel/Makefile b/kernel/Makefile
index c0cc67a..84f6c04 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -55,6 +55,7 @@ obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock.o
 obj-$(CONFIG_PROVE_LOCKING) += spinlock.o
 obj-$(CONFIG_UID16) += uid16.o
 obj-$(CONFIG_MODULES) += module.o
+obj-$(CONFIG_MODULE_SIG) += modsign-pubkey.o
 obj-$(CONFIG_KALLSYMS) += kallsyms.o
 obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o
 obj-$(CONFIG_KEXEC) += kexec.o
@@ -131,3 +132,5 @@ quiet_cmd_timeconst  = TIMEC   $@
 targets += timeconst.h
 $(obj)/timeconst.h: $(src)/timeconst.pl FORCE
$(call if_changed,timeconst)
+
+kernel/modsign-pubkey.o: modsign.pub
diff --git a/kernel/modsign-pubkey.c b/kernel/modsign-pubkey.c
new file mode 100644
index 000..ce14c9a
--- /dev/null
+++ b/kernel/modsign-pubkey.c
@@ -0,0 +1,74 @@
+/* Public keys for module signature verification
+ *
+ * Copyright (C) 2011 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowe...@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include "module-verify.h"
+
+struct key *modsign_keyring;
+
+extern __initdata const u8 modsign_public_keys[];
+extern __initdata const u8 modsign_public_keys_end[];
+asm(".section .init.data,\"aw\"\n"
+"modsign_public_keys:\n"
+".incbin \"modsign.pub\"\n"
+"modsign_public_keys_end:"
+);
+
+/*
+ * We need to make sure ccache doesn't cache the .o file as it doesn't notice
+ * if modsign.pub changes.
+ */
+static __initdata const char annoy_ccache[] = __TIME__ "foo";
+
+/*
+ * Load the compiled-in keys
+ */
+static __init int module_verify_init(void)
+{
+   pr_notice("Initialise module verification\n");
+
+   modsign_keyring = key_alloc(_type_keyring, ".module_sign",
+   0, 0, current_cred(),
+   (KEY_POS_ALL & ~KEY_POS_SETATTR) |
+   KEY_USR_VIEW | KEY_USR_READ,
+   KEY_ALLOC_NOT_IN_QUOTA);
+   if (IS_ERR(modsign_keyring))
+   panic("Can't allocate module signing keyring\n");
+
+   if (key_instantiate_and_link(modsign_keyring, NULL, 0, NULL, NULL) < 0)
+   panic("Can't instantiate module signing keyring\n");
+
+   return 0;
+}
+
+/*
+ * Must be initialised before we try and load the keys into the keyring.
+ */
+device_initcall(module_verify_init);
+
+/*
+ * Load the compiled-in keys
+ */
+static __init int modsign_pubkey_init(void)
+{
+   pr_notice("Load module verification keys\n");
+
+   if (preload_pgp_keys(modsign_public_keys,
+modsign_public_keys_end - modsign_public_keys,
+modsign_keyring) < 0)
+   panic("Can't load module signing keys\n");
+
+   return 0;
+}
+late_initcall(modsign_pubkey_init);
diff --git a/kernel/module-verify.h b/kernel/module-verify.h
new file mode 100644
index 000..2f6cc16
--- /dev/null
+++ b/kernel/module-verify.h
@@ -0,0 +1,14 @@
+/* Module verification definitions
+ *
+ * Copyright (C) 2004, 2012 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowe...@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifdef CONFIG_MODULE_SIG
+extern struct key *modsign_keyring;
+#endif

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 19/25] MODSIGN: Sign modules during the build process

2012-08-15 Thread David Howells
If CONFIG_MODULE_SIG is set, then this patch will cause the module to get a
signature installed.  The following steps will occur:

 (1) The module will be linked to foo.ko.unsigned instead of foo.ko

 (2) The module will be stripped using both "strip -x -g" and "eu-strip" to
 ensure minimal size for inclusion in an initramfs.

 (3) The signature will be generated on the stripped module.

 (4) The signature will be appended to the module, along with the payload
 size, the signature size and a magic string.

Step (3) requires private and public keys to be available.  By default these
are expected to be found in PGP keyring files called modsign.sec (the secret
key) and modsign.pub (the public key) in the build root.

If the secret key is not found then signing will be skipped and the unsigned
module from (1) will just be copied to foo.ko.

If signing occurs, lines like the following will be seen:

LD [M]  fs/foo/foo.ko.unsigned
STRIP [M] fs/foo/foo.ko.stripped
SIGN [M] fs/foo/foo.ko

will appear in the build log.  If the signature step will be skipped and the
following will be seen:

LD [M]  fs/foo/foo.ko.unsigned
STRIP [M] fs/foo/foo.ko.stripped
NO SIGN [M] fs/foo/foo.ko

NOTE!  After the signature step, the signed module must not be passed through
strip.  The unstripped, unsigned module is still available at the name on the
LD [M] line.  This restriction may affect packaging tools (such as rpmbuild)
and initramfs composition tools.

Note that I do not agree with this method of attaching signatures to modules.

Signed-off-by: David Howells 
---

 scripts/Makefile.modpost |   99 ++
 1 file changed, 98 insertions(+), 1 deletion(-)


diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost
index 08dce14..cd4d028 100644
--- a/scripts/Makefile.modpost
+++ b/scripts/Makefile.modpost
@@ -14,7 +14,8 @@
 # 3)  create one .mod.c file pr. module
 # 4)  create one Module.symvers file with CRC for all exported symbols
 # 5) compile all .mod.c files
-# 6) final link of the module to a  file
+# 6) final link of the module to a  (or ) file
+# 7) signs the modules to a  file
 
 # Step 3 is used to place certain information in the module's ELF
 # section, including information such as:
@@ -32,6 +33,8 @@
 # Step 4 is solely used to allow module versioning in external modules,
 # where the CRC of each module is retrieved from the Module.symvers file.
 
+# Step 7 is dependent on CONFIG_MODULE_SIG being enabled.
+
 # KBUILD_MODPOST_WARN can be set to avoid error out in case of undefined
 # symbols in the final module linking stage
 # KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules.
@@ -116,6 +119,7 @@ $(modules:.ko=.mod.o): %.mod.o: %.mod.c FORCE
 targets += $(modules:.ko=.mod.o)
 
 # Step 6), final link of the modules
+ifneq ($(CONFIG_MODULE_SIG),y)
 quiet_cmd_ld_ko_o = LD [M]  $@
   cmd_ld_ko_o = $(LD) -r $(LDFLAGS) \
  $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \
@@ -125,7 +129,100 @@ $(modules): %.ko :%.o %.mod.o FORCE
$(call if_changed,ld_ko_o)
 
 targets += $(modules)
+else
+quiet_cmd_ld_ko_unsigned_o = LD [M]  $@
+  cmd_ld_ko_unsigned_o =   \
+   $(LD) -r $(LDFLAGS) \
+$(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \
+-o $@ $(filter-out FORCE,$^)   \
+   $(if $(AFTER_LINK),; $(AFTER_LINK))
+
+$(modules:.ko=.ko.unsigned): %.ko.unsigned :%.o %.mod.o FORCE
+   $(call if_changed,ld_ko_unsigned_o)
+
+targets += $(modules:.ko=.ko.unsigned)
+
+# Step 7), sign the modules
+MODSECKEY = ./modsign.sec
+MODPUBKEY = ./modsign.pub
+KEYFLAGS = --no-default-keyring --secret-keyring $(MODSECKEY) --keyring 
$(MODPUBKEY) --no-default-keyring --homedir . --no-options 
--no-auto-check-trustdb --no-permission-warning
+
+ifdef CONFIG_MODULE_SIG_SHA1
+KEYFLAGS += --digest-algo=SHA1
+else
+ifdef CONFIG_MODULE_SIG_SHA224
+KEYFLAGS += --digest-algo=SHA224
+else
+ifdef CONFIG_MODULE_SIG_SHA256
+KEYFLAGS += --digest-algo=SHA256
+else
+ifdef CONFIG_MODULE_SIG_SHA384
+KEYFLAGS += --digest-algo=SHA384
+else
+ifdef CONFIG_MODULE_SIG_SHA512
+KEYFLAGS += --digest-algo=SHA512
+else
+endif
+endif
+endif
+endif
+endif
+
+ifdef MODKEYNAME
+KEYFLAGS += --default-key $(MODKEYNAME)
+endif
+
+ifeq ($(wildcard $(MODSECKEY))+$(wildcard 
$(MODPUBKEY)),$(MODSECKEY)+$(MODPUBKEY))
+ifeq ($(KBUILD_SRC),)
+   # no O= is being used
+   SCRIPTS_DIR := scripts
+else
+   SCRIPTS_DIR := $(KBUILD_SRC)/scripts
+endif
+SIGN_MODULES := 1
+else
+SIGN_MODULES := 0
+endif
+
+# only sign if it's an in-tree module
+ifneq ($(KBUILD_EXTMOD),)
+SIGN_MODULES := 0
+endif
+
+# We strip the module as best we can - note that using both strip and eu-strip
+# results in a smaller module than using either alone.

[PATCH 18/25] MODSIGN: Provide Documentation and Kconfig options

2012-08-15 Thread David Howells
Provide documentation and kernel configuration options for module signing.

The documentation can be found in:

Documentation/module-signing.txt

The following configuration options are added:

 (1) CONFIG_MODULE_SIG

 Enable module signing.  This will both cause the build process to sign
 modules and the kernel to check modules when they're loaded.

 (2) CONFIG_MODULE_SIG_SHA1
 CONFIG_MODULE_SIG_SHA224
 CONFIG_MODULE_SIG_SHA256
 CONFIG_MODULE_SIG_SHA384
 CONFIG_MODULE_SIG_SHA512

 Select the cryptographic hash used to digest the data prior to signing.
 Additionally, the crypto module selected will be built into the kernel as
 it won't be possible to load it as a module without incurring a circular
 dependency when the kernel tries to check its signature.

 (3) CONFIG_MODULE_SIG_FORCE

 Require that any module loaded must be signed with a key compiled into
 the kernel.  All other modules are rejected with EKEYREJECTED.

Signed-off-by: David Howells 
---

 Documentation/module-signing.txt |  183 ++
 include/linux/modsign.h  |   27 ++
 init/Kconfig |   62 +
 3 files changed, 272 insertions(+)
 create mode 100644 Documentation/module-signing.txt
 create mode 100644 include/linux/modsign.h


diff --git a/Documentation/module-signing.txt b/Documentation/module-signing.txt
new file mode 100644
index 000..b355aa2
--- /dev/null
+++ b/Documentation/module-signing.txt
@@ -0,0 +1,183 @@
+   ==
+   KERNEL MODULE SIGNING FACILITY
+   ==
+
+The module signing facility applies cryptographic signature checking to modules
+on module load, checking the signature against a ring of public keys compiled
+into the kernel.  GPG is used to do the cryptographic work and determines the
+format of the signature and key data.  The facility uses GPG's MPI library to
+handle the huge numbers involved.
+
+The signature checker in the kernel is capable of handling multiple keys of
+either DSA or RSA type, and can support any of MD5, RIPE-MD-160, SHA-1,
+SHA-224, SHA-256, SHA-384 and SHA-512 hashes - PROVIDED(!) the requisite
+algorithms are compiled into the kernel.
+
+(!) NOTE: Modules may only be verified initially with algorithms compiled into
+the kernel.  Further algorithm modules may be loaded and used - but these must
+first pass a verification step using already loaded/compiled-in algorithms.
+
+
+=
+SUPPLYING PUBLIC KEYS
+=
+
+A set of public keys must be supplied at kernel image build time.  This is done
+by taking a GPG public key file and placing it in the base of the kernel
+directory in a file called modsign.pub.
+
+For example, a throwaway key could be generated automatically by something like
+the following:
+
+   cat >genkey <
+
+ This indicates the whereabouts of the GPG keyring that is the source of
+ the public key to be used.  The default is "./modsign.pub".
+
+ (*) MODKEYNAME=
+
+ The name of the key pair to be used from the aforementioned keyrings.
+ This defaults to being unset, thus leaving the choice of default key to
+ gpg.
+
+ (*) KEYFLAGS="gpg-options"
+
+ Override the complete gpg command line, including the preceding three
+ options.  The default options supplied to gpg are:
+
+   --no-default-keyring
+   --secret-keyring $(MODSECKEY)
+   --keyring $(MODPUBKEY)
+   --no-default-keyring
+   --homedir .
+   --no-options
+   --no-auto-check-trustdb
+   --no-permission-warning
+   --digest-algo=
+
+  with:
+
+   --default-key $(MODKEYNAME)
+
+  being added if requested.
+
+The resulting module.ko file will be the signed module.
+
+
+
+SIGNED MODULES AND STRIPPING
+
+
+The module signature is just appended to the module binary with a magic number
+at the end of file, a couple of fixed-size lengths prior to that and the
+signature prior to that.
+
+WARNING! Signed modules are BRITTLE as the signature is outside of the defined
+ELF container.  Thus they MAY NOT be stripped once the signature is computed
+and attached, lest the signature be discarded or the payload be modified.  Note
+that the entire module is the signed payload, including all the debug
+information present at the time of signing so it must still be present when the
+signature is checked.
+
+As the module may need to be included in a ramdisk image of limited capacity,
+modules are maximally stripped prior to signing by the build process.
+
+Note that if FIPS mode is engaged, a module for which the signature does not
+match the payload will panic the box.
+
+
+==
+LOADING SIGNED MODULES
+==
+
+Modules are loaded with insmod, exactly as for unsigned modules.  The signature
+checker will 

[PATCH 17/25] MODSIGN: Provide gitignore and make clean rules for extra files

2012-08-15 Thread David Howells
Provide gitignore and make clean rules for extra files to hide and clean up the
extra files produced by module signing stuff once it is added.  Also add a
clean up rule for the module content extractor program used to extract the data
to be signed.

Signed-off-by: David Howells 
---

 .gitignore |   13 +
 Makefile   |1 +
 2 files changed, 14 insertions(+)


diff --git a/.gitignore b/.gitignore
index 57af07c..4d63081 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,6 +14,10 @@
 *.o.*
 *.a
 *.s
+*.ko.unsigned
+*.ko.stripped
+*.ko.stripped.sig
+*.ko.trailer
 *.ko
 *.so
 *.so.dbg
@@ -84,3 +88,12 @@ GTAGS
 *.orig
 *~
 \#*#
+
+#
+# GPG leavings from module signing
+#
+genkey
+modsign.pub
+modsign.sec
+random_seed
+trustdb.gpg
diff --git a/Makefile b/Makefile
index ddf5be9..70a6b5b 100644
--- a/Makefile
+++ b/Makefile
@@ -1239,6 +1239,7 @@ clean: $(clean-dirs)
$(call cmd,rmfiles)
@find $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
+   -o -name '*.ko.*' \
-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
-o -name '*.symtypes' -o -name 'modules.order' \
-o -name modules.builtin -o -name '.tmp_*.o.*' \

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 16/25] KEYS: Provide a function to load keys from a PGP keyring blob

2012-08-15 Thread David Howells
Provide a function to load keys from a PGP keyring blob for use in initialising
the module signing key keyring:

int load_PGP_keys(const u8 *pgpdata, size_t pgpdatalen,
  struct key *keyring, const char *descprefix);

The keys are labelled with descprefix plus a number to uniquify them.  The keys
will actually be identified by the ID calculated from the PGP data rather than
by the description, so this shouldn't be a problem.

The keys are attached to the keyring supplied.

Looking as root in /proc/keys after the module signing keyring has been loaded:

24460d1c I- 1 perm 3f01 0 0 cryptomodsign.0: dsa 
5acc2142 []
3ca85723 I- 1 perm 1f01 0 0 keyring   .module_sign: 1/4

Thanks to Tetsuo Handa  for some pointing
out some errors.

Signed-off-by: David Howells 
---

 Documentation/security/keys-crypto.txt |   20 ++
 include/keys/crypto-type.h |3 +
 security/keys/crypto/Kconfig   |9 +++
 security/keys/crypto/Makefile  |1 
 security/keys/crypto/pgp_preload.c |  115 
 5 files changed, 148 insertions(+)
 create mode 100644 security/keys/crypto/pgp_preload.c


diff --git a/Documentation/security/keys-crypto.txt 
b/Documentation/security/keys-crypto.txt
index 0a886ec..be5067e 100644
--- a/Documentation/security/keys-crypto.txt
+++ b/Documentation/security/keys-crypto.txt
@@ -10,6 +10,7 @@ Contents:
 - Signature verification.
   - Implementing crypto parsers.
   - Implementing crypto subtypes.
+  - Initial PGP key preloading.
 
 
 
@@ -279,3 +280,22 @@ There are a number of operations defined by the subtype:
  Mandatory.  This should free the memory associated with the key.  The
  crypto key will look after freeing the fingerprint and releasing the
  reference on the subtype module.
+
+
+===
+INITIAL PGP KEY LOADING
+===
+
+A function is provided to perform an initial load of a set of public keys bound
+into a PGP packet format blob:
+
+   int preload_pgp_keys(const u8 *pgpdata, size_t pgpdatalen,
+struct key *keyring);
+
+This takes the blob of data defined by pgpdata and pgpdatalen, extracts keys
+from them and adds them to the specified keyring.  The keys are labelled with a
+description generated from the fingerprint and last user ID of each key.  The
+description is required to prevent all but the last key being discarded when
+the keys are linked into the keyring.
+
+This function is only available during initial kernel set up.
diff --git a/include/keys/crypto-type.h b/include/keys/crypto-type.h
index 0fb362a..ed9b203 100644
--- a/include/keys/crypto-type.h
+++ b/include/keys/crypto-type.h
@@ -31,4 +31,7 @@ extern void verify_sig_cancel(struct 
crypto_sig_verify_context *ctx);
  * The payload is at the discretion of the subtype.
  */
 
+extern __init int preload_pgp_keys(const u8 *pgpdata, size_t pgpdatalen,
+  struct key *keyring);
+
 #endif /* _KEYS_CRYPTO_TYPE_H */
diff --git a/security/keys/crypto/Kconfig b/security/keys/crypto/Kconfig
index 1c2ae55..8af0155 100644
--- a/security/keys/crypto/Kconfig
+++ b/security/keys/crypto/Kconfig
@@ -40,3 +40,12 @@ config CRYPTO_KEY_PGP_PARSER
  This option provides support for parsing PGP (RFC 4880) format blobs
  for key data and provides the ability to instantiate a crypto key
  from a public key packet found inside the blob.
+
+config PGP_PRELOAD
+   bool "PGP public key preloading facility"
+   select PGP_LIBRARY
+   select CRYPTO_KEY_PGP_PARSER
+   help
+ This option provides a facility for the kernel to preload PGP-wrapped
+ bundles of keys during boot.  It is used by module signing to load
+ the module signing keys for example.
diff --git a/security/keys/crypto/Makefile b/security/keys/crypto/Makefile
index a9a34c6..c873674 100644
--- a/security/keys/crypto/Makefile
+++ b/security/keys/crypto/Makefile
@@ -8,6 +8,7 @@ crypto_keys-y := crypto_type.o crypto_verify.o
 obj-$(CONFIG_CRYPTO_KEY_PUBLIC_KEY_SUBTYPE) += public_key.o
 obj-$(CONFIG_CRYPTO_KEY_PKEY_ALGO_RSA) += crypto_rsa.o
 obj-$(CONFIG_PGP_LIBRARY) += pgp_library.o
+obj-$(CONFIG_PGP_PRELOAD) += pgp_preload.o
 
 obj-$(CONFIG_CRYPTO_KEY_PGP_PARSER) += pgp_key_parser.o
 pgp_key_parser-y := \
diff --git a/security/keys/crypto/pgp_preload.c 
b/security/keys/crypto/pgp_preload.c
new file mode 100644
index 000..ca4cfe6
--- /dev/null
+++ b/security/keys/crypto/pgp_preload.c
@@ -0,0 +1,115 @@
+/* Cryptographic key request handling
+ *
+ * Copyright (C) 2011 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowe...@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at 

[PATCH 15/25] KEYS: Provide PGP key description autogeneration

2012-08-15 Thread David Howells
Provide a facility to autogenerate the name of PGP keys from the contents of
the payload.  If add_key() is given a blank description, a description is
constructed from the last user ID packet in the payload data plus the last 8
hex digits of the key ID.  For instance:

keyctl padd crypto "" @s 
---

 security/keys/crypto/pgp_public_key.c |   64 +++--
 1 file changed, 53 insertions(+), 11 deletions(-)


diff --git a/security/keys/crypto/pgp_public_key.c 
b/security/keys/crypto/pgp_public_key.c
index c260e02..2347ecd 100644
--- a/security/keys/crypto/pgp_public_key.c
+++ b/security/keys/crypto/pgp_public_key.c
@@ -52,6 +52,9 @@ struct pgp_key_data_parse_context {
struct crypto_key_subtype *subtype;
char *fingerprint;
void *payload;
+   const char *user_id;
+   size_t user_id_len;
+   size_t fingerprint_len;
 };
 
 /*
@@ -166,6 +169,7 @@ static int pgp_generate_fingerprint(struct 
pgp_key_data_parse_context *ctx,
if (ret < 0)
goto cleanup_raw_fingerprint;
 
+   ctx->fingerprint_len = digest_size * 2;
fingerprint = kmalloc(digest_size * 2 + 1, GFP_KERNEL);
if (!fingerprint)
goto cleanup_raw_fingerprint;
@@ -212,6 +216,13 @@ static int pgp_process_public_key(struct pgp_parse_context 
*context,
 
kenter(",%u,%u,,%zu", type, headerlen, datalen);
 
+   if (type == PGP_PKT_USER_ID) {
+   ctx->user_id = data;
+   ctx->user_id_len = datalen;
+   kleave(" = 0 [user ID]");
+   return 0;
+   }
+
if (ctx->subtype) {
kleave(" = -ENOKEY [already]");
return -EBADMSG;
@@ -297,21 +308,44 @@ static int pgp_key_preparse(struct key_preparsed_payload 
*prep)
 
kenter("");
 
+   memset(, 0, sizeof(ctx));
ctx.pgp.types_of_interest =
-   (1 << PGP_PKT_PUBLIC_KEY) | (1 << PGP_PKT_PUBLIC_SUBKEY);
+   (1 << PGP_PKT_PUBLIC_KEY) | (1 << PGP_PKT_PUBLIC_SUBKEY) |
+   (1 << PGP_PKT_USER_ID);
ctx.pgp.process_packet = pgp_process_public_key;
-   ctx.subtype = NULL;
-   ctx.fingerprint = NULL;
-   ctx.payload = NULL;
 
ret = pgp_parse_packets(prep->data, prep->datalen, );
-   if (ret < 0) {
-   if (ctx.payload)
-   ctx.subtype->destroy(ctx.payload);
-   if (ctx.subtype)
-   module_put(ctx.subtype->owner);
-   kfree(ctx.fingerprint);
-   return ret;
+   if (ret < 0)
+   goto error;
+
+   if (ctx.user_id && ctx.user_id_len > 0) {
+   /* Propose a description for the key (user ID without the 
comment) */
+   size_t ulen = ctx.user_id_len, flen = ctx.fingerprint_len;
+   const char *p;
+
+   p = memchr(ctx.user_id, '(', ulen);
+   if (p) {
+   /* Remove the comment */
+   do {
+   p--;
+   } while (*p == ' ' && p > ctx.user_id);
+   if (*p != ' ')
+   p++;
+   ulen = p - ctx.user_id;
+   }
+
+   if (ulen > 255 - 9)
+   ulen = 255 - 9;
+   prep->description = kmalloc(ulen + 1 + 8 + 1, GFP_KERNEL);
+   ret = -ENOMEM;
+   if (!prep->description)
+   goto error;
+   memcpy(prep->description, ctx.user_id, ulen);
+   prep->description[ulen] = ' ';
+   memcpy(prep->description + ulen + 1,
+  ctx.fingerprint + flen - 8, 8);
+   prep->description[ulen + 9] = 0;
+   pr_debug("desc '%s'\n", prep->description);
}
 
prep->type_data[0] = ctx.subtype;
@@ -319,6 +353,14 @@ static int pgp_key_preparse(struct key_preparsed_payload 
*prep)
prep->payload = ctx.payload;
prep->quotalen = prep->datalen;
return 0;
+
+error:
+   if (ctx.payload)
+   ctx.subtype->destroy(ctx.payload);
+   if (ctx.subtype)
+   module_put(ctx.subtype->owner);
+   kfree(ctx.fingerprint);
+   return ret;
 }
 
 static struct crypto_key_parser pgp_key_parser = {

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 14/25] KEYS: PGP format signature parser

2012-08-15 Thread David Howells
Implement a signature parser that will attempt to parse a signature blob as a
PGP packet format message.  If it can, it will find an appropriate crypto key
and set the public-key algorithm according to the data in the signature.

Signed-off-by: David Howells 
---

 security/keys/crypto/Makefile |1 
 security/keys/crypto/pgp_sig_parser.c |  136 +
 2 files changed, 137 insertions(+)
 create mode 100644 security/keys/crypto/pgp_sig_parser.c


diff --git a/security/keys/crypto/Makefile b/security/keys/crypto/Makefile
index 0c8b8a1..a9a34c6 100644
--- a/security/keys/crypto/Makefile
+++ b/security/keys/crypto/Makefile
@@ -12,4 +12,5 @@ obj-$(CONFIG_PGP_LIBRARY) += pgp_library.o
 obj-$(CONFIG_CRYPTO_KEY_PGP_PARSER) += pgp_key_parser.o
 pgp_key_parser-y := \
pgp_public_key.o \
+   pgp_sig_parser.o \
pgp_sig_verify.o
diff --git a/security/keys/crypto/pgp_sig_parser.c 
b/security/keys/crypto/pgp_sig_parser.c
new file mode 100644
index 000..683eb53
--- /dev/null
+++ b/security/keys/crypto/pgp_sig_parser.c
@@ -0,0 +1,136 @@
+/* Handling for PGP public key signature data [RFC 4880]
+ *
+ * Copyright (C) 2011 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowe...@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#define pr_fmt(fmt) "PGPSIG: "fmt
+#include 
+#include 
+#include 
+#include 
+#include "public_key.h"
+#include "pgp_parser.h"
+
+struct PGP_sig_parse_context {
+   struct pgp_parse_context pgp;
+   struct pgp_sig_parameters params;
+   bool found_sig;
+};
+
+/*
+ * Look inside signature sections for a key ID
+ */
+static int pgp_process_signature(struct pgp_parse_context *context,
+enum pgp_packet_tag type,
+u8 headerlen,
+const u8 *data,
+size_t datalen)
+{
+   struct PGP_sig_parse_context *ctx =
+   container_of(context, struct PGP_sig_parse_context, pgp);
+
+   ctx->found_sig = true;
+   return pgp_parse_sig_params(, , >params);
+}
+
+/*
+ * Attempt to find a key to use for PGP signature verification, starting off by
+ * looking in the supplied keyring.
+ *
+ * The function may also look for other key sources such as a TPM.  If an
+ * alternative key is found it can be added to the keyring for future
+ * reference.
+ */
+static struct key *find_key_for_pgp_sig(struct key *keyring,
+   const u8 *sig, size_t siglen)
+{
+   struct PGP_sig_parse_context p;
+   key_ref_t key;
+   char criterion[3 + 8 * 2 + 1];
+   int ret;
+
+   if (!keyring)
+   return ERR_PTR(-ENOKEY);
+
+   /* Need to find the key ID */
+   p.pgp.types_of_interest = (1 << PGP_PKT_SIGNATURE);
+   p.pgp.process_packet = pgp_process_signature;
+   p.found_sig = false;
+   ret = pgp_parse_packets(sig, siglen, );
+   if (ret < 0)
+   return ERR_PTR(ret);
+
+   if (!p.found_sig)
+   return ERR_PTR(-ENOMSG);
+
+   sprintf(criterion, "id:%08x%08x",
+   be32_to_cpu(p.params.issuer32[0]),
+   be32_to_cpu(p.params.issuer32[1]));
+
+   pr_debug("Look up: %s\n", criterion);
+
+   key = keyring_search(make_key_ref(keyring, 1),
+_type_crypto, criterion);
+   if (IS_ERR(key)) {
+   switch (PTR_ERR(key)) {
+   /* Hide some search errors */
+   case -EACCES:
+   case -ENOTDIR:
+   case -EAGAIN:
+   return ERR_PTR(-ENOKEY);
+   default:
+   return ERR_CAST(key);
+   }
+   }
+
+   pr_debug("Found key %x\n", key_serial(key_ref_to_ptr(key)));
+   return key_ref_to_ptr(key);
+}
+
+/*
+ * Attempt to parse a signature as a PGP packet format blob and find a
+ * matching key.
+ */
+static struct crypto_sig_verify_context *pgp_verify_sig_begin(
+   struct key *keyring, const u8 *sig, size_t siglen)
+{
+   struct crypto_sig_verify_context *ctx;
+   struct key *key;
+
+   key = find_key_for_pgp_sig(keyring, sig, siglen);
+   if (IS_ERR(key))
+   return ERR_CAST(key);
+
+   /* We only handle in-kernel public key signatures for the moment */
+   ctx = pgp_pkey_verify_sig_begin(key, sig, siglen);
+   key_put(key);
+   return ctx;
+}
+
+static struct crypto_sig_parser pgp_sig_parser = {
+   .owner  = THIS_MODULE,
+   .name   = "pgp",
+   .verify_sig_begin = pgp_verify_sig_begin,
+};
+
+/*
+ * Module stuff
+ */
+static int __init pgp_sig_init(void)
+{
+   return 

[PATCH 13/25] KEYS: PGP-based public key signature verification

2012-08-15 Thread David Howells
Provide handlers for PGP-based public-key algorithm signature verification.
This does most of the work involved in signature verification as most of it is
public-key algorithm agnostic.  The public-key verification algorithm itself
is just the last little bit and is supplied the complete hash data to process.

This requires glue logic putting on top to make use of it - something the next
patch provides.

Signed-off-by: David Howells 
---

 security/keys/crypto/Makefile |3 
 security/keys/crypto/pgp_parser.h |6 +
 security/keys/crypto/pgp_sig_verify.c |  325 +
 3 files changed, 333 insertions(+), 1 deletion(-)
 create mode 100644 security/keys/crypto/pgp_sig_verify.c


diff --git a/security/keys/crypto/Makefile b/security/keys/crypto/Makefile
index 35733fc..0c8b8a1 100644
--- a/security/keys/crypto/Makefile
+++ b/security/keys/crypto/Makefile
@@ -11,4 +11,5 @@ obj-$(CONFIG_PGP_LIBRARY) += pgp_library.o
 
 obj-$(CONFIG_CRYPTO_KEY_PGP_PARSER) += pgp_key_parser.o
 pgp_key_parser-y := \
-   pgp_public_key.o
+   pgp_public_key.o \
+   pgp_sig_verify.o
diff --git a/security/keys/crypto/pgp_parser.h 
b/security/keys/crypto/pgp_parser.h
index 1cda231..6f5b3af 100644
--- a/security/keys/crypto/pgp_parser.h
+++ b/security/keys/crypto/pgp_parser.h
@@ -21,3 +21,9 @@
  */
 extern const
 struct public_key_algorithm *pgp_public_key_algorithms[PGP_PUBKEY__LAST];
+
+/*
+ * pgp_pubkey_sig.c
+ */
+extern struct crypto_sig_verify_context *pgp_pkey_verify_sig_begin(
+   struct key *crypto_key, const u8 *sigdata, size_t siglen);
diff --git a/security/keys/crypto/pgp_sig_verify.c 
b/security/keys/crypto/pgp_sig_verify.c
new file mode 100644
index 000..f9bb949
--- /dev/null
+++ b/security/keys/crypto/pgp_sig_verify.c
@@ -0,0 +1,325 @@
+/* PGP public key signature verification [RFC 4880]
+ *
+ * Copyright (C) 2011 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowe...@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#define pr_fmt(fmt) "PGPSIG: "fmt
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "public_key.h"
+#include "pgp_parser.h"
+
+static const struct {
+   enum pkey_hash_algo algo : 8;
+} pgp_pubkey_hash[PGP_HASH__LAST] = {
+   [PGP_HASH_MD5].algo = PKEY_HASH_MD5,
+   [PGP_HASH_SHA1].algo= PKEY_HASH_SHA1,
+   [PGP_HASH_RIPE_MD_160].algo = PKEY_HASH_RIPE_MD_160,
+   [PGP_HASH_SHA256].algo  = PKEY_HASH_SHA256,
+   [PGP_HASH_SHA384].algo  = PKEY_HASH_SHA384,
+   [PGP_HASH_SHA512].algo  = PKEY_HASH_SHA512,
+   [PGP_HASH_SHA224].algo  = PKEY_HASH_SHA224,
+};
+
+static int pgp_pkey_verify_sig_add_data(struct crypto_sig_verify_context *ctx,
+   const void *data, size_t datalen);
+static int pgp_pkey_verify_sig_end(struct crypto_sig_verify_context *ctx,
+  const u8 *sig, size_t siglen);
+static void pgp_pkey_verify_sig_cancel(struct crypto_sig_verify_context *ctx);
+
+struct pgp_pkey_sig_parse_context {
+   struct pgp_parse_context pgp;
+   struct pgp_sig_parameters params;
+};
+
+static int pgp_pkey_parse_signature(struct pgp_parse_context *context,
+   enum pgp_packet_tag type,
+   u8 headerlen,
+   const u8 *data,
+   size_t datalen)
+{
+   struct pgp_pkey_sig_parse_context *ctx =
+   container_of(context, struct pgp_pkey_sig_parse_context, pgp);
+
+   return pgp_parse_sig_params(, , >params);
+}
+
+/*
+ * Begin the process of verifying a DSA signature.
+ *
+ * This involves allocating the hash into which first the data and then the
+ * metadata will be put, and parsing the signature to check that it matches the
+ * key.
+ */
+struct crypto_sig_verify_context *pgp_pkey_verify_sig_begin(
+   struct key *crypto_key, const u8 *sigdata, size_t siglen)
+{
+   struct pgp_pkey_sig_parse_context p;
+   struct public_key_signature *sig;
+   struct crypto_shash *tfm;
+   const struct public_key *key = crypto_key->payload.data;
+   size_t digest_size, desc_size;
+   int ret;
+
+   kenter("{%d},,%zu", key_serial(crypto_key), siglen);
+
+   if (!key) {
+   kleave(" = -ENOKEY [no public key]");
+   return ERR_PTR(-ENOKEY);
+   }
+
+   p.pgp.types_of_interest = (1 << PGP_PKT_SIGNATURE);
+   p.pgp.process_packet = pgp_pkey_parse_signature;
+   ret = pgp_parse_packets(sigdata, siglen, );
+   if (ret < 0)
+   return ERR_PTR(ret);
+
+   if (p.params.pubkey_algo >= PGP_PUBKEY__LAST ||
+   

[PATCH 12/25] KEYS: PGP data parser

2012-08-15 Thread David Howells
Implement a PGP data parser for the crypto key type to use when instantiating a
key.

This parser attempts to parse the instantiation data as a PGP packet sequence
(RFC 4880) and if it parses okay, attempts to extract a public-key algorithm
key or subkey from it.

If it finds such a key, it will set up a public_key subtype payload with
appropriate handler routines (DSA or RSA) and attach it to the key.

Thanks to Tetsuo Handa  for pointing out
some errors.

Signed-off-by: David Howells 
---

 security/keys/crypto/Kconfig  |   12 +
 security/keys/crypto/Makefile |4 
 security/keys/crypto/pgp_parser.h |   23 ++
 security/keys/crypto/pgp_public_key.c |  344 +
 4 files changed, 383 insertions(+)
 create mode 100644 security/keys/crypto/pgp_parser.h
 create mode 100644 security/keys/crypto/pgp_public_key.c


diff --git a/security/keys/crypto/Kconfig b/security/keys/crypto/Kconfig
index 88ce0e2..1c2ae55 100644
--- a/security/keys/crypto/Kconfig
+++ b/security/keys/crypto/Kconfig
@@ -28,3 +28,15 @@ config PGP_LIBRARY
help
  This option enables a library that provides a number of simple
  utility functions for parsing PGP (RFC 4880) packet-based messages.
+
+config CRYPTO_KEY_PGP_PARSER
+   tristate "PGP key blob parser"
+   depends on CRYPTO_KEY_TYPE
+   select CRYPTO_KEY_PUBLIC_KEY_SUBTYPE
+   select PGP_LIBRARY
+   select MD5 # V3 fingerprint generation
+   select SHA1 # V4 fingerprint generation
+   help
+ This option provides support for parsing PGP (RFC 4880) format blobs
+ for key data and provides the ability to instantiate a crypto key
+ from a public key packet found inside the blob.
diff --git a/security/keys/crypto/Makefile b/security/keys/crypto/Makefile
index 5fbe54e..35733fc 100644
--- a/security/keys/crypto/Makefile
+++ b/security/keys/crypto/Makefile
@@ -8,3 +8,7 @@ crypto_keys-y := crypto_type.o crypto_verify.o
 obj-$(CONFIG_CRYPTO_KEY_PUBLIC_KEY_SUBTYPE) += public_key.o
 obj-$(CONFIG_CRYPTO_KEY_PKEY_ALGO_RSA) += crypto_rsa.o
 obj-$(CONFIG_PGP_LIBRARY) += pgp_library.o
+
+obj-$(CONFIG_CRYPTO_KEY_PGP_PARSER) += pgp_key_parser.o
+pgp_key_parser-y := \
+   pgp_public_key.o
diff --git a/security/keys/crypto/pgp_parser.h 
b/security/keys/crypto/pgp_parser.h
new file mode 100644
index 000..1cda231
--- /dev/null
+++ b/security/keys/crypto/pgp_parser.h
@@ -0,0 +1,23 @@
+/* PGP crypto data parser internal definitions
+ *
+ * Copyright (C) 2011 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowe...@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#include 
+
+#define kenter(FMT, ...) \
+   pr_devel("==> %s("FMT")\n", __func__, ##__VA_ARGS__)
+#define kleave(FMT, ...) \
+   pr_devel("<== %s()"FMT"\n", __func__, ##__VA_ARGS__)
+
+/*
+ * pgp_key_parser.c
+ */
+extern const
+struct public_key_algorithm *pgp_public_key_algorithms[PGP_PUBKEY__LAST];
diff --git a/security/keys/crypto/pgp_public_key.c 
b/security/keys/crypto/pgp_public_key.c
new file mode 100644
index 000..c260e02
--- /dev/null
+++ b/security/keys/crypto/pgp_public_key.c
@@ -0,0 +1,344 @@
+/* Instantiate a public key crypto key from PGP format data [RFC 4880]
+ *
+ * Copyright (C) 2011 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowe...@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#define pr_fmt(fmt) "PGP: "fmt
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "public_key.h"
+#include "pgp_parser.h"
+
+MODULE_LICENSE("GPL");
+
+const
+struct public_key_algorithm *pgp_public_key_algorithms[PGP_PUBKEY__LAST] = {
+#if defined(CONFIG_CRYPTO_KEY_PKEY_ALGO_RSA) || \
+   defined(CONFIG_CRYPTO_KEY_PKEY_ALGO_RSA_MODULE)
+   [PGP_PUBKEY_RSA_ENC_OR_SIG] = _public_key_algorithm,
+   [PGP_PUBKEY_RSA_ENC_ONLY]   = _public_key_algorithm,
+   [PGP_PUBKEY_RSA_SIG_ONLY]   = _public_key_algorithm,
+#endif
+   [PGP_PUBKEY_ELGAMAL]= NULL,
+   [PGP_PUBKEY_DSA]= NULL,
+};
+
+static const u8 pgp_public_key_capabilities[PGP_PUBKEY__LAST] = {
+   [PGP_PUBKEY_RSA_ENC_OR_SIG] = PKEY_CAN_ENCDEC | PKEY_CAN_SIGVER,
+   [PGP_PUBKEY_RSA_ENC_ONLY]   = PKEY_CAN_ENCDEC,
+   [PGP_PUBKEY_RSA_SIG_ONLY]   = PKEY_CAN_SIGVER,
+   [PGP_PUBKEY_ELGAMAL]= 0,
+   [PGP_PUBKEY_DSA]= 0,
+};
+
+static inline void digest_putc(struct shash_desc *digest, uint8_t ch)
+{
+   

[PATCH 11/25] PGPLIB: Signature parser

2012-08-15 Thread David Howells
Provide some PGP signature parsing helpers:

 (1) A function to parse V4 signature subpackets and pass the desired ones to
 a processor function:

int pgp_parse_sig_subpkts(const u8 *data, size_t datalen,
  struct pgp_parse_sig_context *ctx);

 (2) A function to parse out basic signature parameters from any PGP signature
 such that the algorithms and public key can be selected:

int pgp_parse_sig_params(const u8 **_data, size_t *_datalen,
 struct pgp_sig_parameters *p);

Signed-off-by: David Howells 
---

 include/linux/pgplib.h |   25 +++
 security/keys/crypto/pgp_library.c |  280 
 2 files changed, 305 insertions(+)


diff --git a/include/linux/pgplib.h b/include/linux/pgplib.h
index a045b3a..34594a9 100644
--- a/include/linux/pgplib.h
+++ b/include/linux/pgplib.h
@@ -41,6 +41,31 @@ struct pgp_parse_pubkey {
 extern int pgp_parse_public_key(const u8 **_data, size_t *_datalen,
struct pgp_parse_pubkey *pk);
 
+struct pgp_parse_sig_context {
+   unsigned long types_of_interest[128 / BITS_PER_LONG];
+   int (*process_packet)(struct pgp_parse_sig_context *context,
+ enum pgp_sig_subpkt_type type,
+ const u8 *data,
+ size_t datalen);
+};
+
+extern int pgp_parse_sig_packets(const u8 *data, size_t datalen,
+struct pgp_parse_sig_context *ctx);
+
+struct pgp_sig_parameters {
+   enum pgp_signature_version version : 8;
+   enum pgp_signature_type signature_type : 8;
+   enum pgp_pubkey_algo pubkey_algo : 8;
+   enum pgp_hash_algo hash_algo : 8;
+   union {
+   struct pgp_key_ID issuer;
+   __be32 issuer32[2];
+   };
+};
+
+extern int pgp_parse_sig_params(const u8 **_data, size_t *_datalen,
+   struct pgp_sig_parameters *p);
+
 
 #endif /* CONFIG_PGP_LIBRARY */
 
diff --git a/security/keys/crypto/pgp_library.c 
b/security/keys/crypto/pgp_library.c
index 39d2878..50b7fa0 100644
--- a/security/keys/crypto/pgp_library.c
+++ b/security/keys/crypto/pgp_library.c
@@ -266,3 +266,283 @@ int pgp_parse_public_key(const u8 **_data, size_t 
*_datalen,
return 0;
 }
 EXPORT_SYMBOL_GPL(pgp_parse_public_key);
+
+/**
+ * pgp_parse_sig_subpkt_header - Parse a PGP V4 signature subpacket header
+ * @_data: Start of the subpacket (updated to subpacket data)
+ * @_datalen: Amount of data remaining in buffer (decreased)
+ * @_type: Where the subpacket type will be returned
+ *
+ * Parse a PGP V4 signature subpacket header [RFC 4880: 5.2.3.1].
+ *
+ * Returns packet data size on success; non-zero on error.  If successful,
+ * *_data and *_datalen will have been updated and *_headerlen will be set to
+ * hold the length of the packet header.
+ */
+static ssize_t pgp_parse_sig_subpkt_header(const u8 **_data, size_t *_datalen,
+  enum pgp_sig_subpkt_type *_type)
+{
+   enum pgp_sig_subpkt_type type;
+   const u8 *data = *_data;
+   size_t size, datalen = *_datalen;
+
+   pr_devel("-->pgp_parse_sig_subpkt_header(,%zu,,)", datalen);
+
+   if (datalen < 2)
+   goto short_subpacket;
+
+   pr_devel("subpkt hdr %02x, %02x\n", data[0], data[1]);
+
+   switch (data[0]) {
+   case 0x00 ... 0xbf:
+   /* One-byte length */
+   size = data[0];
+   data++;
+   datalen--;
+   break;
+   case 0xc0 ... 0xfe:
+   /* Two-byte length */
+   if (datalen < 3)
+   goto short_subpacket;
+   size = (data[0] - 192) * 256;
+   size += data[1] + 192;
+   data += 2;
+   datalen -= 2;
+   break;
+   case 0xff:
+   if (datalen < 6)
+   goto short_subpacket;
+   size  = data[1] << 24;
+   size |= data[2] << 16;
+   size |= data[3] << 8;
+   size |= data[4];
+   data += 5;
+   datalen -= 5;
+   break;
+   }
+
+   /* The type octet is included in the size */
+   pr_devel("datalen=%zu size=%zu", datalen, size);
+   if (datalen < size)
+   goto short_subpacket;
+   if (size == 0)
+   goto very_short_subpacket;
+   if ((int)size < 0)
+   goto too_big;
+
+   type = *data++ & ~PGP_SIG_SUBPKT_TYPE_CRITICAL_MASK;
+   datalen--;
+   size--;
+
+   *_data = data;
+   *_datalen = datalen;
+   *_type = type;
+   pr_devel("Found subpkt type=%u size=%zd\n", type, size);
+   return size;
+
+very_short_subpacket:
+   pr_debug("Signature subpacket size can't be zero\n");
+   return -EBADMSG;
+short_subpacket:
+   pr_debug("Attempt to parse short signature 

[PATCH 10/25] PGPLIB: Basic packet parser

2012-08-15 Thread David Howells
Provide a simple parser that extracts the packets from a PGP packet blob and
passes the desirous ones to the given processor function:

struct pgp_parse_context {
u64 types_of_interest;
int (*process_packet)(struct pgp_parse_context *context,
  enum pgp_packet_tag type,
  u8 headerlen,
  const u8 *data,
  size_t datalen);
};

int pgp_parse_packets(const u8 *data, size_t datalen,
  struct pgp_parse_context *ctx);

This is configured on with CONFIG_PGP_LIBRARY.

Signed-off-by: David Howells 
---

 include/linux/pgplib.h |   47 ++
 security/keys/crypto/Kconfig   |6 +
 security/keys/crypto/Makefile  |1 
 security/keys/crypto/pgp_library.c |  268 
 4 files changed, 322 insertions(+)
 create mode 100644 include/linux/pgplib.h
 create mode 100644 security/keys/crypto/pgp_library.c


diff --git a/include/linux/pgplib.h b/include/linux/pgplib.h
new file mode 100644
index 000..a045b3a
--- /dev/null
+++ b/include/linux/pgplib.h
@@ -0,0 +1,47 @@
+/* PGP library definitions (RFC 4880)
+ *
+ * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowe...@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _LINUX_PGPLIB_H
+#define _LINUX_PGPLIB_H
+
+#if defined(CONFIG_PGP_LIBRARY) || defined(CONFIG_PGP_LIBRARY_MODULE)
+
+#include 
+
+/*
+ * PGP library packet parser
+ */
+struct pgp_parse_context {
+   u64 types_of_interest;
+   int (*process_packet)(struct pgp_parse_context *context,
+ enum pgp_packet_tag type,
+ u8 headerlen,
+ const u8 *data,
+ size_t datalen);
+};
+
+extern int pgp_parse_packets(const u8 *data, size_t datalen,
+struct pgp_parse_context *ctx);
+
+struct pgp_parse_pubkey {
+   enum pgp_key_version version : 8;
+   enum pgp_pubkey_algo pubkey_algo : 8;
+   time_t  creation_time;
+   time_t  expires_at;
+};
+
+extern int pgp_parse_public_key(const u8 **_data, size_t *_datalen,
+   struct pgp_parse_pubkey *pk);
+
+
+#endif /* CONFIG_PGP_LIBRARY */
+
+#endif /* _LINUX_PGPLIB_H */
diff --git a/security/keys/crypto/Kconfig b/security/keys/crypto/Kconfig
index 4e3777e..88ce0e2 100644
--- a/security/keys/crypto/Kconfig
+++ b/security/keys/crypto/Kconfig
@@ -22,3 +22,9 @@ config CRYPTO_KEY_PKEY_ALGO_RSA
select MPILIB_EXTRA
help
  This option enables support for the RSA algorithm (PKCS#1, RFC3447).
+
+config PGP_LIBRARY
+   tristate "PGP parsing library"
+   help
+ This option enables a library that provides a number of simple
+ utility functions for parsing PGP (RFC 4880) packet-based messages.
diff --git a/security/keys/crypto/Makefile b/security/keys/crypto/Makefile
index b6b1a5a..5fbe54e 100644
--- a/security/keys/crypto/Makefile
+++ b/security/keys/crypto/Makefile
@@ -7,3 +7,4 @@ crypto_keys-y := crypto_type.o crypto_verify.o
 
 obj-$(CONFIG_CRYPTO_KEY_PUBLIC_KEY_SUBTYPE) += public_key.o
 obj-$(CONFIG_CRYPTO_KEY_PKEY_ALGO_RSA) += crypto_rsa.o
+obj-$(CONFIG_PGP_LIBRARY) += pgp_library.o
diff --git a/security/keys/crypto/pgp_library.c 
b/security/keys/crypto/pgp_library.c
new file mode 100644
index 000..39d2878
--- /dev/null
+++ b/security/keys/crypto/pgp_library.c
@@ -0,0 +1,268 @@
+/* PGP packet parser (RFC 4880)
+ *
+ * Copyright (C) 2011 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowe...@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#define pr_fmt(fmt) "PGP: "fmt
+#include 
+#include 
+#include 
+#include 
+
+MODULE_LICENSE("GPL");
+
+const char *const pgp_hash_algorithms[PGP_HASH__LAST] = {
+   [PGP_HASH_MD5]  = "md5",
+   [PGP_HASH_SHA1] = "sha1",
+   [PGP_HASH_RIPE_MD_160]  = "rmd160",
+   [PGP_HASH_SHA256]   = "sha256",
+   [PGP_HASH_SHA384]   = "sha384",
+   [PGP_HASH_SHA512]   = "sha512",
+   [PGP_HASH_SHA224]   = "sha224",
+};
+EXPORT_SYMBOL_GPL(pgp_hash_algorithms);
+
+/**
+ * pgp_parse_packet_header - Parse a PGP packet header
+ * @_data: Start of the PGP packet (updated to PGP packet data)
+ * @_datalen: Amount of data 

Re: [PATCH RESEND] remove the queue unlock in scsi_requset_fn

2012-08-15 Thread Chanho Min
> functions will occur in line.  I also don't see why the sdev reference
> couldn't drop to zero here.
scsi_request_fn is called under the lock of request_queue->queue_lock.
If we drop the sdev reference to zero here,
scsi_device_dev_release_usercontext is
invoked and make request_queue to NULL. When caller of scsi_request_fn try to
unlock request_queue->queue_lock, the oops is occurred.

Thanks, Chanho
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 08/25] KEYS: RSA: Fix signature verification for shorter signatures

2012-08-15 Thread David Howells
gpg can produce a signature file where length of signature is less than the
modulus size because the amount of space an MPI takes up is kept as low as
possible by discarding leading zeros.  This regularly happens for several
modules during the build.

Fix it by relaxing check in RSA verification code.

Thanks to Tomas Mraz and Miloslav Trmac for help.

Signed-off-by: Milan Broz 
Signed-off-by: David Howells 
---

 security/keys/crypto/crypto_rsa.c |   14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)


diff --git a/security/keys/crypto/crypto_rsa.c 
b/security/keys/crypto/crypto_rsa.c
index 6e95e60..796ed1d 100644
--- a/security/keys/crypto/crypto_rsa.c
+++ b/security/keys/crypto/crypto_rsa.c
@@ -222,15 +222,23 @@ static int RSA_verify_signature(const struct public_key 
*key,
return -ENOTSUPP;
 
/* (1) Check the signature size against the public key modulus size */
-   k = (mpi_get_nbits(key->rsa.n) + 7) / 8;
+   k = mpi_get_nbits(key->rsa.n);
+   tsize = mpi_get_nbits(sig->rsa.s);
 
-   tsize = (mpi_get_nbits(sig->rsa.s) + 7) / 8;
+   /* According to RFC 4880 sec 3.2, length of MPI is computed starting
+* from most significant bit.  So the RFC 3447 sec 8.2.2 size check
+* must be relaxed to conform with shorter signatures - so we fail here
+* only if signature length is longer than modulus size.
+*/
pr_devel("step 1: k=%zu size(S)=%zu\n", k, tsize);
-   if (tsize != k) {
+   if (k < tsize) {
ret = -EBADMSG;
goto error;
}
 
+   /* Round up and convert to octets */
+   k = (k + 7) / 8;
+
/* (2b) Apply the RSAVP1 verification primitive to the public key */
ret = RSAVP1(key, sig->rsa.s, );
if (ret < 0)

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 07/25] KEYS: RSA: Implement signature verification algorithm [PKCS#1 / RFC3447]

2012-08-15 Thread David Howells
Implement RSA public key cryptography [PKCS#1 / RFC3447].  At this time, only
the signature verification algorithm is supported.  This uses the asymmetric
public key subtype to hold its key data.

Signed-off-by: David Howells 
---

 security/keys/crypto/Kconfig  |7 +
 security/keys/crypto/Makefile |1 
 security/keys/crypto/crypto_rsa.c |  267 +
 security/keys/crypto/public_key.h |2 
 4 files changed, 277 insertions(+)
 create mode 100644 security/keys/crypto/crypto_rsa.c


diff --git a/security/keys/crypto/Kconfig b/security/keys/crypto/Kconfig
index 5f2b8ac..4e3777e 100644
--- a/security/keys/crypto/Kconfig
+++ b/security/keys/crypto/Kconfig
@@ -15,3 +15,10 @@ config CRYPTO_KEY_PUBLIC_KEY_SUBTYPE
  If signature generation and/or verification are to be used,
  appropriate hash algorithms (such as SHA-1) must be available.
  ENOPKG will be reported if the requisite algorithm is unavailable.
+
+config CRYPTO_KEY_PKEY_ALGO_RSA
+   tristate "RSA public-key algorithm"
+   depends on CRYPTO_KEY_PUBLIC_KEY_SUBTYPE
+   select MPILIB_EXTRA
+   help
+ This option enables support for the RSA algorithm (PKCS#1, RFC3447).
diff --git a/security/keys/crypto/Makefile b/security/keys/crypto/Makefile
index 6384306..b6b1a5a 100644
--- a/security/keys/crypto/Makefile
+++ b/security/keys/crypto/Makefile
@@ -6,3 +6,4 @@ obj-$(CONFIG_CRYPTO_KEY_TYPE) += crypto_keys.o
 crypto_keys-y := crypto_type.o crypto_verify.o
 
 obj-$(CONFIG_CRYPTO_KEY_PUBLIC_KEY_SUBTYPE) += public_key.o
+obj-$(CONFIG_CRYPTO_KEY_PKEY_ALGO_RSA) += crypto_rsa.o
diff --git a/security/keys/crypto/crypto_rsa.c 
b/security/keys/crypto/crypto_rsa.c
new file mode 100644
index 000..6e95e60
--- /dev/null
+++ b/security/keys/crypto/crypto_rsa.c
@@ -0,0 +1,267 @@
+/* RSA asymmetric public-key algorithm [RFC3447]
+ *
+ * Copyright (C) 2011 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowe...@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#define pr_fmt(fmt) "RSA: "fmt
+#include 
+#include 
+#include "public_key.h"
+
+MODULE_LICENSE("GPL");
+
+#define kenter(FMT, ...) \
+   pr_devel("==> %s("FMT")\n", __func__, ##__VA_ARGS__)
+#define kleave(FMT, ...) \
+   pr_devel("<== %s()"FMT"\n", __func__, ##__VA_ARGS__)
+
+/*
+ * Hash algorithm OIDs plus ASN.1 DER wrappings [RFC4880 sec 5.2.2].
+ */
+static const u8 RSA_digest_info_MD5[] = {
+   0x30, 0x20, 0x30, 0x0C, 0x06, 0x08,
+   0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05, /* OID */
+   0x05, 0x00, 0x04, 0x10
+};
+
+static const u8 RSA_digest_info_SHA1[] = {
+   0x30, 0x21, 0x30, 0x09, 0x06, 0x05,
+   0x2B, 0x0E, 0x03, 0x02, 0x1A,
+   0x05, 0x00, 0x04, 0x14
+};
+
+static const u8 RSA_digest_info_RIPE_MD_160[] = {
+   0x30, 0x21, 0x30, 0x09, 0x06, 0x05,
+   0x2B, 0x24, 0x03, 0x02, 0x01,
+   0x05, 0x00, 0x04, 0x14
+};
+
+static const u8 RSA_digest_info_SHA224[] = {
+   0x30, 0x2d, 0x30, 0x0d, 0x06, 0x09,
+   0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04,
+   0x05, 0x00, 0x04, 0x1C
+};
+
+static const u8 RSA_digest_info_SHA256[] = {
+   0x30, 0x31, 0x30, 0x0d, 0x06, 0x09,
+   0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01,
+   0x05, 0x00, 0x04, 0x20
+};
+
+static const u8 RSA_digest_info_SHA384[] = {
+   0x30, 0x41, 0x30, 0x0d, 0x06, 0x09,
+   0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02,
+   0x05, 0x00, 0x04, 0x30
+};
+
+static const u8 RSA_digest_info_SHA512[] = {
+   0x30, 0x51, 0x30, 0x0d, 0x06, 0x09,
+   0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03,
+   0x05, 0x00, 0x04, 0x40
+};
+
+static const struct {
+   const u8 *data;
+   size_t size;
+} RSA_ASN1_templates[PKEY_HASH__LAST] = {
+#define _(X) { RSA_digest_info_##X, sizeof(RSA_digest_info_##X) }
+   [PKEY_HASH_MD5] = _(MD5),
+   [PKEY_HASH_SHA1]= _(SHA1),
+   [PKEY_HASH_RIPE_MD_160] = _(RIPE_MD_160),
+   [PKEY_HASH_SHA256]  = _(SHA256),
+   [PKEY_HASH_SHA384]  = _(SHA384),
+   [PKEY_HASH_SHA512]  = _(SHA512),
+   [PKEY_HASH_SHA224]  = _(SHA224),
+#undef _
+};
+
+/*
+ * RSAVP1() function [RFC3447 sec 5.2.2]
+ */
+static int RSAVP1(const struct public_key *key, MPI s, MPI *_m)
+{
+   MPI m;
+   int ret;
+
+   /* (1) Validate 0 <= s < n */
+   if (mpi_cmp_ui(s, 0) < 0) {
+   kleave(" = -EBADMSG [s < 0]");
+   return -EBADMSG;
+   }
+   if (mpi_cmp(s, key->rsa.n) >= 0) {
+   kleave(" = -EBADMSG [s >= n]");
+   return -EBADMSG;
+   }
+
+   m = mpi_alloc(0);
+   if (!m)
+   return -ENOMEM;
+
+   /* (2) m = s^e mod n */
+   ret = 

[PATCH 05/25] KEYS: Asymmetric public-key algorithm crypto key subtype

2012-08-15 Thread David Howells
Add a subtype for supporting asymmetric public-key encryption algorithms such
as DSA (FIPS-186) and RSA (PKCS#1 / RFC1337).

Signed-off-by: David Howells 
---

 security/keys/crypto/Kconfig  |   10 +++
 security/keys/crypto/Makefile |3 +
 security/keys/crypto/public_key.c |   82 +
 security/keys/crypto/public_key.h |  123 +
 4 files changed, 217 insertions(+), 1 deletion(-)
 create mode 100644 security/keys/crypto/public_key.c
 create mode 100644 security/keys/crypto/public_key.h


diff --git a/security/keys/crypto/Kconfig b/security/keys/crypto/Kconfig
index 3d15710..5f2b8ac 100644
--- a/security/keys/crypto/Kconfig
+++ b/security/keys/crypto/Kconfig
@@ -5,3 +5,13 @@ config CRYPTO_KEY_TYPE
  This option provides support for a type of key that holds the keys
  required for cryptographic operations such as encryption, decryption,
  signature generation and signature verification.
+
+config CRYPTO_KEY_PUBLIC_KEY_SUBTYPE
+   tristate "Asymmetric public-key crypto algorithm subtype"
+   depends on CRYPTO_KEY_TYPE
+   select MPILIB
+   help
+ This option provides support for asymmetric public key type handling.
+ If signature generation and/or verification are to be used,
+ appropriate hash algorithms (such as SHA-1) must be available.
+ ENOPKG will be reported if the requisite algorithm is unavailable.
diff --git a/security/keys/crypto/Makefile b/security/keys/crypto/Makefile
index 67001bc..6384306 100644
--- a/security/keys/crypto/Makefile
+++ b/security/keys/crypto/Makefile
@@ -3,5 +3,6 @@
 #
 
 obj-$(CONFIG_CRYPTO_KEY_TYPE) += crypto_keys.o
-
 crypto_keys-y := crypto_type.o crypto_verify.o
+
+obj-$(CONFIG_CRYPTO_KEY_PUBLIC_KEY_SUBTYPE) += public_key.o
diff --git a/security/keys/crypto/public_key.c 
b/security/keys/crypto/public_key.c
new file mode 100644
index 000..ebb31ec
--- /dev/null
+++ b/security/keys/crypto/public_key.c
@@ -0,0 +1,82 @@
+/* Asymmetric public key crypto subtype
+ *
+ * Copyright (C) 2011 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowe...@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#define pr_fmt(fmt) "PKEY: "fmt
+#include 
+#include 
+#include 
+#include "public_key.h"
+
+MODULE_LICENSE("GPL");
+
+const char *const pkey_algo[PKEY_ALGO__LAST] = {
+   [PKEY_ALGO_DSA] = "DSA",
+   [PKEY_ALGO_RSA] = "RSA",
+};
+EXPORT_SYMBOL_GPL(pkey_algo);
+
+const char *const pkey_hash_algo[PKEY_HASH__LAST] = {
+   [PKEY_HASH_MD4] = "md4",
+   [PKEY_HASH_MD5] = "md5",
+   [PKEY_HASH_SHA1]= "sha1",
+   [PKEY_HASH_RIPE_MD_160] = "rmd160",
+   [PKEY_HASH_SHA256]  = "sha256",
+   [PKEY_HASH_SHA384]  = "sha384",
+   [PKEY_HASH_SHA512]  = "sha512",
+   [PKEY_HASH_SHA224]  = "sha224",
+};
+EXPORT_SYMBOL_GPL(pkey_hash_algo);
+
+const char *const pkey_id_type[PKEY_ID_TYPE__LAST] = {
+   [PKEY_ID_PGP]   = "PGP",
+   [PKEY_ID_X509]  = "X509",
+};
+EXPORT_SYMBOL_GPL(pkey_id_type);
+
+/*
+ * Provide a part of a description of the key for /proc/keys.
+ */
+static void public_key_describe(const struct key *crypto_key,
+   struct seq_file *m)
+{
+   struct public_key *key = crypto_key->payload.data;
+
+   if (key)
+   seq_printf(m, "%s.%s",
+  pkey_id_type[key->id_type], key->algo->name);
+}
+
+/*
+ * Destroy a public key algorithm key
+ */
+void public_key_destroy(void *payload)
+{
+   struct public_key *key = payload;
+   int i;
+
+   if (key) {
+   for (i = 0; i < ARRAY_SIZE(key->mpi); i++)
+   mpi_free(key->mpi[i]);
+   kfree(key);
+   }
+}
+EXPORT_SYMBOL_GPL(public_key_destroy);
+
+/*
+ * Public key algorithm crypto key subtype
+ */
+struct crypto_key_subtype public_key_crypto_key_subtype = {
+   .owner  = THIS_MODULE,
+   .name   = "public_key",
+   .describe   = public_key_describe,
+   .destroy= public_key_destroy,
+};
+EXPORT_SYMBOL_GPL(public_key_crypto_key_subtype);
diff --git a/security/keys/crypto/public_key.h 
b/security/keys/crypto/public_key.h
new file mode 100644
index 000..228090d
--- /dev/null
+++ b/security/keys/crypto/public_key.h
@@ -0,0 +1,123 @@
+/* Asymmetric public-key algorithm definitions
+ *
+ * Copyright (C) 2011 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowe...@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 

[PATCH 04/25] KEYS: Add signature verification facility

2012-08-15 Thread David Howells
Add a facility whereby a key subtype may be asked to verify a signature against
the data it is purported to have signed.

This adds four routines:

 (1) struct crypto_key_verify_context *
 verify_sig_begin(struct key *keyring, const void *sig, size_t siglen);

 This sets up a verification context for the given signature using
 information in that signature to select a key from the specified keyring
 and to request a hash algorithm from the crypto layer.

 (2) int verify_sig_add_data(struct crypto_key_verify_context *ctx,
 const void *data, size_t datalen);

 Incrementally supply data to be signed.  May be called multiple times.

 (3) int verify_sig_end(struct crypto_key_verify_context *ctx,
const void *sig, size_t siglen);

 Complete the verification process and return the result.  -EKEYREJECTED
 will indicate that the verification failed and 0 will indicate success.
 Other errors are also possible.

 (4) void verify_sig_cancel(struct crypto_key_verify_context *ctx);

 Cancel the verification process.

Signed-off-by: David Howells 
---

 Documentation/security/keys-crypto.txt |  100 
 include/keys/crypto-subtype.h  |   36 +++
 include/keys/crypto-type.h |9 ++
 security/keys/crypto/Makefile  |2 
 security/keys/crypto/crypto_keys.h |1 
 security/keys/crypto/crypto_type.c |2 
 security/keys/crypto/crypto_verify.c   |  159 
 7 files changed, 304 insertions(+), 5 deletions(-)
 create mode 100644 security/keys/crypto/crypto_verify.c


diff --git a/Documentation/security/keys-crypto.txt 
b/Documentation/security/keys-crypto.txt
index 97dee80..0a886ec 100644
--- a/Documentation/security/keys-crypto.txt
+++ b/Documentation/security/keys-crypto.txt
@@ -7,6 +7,7 @@ Contents:
   - Overview.
   - Key identification.
   - Accessing crypto keys.
+- Signature verification.
   - Implementing crypto parsers.
   - Implementing crypto subtypes.
 
@@ -89,6 +90,65 @@ This gives access to the key type:
struct key_type key_type_crypto;
 
 
+SIGNATURE VERIFICATION
+--
+
+The four operations that can perform cryptographic signature verification,
+using one of a set of keys to provide the public key:
+
+ (1) Begin verification procedure.
+
+   struct crypto_key_verify_context *
+   verify_sig_begin(struct key *keyring, const void *sig, size_t siglen);
+
+ This function sets up a verification context from the information in the
+ signature and looks for a suitable key in the keyring.  The signature blob
+ must be presented again at the end of the procedure.  The keys will be
+ checked against parameters in the signature, and if the matching one is
+ not found then -ENOKEY will be returned.
+
+ The hashing algorithm, if such a thing applies, will be determined from
+ information in the signature and the appropriate crypto module will be
+ used.  -ENOPKG will be returned if the hash algorithm is unavailable.
+
+ The return value is an opaque pointer to be passed to the other functions,
+ or a negative error code.
+
+ (2) Indicate data to be verified.
+
+   int verify_sig_add_data(struct crypto_key_verify_context *ctx,
+   const void *data, size_t datalen);
+
+ This function is used to shovel data to the verification procedure so that
+ it can load it into the hash, pass it to hardware or whatever is
+ appropriate for the algorithm being employed.
+
+ The data is not canonicalised for the document type specified in the
+ signature.  The caller must do that.
+
+ It will return 0 if successful and a negative error code if not.
+
+ (3) Complete the verification process.
+
+   int verify_sig_end(struct crypto_key_verify_context *ctx,
+  const void *sig, size_t siglen);
+
+ This function performs the actual signature verification step and cleans
+ up the resources allocated at the beginning.  The signature must be
+ presented again as some of the data therein may need to be added to the
+ internal hash.
+
+ It will return -EKEYREJECTED if the signature didn't match, 0 if
+ successful and may return other errors as appropriate.
+
+ (4) Cancel the verification process.
+
+   void verify_sig_cancel(struct crypto_key_verify_context *ctx);
+
+ This function cleans up the resources allocated at the beginning.  This is
+ not necessary if verify_sig_end() was called.
+
+
 ===
 IMPLEMENTING CRYPTO PARSERS
 ===
@@ -107,6 +167,8 @@ The parser definition structure looks like the following:
 
int (*instantiate)(struct key *key,
   const void *data, size_t datalen);
+   struct crypto_key_verify_context *(*verify_sig_begin)(
+   struct key 

[PATCH 03/25] KEYS: Create a key type that can be used for general cryptographic operations

2012-08-15 Thread David Howells
Create a key type that can be used for general cryptographic operations, such
as encryption, decryption, signature generation and signature verification.

The key type is "crypto" and can provide access to a variety of cryptographic
algorithms.

Signed-off-by: David Howells 
---

 Documentation/security/keys-crypto.txt |  181 +
 include/keys/crypto-subtype.h  |   57 +++
 include/keys/crypto-type.h |   25 +++
 security/keys/Kconfig  |2 
 security/keys/Makefile |1 
 security/keys/crypto/Kconfig   |7 +
 security/keys/crypto/Makefile  |7 +
 security/keys/crypto/crypto_keys.h |   28 +++
 security/keys/crypto/crypto_type.c |  272 
 9 files changed, 580 insertions(+)
 create mode 100644 Documentation/security/keys-crypto.txt
 create mode 100644 include/keys/crypto-subtype.h
 create mode 100644 include/keys/crypto-type.h
 create mode 100644 security/keys/crypto/Kconfig
 create mode 100644 security/keys/crypto/Makefile
 create mode 100644 security/keys/crypto/crypto_keys.h
 create mode 100644 security/keys/crypto/crypto_type.c


diff --git a/Documentation/security/keys-crypto.txt 
b/Documentation/security/keys-crypto.txt
new file mode 100644
index 000..97dee80
--- /dev/null
+++ b/Documentation/security/keys-crypto.txt
@@ -0,0 +1,181 @@
+   ==
+   CRYPTOGRAPHIC KEY TYPE
+   ==
+
+Contents:
+
+  - Overview.
+  - Key identification.
+  - Accessing crypto keys.
+  - Implementing crypto parsers.
+  - Implementing crypto subtypes.
+
+
+
+OVERVIEW
+
+
+The "crypto" key type is designed to be a container for cryptographic keys,
+without imposing any particular restrictions on the form of the cryptography or
+the key.
+
+The crypto key is given a subtype that defines what sort of data is associated
+with the key and provides operations to describe and destroy it.  However, no
+requirement is made that the key data actually be loaded into the key.
+
+The crypto key also has a number of data parsers registered with it.  The data
+parsers are responsible for extracing information the blobs of data passed to
+the instantiator function.  The first data parser that recognises the blob gets
+to set the subtype of the key and define the operations that can be done on
+that key.
+
+Completely in-kernel key retention and operation subtypes and parsers can be
+defined, but it would also be possible to provide access to cryptographic
+hardware (such as a TPM) that might be used to both retain the relevant key and
+perform operations using that key.  In such a case, the crypto key would then
+merely be an interface to the TPM driver.
+
+
+==
+KEY IDENTIFICATION
+==
+
+Because the identity of a key is not necessarily known and may not be easily
+calculated when a crypto key is allocated, it may not be a simple matter to set
+a key description to something that's useful for determining whether this is
+the key you're looking for.  Furthermore, it may be necessary to perform a
+partial match upon the key identity.
+
+To help with this, when a key is loaded, the parser calculates the key
+fingerprint and stores a copy in the key structure.
+
+The crypto key type's key matching function then performs more checks than just
+the straightforward comparison of the description with the criterion string:
+
+ (1) If the criterion string is of the form "id:" then the match
+ function will examine a key's fingerprint to see if the hex digits given
+ after the "id:" match the tail.  For instance:
+
+   keyctl search @s crypto id:5acc2142
+
+ will match a key with fingerprint:
+
+   1A00 2040 7601 7889 DE11  882C 3823 04AD 5ACC 2142
+
+ (2) If the criterion string is of the form ":" then the
+ match will match the ID as in (1), but with the added restriction that
+ only keys of the specified subtype (e.g. dsa or rsa) will be matched.  For
+ instance:
+
+   keyctl search @s crypto dsa:5acc2142
+
+Looking in /proc/keys, the last 8 hex digits of the key fingerprint are
+displayed, along with the subtype:
+
+   1a39e171 I- 1 perm 3f01 0 0 cryptomodsign.0: 
DSA 5acc2142 []
+
+
+=
+ACCESSING CRYPTO KEYS
+=
+
+To access crypto keys from within the kernel, the following inclusion is
+required:
+
+   #include 
+
+This gives access to the key type:
+
+   struct key_type key_type_crypto;
+
+
+===
+IMPLEMENTING CRYPTO PARSERS
+===
+
+The crypto key type keeps a list of registered data parsers.  An example of
+such a parser is one that parses OpenPGP packet formatted data [RFC 4880].
+
+During key instantiation each parser in the list is tried until one doesn't
+return -EBADMSG.
+
+The parser 

[PATCH 00/25] Crypto keys and module signing

2012-08-15 Thread David Howells

Hi Rusty,

I've posted new versions of my module signing patches to my GIT trees.

The patches with (approximately) your preferred way of attaching the signature
can be found here and I've followed this message with them:


http://git.kernel.org/?p=linux/kernel/git/dhowells/linux-modsign.git;a=shortlog;h=refs/heads/modsign-rusty

And using an ELF note can be found here:


http://git.kernel.org/?p=linux/kernel/git/dhowells/linux-modsign.git;a=shortlog;h=refs/heads/modsign

A slightly older version of the latter patches are being used in Fedora 18 and
Rawhide kernels.  I'm still doing some development on them to get X.509 and
PKCS#7 working with module signing for UEFI purposes.

If you look here, you can find most of an X.509 key parser:


http://git.kernel.org/?p=linux/kernel/git/dhowells/linux-modsign.git;a=shortlog;h=refs/heads/devel-x509

I'm also working on a PKCS#7 signature parser and have a chunk of it working,
though it's not ready for release yet.  At the moment, I can add X.509
certificates as public keys like so:

keyctl padd crypto "" @s http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [discussion]sched: a rough proposal to enable power saving in scheduler

2012-08-15 Thread Arjan van de Ven
On 8/15/2012 6:14 PM, Rik van Riel wrote:
> 
> The idea Matthew and I have is simply planning for a shorter
> sleep period (discarding the outliers to the high end in the
> function once known as detect_repeating_patterns), and going
> to a deeper C state if we have significantly overslept.
> 
> The new estimation code is easy, but for the past days I have
> been looking through the timer code to figure out how such a
> timer could fire, and how we could recognize it without it
> looking like a normal wakeup, if we do not end up accidentally
> waking up another CPU, etc...

this sort of code we recently developed already in house;
i'm surprised it hasn't been pasted to lkml yet


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [discussion]sched: a rough proposal to enable power saving in scheduler

2012-08-15 Thread Arjan van de Ven
On 8/15/2012 6:14 PM, Rik van Riel wrote:
> On 08/15/2012 10:43 AM, Arjan van de Ven wrote:
> 
>> The easy cop-out is provide the sysadmin a slider.
>> The slightly less easy one is to (and we're taking this approach
>> in the new P state code we're working on) say "in the default
>> setting, we're going to sacrifice up to 5% performance from peak
>> to give you the best power savings within that performance loss budget"
>> (with a slider that can give you 0%, 2 1/2%  5% and 10%)
> 
> On a related note, I am looking at the c-state menu governor.
> 
> We seem to have issues there, with Linux often going into a much
> deeper C state than warranted, which can lead to a fairly steep
> performance penalty for some workloads.
> 

predicting the future is hard.
if you pick a too deep C state, you get a certain fixed performance hit
if you pick a too shallow C state, you get a pretty large power hit (depending 
on how long you actually stay idle)

also would need to know hw details; at least on Intel a bunch of things are done
by the firmware and some platforms we're not doing the right things as Linux
(or BIOS)

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [discussion]sched: a rough proposal to enable power saving in scheduler

2012-08-15 Thread Rik van Riel

On 08/15/2012 10:43 AM, Arjan van de Ven wrote:


The easy cop-out is provide the sysadmin a slider.
The slightly less easy one is to (and we're taking this approach
in the new P state code we're working on) say "in the default
setting, we're going to sacrifice up to 5% performance from peak
to give you the best power savings within that performance loss budget"
(with a slider that can give you 0%, 2 1/2%  5% and 10%)


On a related note, I am looking at the c-state menu governor.

We seem to have issues there, with Linux often going into a much
deeper C state than warranted, which can lead to a fairly steep
performance penalty for some workloads.

One of the issues we identified is that detect_repeating_patterns
would deal quite poorly with patterns that have a short pause,
followed by a long pause, followed by another short pause. For
example, pinging a virtual machine :)

The idea Matthew and I have is simply planning for a shorter
sleep period (discarding the outliers to the high end in the
function once known as detect_repeating_patterns), and going
to a deeper C state if we have significantly overslept.

The new estimation code is easy, but for the past days I have
been looking through the timer code to figure out how such a
timer could fire, and how we could recognize it without it
looking like a normal wakeup, if we do not end up accidentally
waking up another CPU, etc...

I guess I should probably post what I have and kick off a
debate between people who know that code much better than I do :)

--
All rights reversed
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: O_DIRECT to md raid 6 is slow

2012-08-15 Thread Andy Lutomirski
On Wed, Aug 15, 2012 at 4:50 PM, Stan Hoeppner  wrote:
> On 8/15/2012 5:10 PM, Andy Lutomirski wrote:
>> On Wed, Aug 15, 2012 at 3:00 PM, Stan Hoeppner  
>> wrote:
>>> On 8/15/2012 12:57 PM, Andy Lutomirski wrote:
 On Wed, Aug 15, 2012 at 4:50 AM, John Robinson
  wrote:
> On 15/08/2012 01:49, Andy Lutomirski wrote:
>>
>> If I do:
>> # dd if=/dev/zero of=/dev/md0p1 bs=8M
>
> [...]
>>
>> Grr.  I thought the bad old days of filesystem and related defaults
>> sucking were over.
>
> The previous md chunk default of 64KB wasn't horribly bad, though still
> maybe a bit high for alot of common workloads.  I didn't have eyes/ears
> on the discussion and/or testing process that led to the 'new' 512KB
> default.  Obviously something went horribly wrong here.  512KB isn't a
> show stopper as a default for 0/1/10, but is 8-16 times too large for
> parity RAID.
>
>> cryptsetup aligns sanely these days, xfs is
>> sensible, etc.
>
> XFS won't align with the 512KB chunk default of metadata 1.2.  The
> largest XFS journal stripe unit (su--chunk) is 256KB, and even that
> isn't recommended.  Thus mkfs.xfs throws an error due to the 512KB
> stripe.  See the md and xfs archives for more details, specifically Dave
> Chinner's colorful comments on the md 512KB default.

Heh -- that's why the math didn't make any sense :)

>
>> wtf?  Why is there no sensible filesystem for
>> huge disks?  zfs can't cp --reflink and has all kinds of source
>> availability and licensing issues, xfs can't dedupe at all, and btrfs
>> isn't nearly stable enough.
>
> Deduplication isn't a responsibility of a filesystem.  TTBOMK there are
> two, and only two, COW filesystems in existence:  ZFS and BTRFS.  And
> these are the only two to offer a native dedupe capability.  They did it
> because they could, with COW, not necessarily because they *should*.
> There are dozens of other single node, cluster, and distributed
> filesystems in use today and none of them support COW, and thus none
> support dedup.  So to *expect* a 'sensible' filesystem to include dedupe
> is wishful thinking at best.

I should clarify my rant for the record.  I don't care about in-fs
dedupe.  I want COW so userspace can dedupe and generally replace
hardlinks with sensible cowlinks.  I'm also working on some fun tools
that *require* reflinks for anything resembling decent performance.

--Andy
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [PATCH] x86_dump_trace: avoiding endless " " is printed

2012-08-15 Thread Liu, Chuansheng

> The endless "  " is as below:
> ...
> [   82.215244,0]  
> [   82.215399,0]  
> [   82.215554,0]  
> [   82.215710,0]  
> [   82.215865,0]  
> [   82.216022,0]  
> [   82.216178,0]  
> [   82.216333,0]  
> [   82.216488,0]  
> [   82.216643,0]  
> [   82.216798,0]  
> [   82.216953,0]  
> ...
> 
Anyone can give some help for the above logs? It is the real case we meet on 
our x86_32 platform.
I checked the code, the tons of "  " should be printed from the below code 
in dumpstack_32.c:
[if (ops->stack(data, "IRQ") < 0)] will print "  ", as for the endless 
printing, it should be for(;;) is not
broken, so I guess in this case context->previous_esp == context.

But from code review, previous_esp is just set at hardirq. No possible this 
case happening.
Who can give help? Thanks.

void dump_trace(struct task_struct *task, struct pt_regs *regs,
unsigned long *stack, unsigned long bp,
const struct stacktrace_ops *ops, void *data)
{
for (;;) {
struct thread_info *context;

context = (struct thread_info *)
((unsigned long)stack & (~(THREAD_SIZE - 1)));
bp = ops->walk_stack(context, stack, bp, ops, data, NULL, 
);

stack = (unsigned long *)context->previous_esp;
if (!stack)
break;
if (ops->stack(data, "IRQ") < 0) == > Here printing the "  
"
break;
touch_nmi_watchdog();
}
}

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [NEW DRIVER V3 7/8] DA9058 HWMON driver

2012-08-15 Thread Guenter Roeck
On Wed, Aug 15, 2012 at 04:05:24PM +0100, Anthony Olech wrote:
> This is the HWMON component driver of the Dialog DA9058 PMIC.
> This driver is just one component of the whole DA9058 PMIC driver.
> It depends on the CORE and ADC component drivers of the DA9058 MFD.
> 
If so, please state as dependencies in Kconfig. Also see below. 

> Signed-off-by: Anthony Olech 
> Signed-off-by: David Dajun Chen 
> ---
>  Documentation/hwmon/da9058   |   30 +++
>  drivers/hwmon/Kconfig|   10 +
>  drivers/hwmon/Makefile   |1 +
>  drivers/hwmon/da9058-hwmon.c |  425 
> ++
>  4 files changed, 466 insertions(+), 0 deletions(-)
>  create mode 100644 Documentation/hwmon/da9058
>  create mode 100644 drivers/hwmon/da9058-hwmon.c
> 
The patch neither applies on top of 3.6-rc1 nor my -next tree. What is
its parent ?

> diff --git a/Documentation/hwmon/da9058 b/Documentation/hwmon/da9058
> new file mode 100644
> index 000..60634c5
> --- /dev/null
> +++ b/Documentation/hwmon/da9058
> @@ -0,0 +1,30 @@
> +Kernel driver da9058-hwmon
> +==
> +
> +Supported chips:
> +  * Dialog Semiconductor DA9058 PMIC
> +Prefix: 'da9058'
> +Datasheet:
> + http://www.dialog-semiconductor.com/products/power-management/da9058
> +
> +Authors: Opensource [Anthony Olech] 
> +
> +Description
> +---
> +
> +The DA9058 PMIC contains a 5 channel ADC which can be used to monitor a
> +range of system operating parameters, including the battery voltage and
> +temperature.  The ADC measures voltage, but two of the ADC channels can
> +be configured to supply a current, so that if an NTC termister is connected
> +then the voltage reading can be converted to a temperature. Currently the
> +driver provides reporting of all the input values but does not provide any
> +alarms.
> +
> +Voltage Monitoring
> +--
> +
> +Voltages are sampled in either 'automatic' or 'manual' mode, which is an
> +initialization parameter set in the platform data by the machine driver.
> +In manual mode the ADC conversion is 12 bit and in automatic mode it is
> +10 bit. However all the raw readings are reported as 12 bit numbers.
> +

This results in a whitespace error (no blank line at EOF).

> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
> index 6f1d167..0986f43 100644
> --- a/drivers/hwmon/Kconfig
> +++ b/drivers/hwmon/Kconfig
> @@ -294,6 +294,16 @@ config SENSORS_ATXP1
> This driver can also be built as a module.  If so, the module
> will be called atxp1.
>  
> +config SENSORS_DA9058
> + tristate "Dialog Semiconductor DA9058 ADC"
> + depends on I2C

Presumably also depends on the MFD driver and possibly EXPERIMENTAL. The one
thing it does not depend on, at least not directly, is I2C, since it does not
perform any I2C function calls.

> + help
> +   If you say yes here you get support for ADC on the Dialog
> +   Semiconductor DA9058 PMIC.
> +
> +   This driver can also be built as a module.  If so, the module
> +   will be called da9058-hwmon.
> +
>  config SENSORS_DS620
>   tristate "Dallas Semiconductor DS620"
>   depends on I2C
> diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
> index e1eeac1..be99572 100644
> --- a/drivers/hwmon/Makefile
> +++ b/drivers/hwmon/Makefile
> @@ -43,6 +43,7 @@ obj-$(CONFIG_SENSORS_ASC7621)   += asc7621.o
>  obj-$(CONFIG_SENSORS_ATXP1)  += atxp1.o
>  obj-$(CONFIG_SENSORS_CORETEMP)   += coretemp.o
>  obj-$(CONFIG_SENSORS_DME1737)+= dme1737.o
> +obj-$(CONFIG_SENSORS_DA9058) += da9058-hwmon.o

In alphabetical order, please

>  obj-$(CONFIG_SENSORS_DS620)  += ds620.o
>  obj-$(CONFIG_SENSORS_DS1621) += ds1621.o
>  obj-$(CONFIG_SENSORS_EMC1403)+= emc1403.o
> diff --git a/drivers/hwmon/da9058-hwmon.c b/drivers/hwmon/da9058-hwmon.c
> new file mode 100644
> index 000..8953170
> --- /dev/null
> +++ b/drivers/hwmon/da9058-hwmon.c
> @@ -0,0 +1,425 @@
> +/*
> + *  Copyright (C) 2012 Dialog Semiconductor Ltd.
> + *
> + *  This program is free software; you can redistribute it and/or modify
> + *  it under the terms of the GNU General Public License as published by
> + *  the Free Software Foundation; either version 2 of the License, or
> + *  (at your option) any later version.
> + *
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +static ssize_t da9058_vbat_show_txt(struct device *dev,
> + struct device_attribute *devattr, char *buf)

Please align second lines of function declarations and function calls with the
opening (.

You don't need separate functions for all the label show functions. One function
plus index is good enough. Look into the da902 driver for an example. 

_label instead of _txt might be a better function name.

> +{
> + return sprintf(buf, "vbat\n");
> +}
> +
> +static ssize_t 

Re: [PATCH V5 13/18] drm: Define SAREA_MAX for Loongson (PageSize = 16KB).

2012-08-15 Thread Huacai Chen
On Thu, Aug 16, 2012 at 5:31 AM, Ralf Baechle  wrote:
> On Sat, Aug 11, 2012 at 05:32:18PM +0800, Huacai Chen wrote:
>
>> Subject: [PATCH V5 13/18] drm: Define SAREA_MAX for Loongson (PageSize = 
>> 16KB).
>
> But your code doesn't define it just for Loongsson as the log message claims
> but rather for all MIPS.
>
>> diff --git a/include/drm/drm_sarea.h b/include/drm/drm_sarea.h
>> index ee5389d..1d1a858 100644
>> --- a/include/drm/drm_sarea.h
>> +++ b/include/drm/drm_sarea.h
>> @@ -37,6 +37,8 @@
>>  /* SAREA area needs to be at least a page */
>>  #if defined(__alpha__)
>>  #define SAREA_MAX   0x2000U
>> +#elif defined(__mips__)
>> +#define SAREA_MAX   0x4000U
>
> How about replacing this whole #ifdef mess with something like:
>
> #include 
> #include 
>
> /* Intel 830M driver needs at least 8k SAREA */
> #define SAREA_MAX   max(PAGE_SIZE, 0x2000U)
>
> MIPS also uses 64K page size and your patch as posted would break with 64k
> pages.
Yes, I think this is better. Thank you.
>
>   Ralf
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [PATCH v2] iio: adc: add new lp8788 adc driver

2012-08-15 Thread Kim, Milo
> > +   switch (mask) {
> > +   case IIO_CHAN_INFO_RAW:
> > +   *val = result;
> > +   return IIO_VAL_INT;
> > +   case IIO_CHAN_INFO_SCALE:
> > +   *val = adc_const[id] * ((result * 1000 + 500) / 1000);
> 
> This looks wrong. The IIO_CHAN_INFO_SCALE attribute is the factor by
> which
> IIO_CHAN_INFO_RAW needs to be multiplied to get the value in the proper
> unit,
> which is specified in the IIO ABI spec. E.g. milli volts for voltages.
> 
> What you return here seems to be the IIO_CHAN_INFO_PROCESSED attribute.
> Which
> basically is raw * scale.

Thanks a lot for your review.

Any way to get the result with offset value in the iio-consumer side?
What I need is as below.

  result = raw * scale + offset

At this moment, there are two apis() for reading the iio channel
- iio_read_channel_raw() and iio_read_channel_scale().

Does it sound good if I add iio_read_channel_offset() consumer api
using IIO_CHAN_INFO_OFFSET?

Best Regards,
Milo

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 7/7] staging: comedi: contec_pci_dio: cleanup contec_do_insn_bits

2012-08-15 Thread H Hartley Sweeten
Create local variables for the mask and bits values passed in
the data pointer to make this function a bit clearer.

Return the state of the output bits (s->state) in data[1] since
this is what comedilib is expecting.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-hartman 
---
 drivers/staging/comedi/drivers/contec_pci_dio.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/comedi/drivers/contec_pci_dio.c 
b/drivers/staging/comedi/drivers/contec_pci_dio.c
index b7b60d3..12ad9fa3 100644
--- a/drivers/staging/comedi/drivers/contec_pci_dio.c
+++ b/drivers/staging/comedi/drivers/contec_pci_dio.c
@@ -44,12 +44,18 @@ static int contec_do_insn_bits(struct comedi_device *dev,
   struct comedi_subdevice *s,
   struct comedi_insn *insn, unsigned int *data)
 {
-   if (data[0]) {
-   s->state &= ~data[0];
-   s->state |= data[0] & data[1];
+   unsigned int mask = data[0];
+   unsigned int bits = data[1];
+
+   if (mask) {
+   s->state &= ~mask;
+   s->state |= (bits & mask);
 
outw(s->state, dev->iobase + PIO1616L_DO_REG);
}
+
+   data[1] = s->state;
+
return insn->n;
 }
 
-- 
1.7.11

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 6/7] staging: comedi: contec_pci_dio: use attach_pci callback

2012-08-15 Thread H Hartley Sweeten
Convert this PCI driver to use the comedi PCI auto config attach
mechanism by adding an attach_pci callback function. Since the
driver does not require any external configuration options, disable
the legacy attach by making the attach simply return -ENOSYS. This
removes the need to walk to pci bus to find the pci_dev and the
need for the pci_dev_put in the detach.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-hartman 
---
 drivers/staging/comedi/drivers/contec_pci_dio.c | 97 +
 1 file changed, 35 insertions(+), 62 deletions(-)

diff --git a/drivers/staging/comedi/drivers/contec_pci_dio.c 
b/drivers/staging/comedi/drivers/contec_pci_dio.c
index 4b47fa0..b7b60d3 100644
--- a/drivers/staging/comedi/drivers/contec_pci_dio.c
+++ b/drivers/staging/comedi/drivers/contec_pci_dio.c
@@ -27,11 +27,7 @@ Author: Stefano Rivoir 
 Updated: Wed, 27 Jun 2007 13:00:06 +0100
 Status: works
 
-Configuration Options:
-  [0] - PCI bus of device (optional)
-  [1] - PCI slot of device (optional)
-  If bus/slot is not specified, the first supported
-  PCI device found will be used.
+Configuration Options: not applicable, uses comedi PCI auto config
 */
 
 #include "../comedidev.h"
@@ -66,76 +62,53 @@ static int contec_di_insn_bits(struct comedi_device *dev,
return insn->n;
 }
 
-static struct pci_dev *contec_find_pci_dev(struct comedi_device *dev,
-  struct comedi_devconfig *it)
+static int contec_attach_pci(struct comedi_device *dev,
+struct pci_dev *pcidev)
 {
-   struct pci_dev *pcidev = NULL;
-   int bus = it->options[0];
-   int slot = it->options[1];
-
-   for_each_pci_dev(pcidev) {
-   if (bus || slot) {
-   if (bus != pcidev->bus->number ||
-   slot != PCI_SLOT(pcidev->devfn))
-   continue;
-   }
-   if (pcidev->vendor != PCI_VENDOR_ID_CONTEC ||
-   pcidev->device != PCI_DEVICE_ID_PIO1616L)
-   continue;
-
-   return pcidev;
-   }
-   dev_err(dev->class_dev,
-   "No supported board found! (req. bus %d, slot %d)\n",
-   bus, slot);
-   return NULL;
-}
-
-static int contec_attach(struct comedi_device *dev, struct comedi_devconfig 
*it)
-{
-   struct pci_dev *pcidev;
struct comedi_subdevice *s;
int ret;
 
-   printk("comedi%d: contec: ", dev->minor);
-
-   ret = comedi_alloc_subdevices(dev, 2);
-   if (ret)
-   return ret;
-
-   pcidev = contec_find_pci_dev(dev, it);
-   if (!pcidev)
-   return -EIO;
comedi_set_hw_dev(dev, >dev);
+
dev->board_name = dev->driver->driver_name;
 
-   if (comedi_pci_enable(pcidev, "contec_pci_dio")) {
-   printk("error enabling PCI device and request regions!\n");
-   return -EIO;
-   }
+   ret = comedi_pci_enable(pcidev, dev->board_name);
+   if (ret)
+   return ret;
dev->iobase = pci_resource_start(pcidev, 0);
-   printk(" base addr %lx ", dev->iobase);
 
-   s = dev->subdevices + 0;
+   ret = comedi_alloc_subdevices(dev, 2);
+   if (ret)
+   return ret;
 
-   s->type = COMEDI_SUBD_DI;
-   s->subdev_flags = SDF_READABLE;
-   s->n_chan = 16;
-   s->maxdata = 1;
-   s->range_table = _digital;
-   s->insn_bits = contec_di_insn_bits;
+   s = dev->subdevices + 0;
+   s->type = COMEDI_SUBD_DI;
+   s->subdev_flags = SDF_READABLE;
+   s->n_chan   = 16;
+   s->maxdata  = 1;
+   s->range_table  = _digital;
+   s->insn_bits= contec_di_insn_bits;
 
s = dev->subdevices + 1;
-   s->type = COMEDI_SUBD_DO;
-   s->subdev_flags = SDF_WRITABLE;
-   s->n_chan = 16;
-   s->maxdata = 1;
-   s->range_table = _digital;
-   s->insn_bits = contec_do_insn_bits;
+   s->type = COMEDI_SUBD_DO;
+   s->subdev_flags = SDF_WRITABLE;
+   s->n_chan   = 16;
+   s->maxdata  = 1;
+   s->range_table  = _digital;
+   s->insn_bits= contec_do_insn_bits;
+
+   dev_info(dev->class_dev, "%s attached\n", dev->board_name);
 
-   printk("attached\n");
+   return 0;
+}
+
+static int contec_attach(struct comedi_device *dev,
+struct comedi_devconfig *it)
+{
+   dev_warn(dev->class_dev,
+   "This driver does not support attach using comedi_config\n");
 
-   return 1;
+   return -ENOSYS;
 }
 
 static void contec_detach(struct comedi_device *dev)
@@ -145,7 +118,6 @@ static void contec_detach(struct comedi_device *dev)
if (pcidev) {
if (dev->iobase)
comedi_pci_disable(pcidev);
-   pci_dev_put(pcidev);
}
 }
 
@@ -153,6 +125,7 @@ static struct comedi_driver contec_pci_dio_driver = {
   

[PATCH 5/7] staging: comedi: contec_pci_dio: remove unneeded boardinfo code

2012-08-15 Thread H Hartley Sweeten
The boardinfo code is not needed by this driver. Only one board
type is supported.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-hartman 
---
 drivers/staging/comedi/drivers/contec_pci_dio.c | 19 ++-
 1 file changed, 2 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/comedi/drivers/contec_pci_dio.c 
b/drivers/staging/comedi/drivers/contec_pci_dio.c
index 698d05b..4b47fa0 100644
--- a/drivers/staging/comedi/drivers/contec_pci_dio.c
+++ b/drivers/staging/comedi/drivers/contec_pci_dio.c
@@ -36,17 +36,6 @@ Configuration Options:
 
 #include "../comedidev.h"
 
-enum contec_model {
-   PIO1616L = 0,
-};
-
-struct contec_board {
-   const char *name;
-};
-static const struct contec_board contec_boards[] = {
-   {"PIO1616L", },
-};
-
 #define PCI_DEVICE_ID_PIO1616L 0x8172
 
 /*
@@ -94,7 +83,6 @@ static struct pci_dev *contec_find_pci_dev(struct 
comedi_device *dev,
pcidev->device != PCI_DEVICE_ID_PIO1616L)
continue;
 
-   dev->board_ptr = contec_boards + 0;
return pcidev;
}
dev_err(dev->class_dev,
@@ -105,7 +93,6 @@ static struct pci_dev *contec_find_pci_dev(struct 
comedi_device *dev,
 
 static int contec_attach(struct comedi_device *dev, struct comedi_devconfig 
*it)
 {
-   const struct contec_board *thisboard;
struct pci_dev *pcidev;
struct comedi_subdevice *s;
int ret;
@@ -120,8 +107,7 @@ static int contec_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
if (!pcidev)
return -EIO;
comedi_set_hw_dev(dev, >dev);
-   thisboard = comedi_board(dev);
-   dev->board_name = thisboard->name;
+   dev->board_name = dev->driver->driver_name;
 
if (comedi_pci_enable(pcidev, "contec_pci_dio")) {
printk("error enabling PCI device and request regions!\n");
@@ -182,8 +168,7 @@ static void __devexit contec_pci_dio_pci_remove(struct 
pci_dev *dev)
 }
 
 static DEFINE_PCI_DEVICE_TABLE(contec_pci_dio_pci_table) = {
-   { PCI_DEVICE(PCI_VENDOR_ID_CONTEC, PCI_DEVICE_ID_PIO1616L),
-   .driver_data = PIO1616L },
+   { PCI_DEVICE(PCI_VENDOR_ID_CONTEC, PCI_DEVICE_ID_PIO1616L) },
{ 0 }
 };
 MODULE_DEVICE_TABLE(pci, contec_pci_dio_pci_table);
-- 
1.7.11

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 4/7] staging: comedi: contec_pci_dio: define register map for board

2012-08-15 Thread H Hartley Sweeten
Only one board type is supported by this driver. Instead of
passing the register offsets for the digital in/out ports in
the boardinfo, define the register map and use that to access
the ports.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-hartman 
---
 drivers/staging/comedi/drivers/contec_pci_dio.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/comedi/drivers/contec_pci_dio.c 
b/drivers/staging/comedi/drivers/contec_pci_dio.c
index 24427ca..698d05b 100644
--- a/drivers/staging/comedi/drivers/contec_pci_dio.c
+++ b/drivers/staging/comedi/drivers/contec_pci_dio.c
@@ -42,26 +42,28 @@ enum contec_model {
 
 struct contec_board {
const char *name;
-   int in_offs;
-   int out_offs;
 };
 static const struct contec_board contec_boards[] = {
-   {"PIO1616L", 0, 2 },
+   {"PIO1616L", },
 };
 
 #define PCI_DEVICE_ID_PIO1616L 0x8172
 
+/*
+ * Register map
+ */
+#define PIO1616L_DI_REG0x00
+#define PIO1616L_DO_REG0x02
+
 static int contec_do_insn_bits(struct comedi_device *dev,
   struct comedi_subdevice *s,
   struct comedi_insn *insn, unsigned int *data)
 {
-   const struct contec_board *thisboard = comedi_board(dev);
-
if (data[0]) {
s->state &= ~data[0];
s->state |= data[0] & data[1];
 
-   outw(s->state, dev->iobase + thisboard->out_offs);
+   outw(s->state, dev->iobase + PIO1616L_DO_REG);
}
return insn->n;
 }
@@ -70,9 +72,7 @@ static int contec_di_insn_bits(struct comedi_device *dev,
   struct comedi_subdevice *s,
   struct comedi_insn *insn, unsigned int *data)
 {
-   const struct contec_board *thisboard = comedi_board(dev);
-
-   data[1] = inw(dev->iobase + thisboard->in_offs);
+   data[1] = inw(dev->iobase + PIO1616L_DI_REG);
 
return insn->n;
 }
-- 
1.7.11

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 3/7] staging: comedi: contec_pci_dio: remove unused fields in the boardinfo

2012-08-15 Thread H Hartley Sweeten
The model, in_ports, out_ports, and out_boffs information in the
boardinfo is not used by the driver. Remove them.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-hartman 
---
 drivers/staging/comedi/drivers/contec_pci_dio.c | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/staging/comedi/drivers/contec_pci_dio.c 
b/drivers/staging/comedi/drivers/contec_pci_dio.c
index 387dd42..24427ca 100644
--- a/drivers/staging/comedi/drivers/contec_pci_dio.c
+++ b/drivers/staging/comedi/drivers/contec_pci_dio.c
@@ -42,15 +42,11 @@ enum contec_model {
 
 struct contec_board {
const char *name;
-   int model;
-   int in_ports;
-   int out_ports;
int in_offs;
int out_offs;
-   int out_boffs;
 };
 static const struct contec_board contec_boards[] = {
-   {"PIO1616L", PIO1616L, 16, 16, 0, 2, 10},
+   {"PIO1616L", 0, 2 },
 };
 
 #define PCI_DEVICE_ID_PIO1616L 0x8172
-- 
1.7.11

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/7] staging: comedi: contec_pci_dio: remove function trace messages

2012-08-15 Thread H Hartley Sweeten
The dev_dbg function trace messages in the contec_do_insn_bits
and contec_di_insn_bits functions are just noise. Remove them.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-hartman 
---
 drivers/staging/comedi/drivers/contec_pci_dio.c | 9 +
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/drivers/staging/comedi/drivers/contec_pci_dio.c 
b/drivers/staging/comedi/drivers/contec_pci_dio.c
index 71b7266..387dd42 100644
--- a/drivers/staging/comedi/drivers/contec_pci_dio.c
+++ b/drivers/staging/comedi/drivers/contec_pci_dio.c
@@ -61,14 +61,10 @@ static int contec_do_insn_bits(struct comedi_device *dev,
 {
const struct contec_board *thisboard = comedi_board(dev);
 
-   dev_dbg(dev->class_dev, "contec_do_insn_bits called\n");
-   dev_dbg(dev->class_dev, "data: %d %d\n", data[0], data[1]);
-
if (data[0]) {
s->state &= ~data[0];
s->state |= data[0] & data[1];
-   dev_dbg(dev->class_dev, "out: %d on %lx\n", s->state,
-   dev->iobase + thisboard->out_offs);
+
outw(s->state, dev->iobase + thisboard->out_offs);
}
return insn->n;
@@ -80,9 +76,6 @@ static int contec_di_insn_bits(struct comedi_device *dev,
 {
const struct contec_board *thisboard = comedi_board(dev);
 
-   dev_dbg(dev->class_dev, "contec_di_insn_bits called\n");
-   dev_dbg(dev->class_dev, "data: %d %d\n", data[0], data[1]);
-
data[1] = inw(dev->iobase + thisboard->in_offs);
 
return insn->n;
-- 
1.7.11

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/7] staging: comedi: contec_pci_dio: remove thisboard macro

2012-08-15 Thread H Hartley Sweeten
This macro relies on a local variable of a specific name. Remove the
macro and use the comedi_board() helper to get the thisboard pointer.

Move the 'dev->board_name = thisboard->name;' in contec_attach().
The contec_find_pci_dev() function modifies the dev->board_ptr.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-hartman 
---
 drivers/staging/comedi/drivers/contec_pci_dio.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/comedi/drivers/contec_pci_dio.c 
b/drivers/staging/comedi/drivers/contec_pci_dio.c
index 944cfee..71b7266 100644
--- a/drivers/staging/comedi/drivers/contec_pci_dio.c
+++ b/drivers/staging/comedi/drivers/contec_pci_dio.c
@@ -55,12 +55,11 @@ static const struct contec_board contec_boards[] = {
 
 #define PCI_DEVICE_ID_PIO1616L 0x8172
 
-#define thisboard ((const struct contec_board *)dev->board_ptr)
-
 static int contec_do_insn_bits(struct comedi_device *dev,
   struct comedi_subdevice *s,
   struct comedi_insn *insn, unsigned int *data)
 {
+   const struct contec_board *thisboard = comedi_board(dev);
 
dev_dbg(dev->class_dev, "contec_do_insn_bits called\n");
dev_dbg(dev->class_dev, "data: %d %d\n", data[0], data[1]);
@@ -79,6 +78,7 @@ static int contec_di_insn_bits(struct comedi_device *dev,
   struct comedi_subdevice *s,
   struct comedi_insn *insn, unsigned int *data)
 {
+   const struct contec_board *thisboard = comedi_board(dev);
 
dev_dbg(dev->class_dev, "contec_di_insn_bits called\n");
dev_dbg(dev->class_dev, "data: %d %d\n", data[0], data[1]);
@@ -116,14 +116,13 @@ static struct pci_dev *contec_find_pci_dev(struct 
comedi_device *dev,
 
 static int contec_attach(struct comedi_device *dev, struct comedi_devconfig 
*it)
 {
+   const struct contec_board *thisboard;
struct pci_dev *pcidev;
struct comedi_subdevice *s;
int ret;
 
printk("comedi%d: contec: ", dev->minor);
 
-   dev->board_name = thisboard->name;
-
ret = comedi_alloc_subdevices(dev, 2);
if (ret)
return ret;
@@ -132,6 +131,8 @@ static int contec_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
if (!pcidev)
return -EIO;
comedi_set_hw_dev(dev, >dev);
+   thisboard = comedi_board(dev);
+   dev->board_name = thisboard->name;
 
if (comedi_pci_enable(pcidev, "contec_pci_dio")) {
printk("error enabling PCI device and request regions!\n");
-- 
1.7.11

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


  1   2   3   4   5   6   7   8   9   10   >