Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750890AbWHGCS3 (ORCPT ); Sun, 6 Aug 2006 22:18:29 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1750892AbWHGCS3 (ORCPT ); Sun, 6 Aug 2006 22:18:29 -0400 Received: from py-out-1112.google.com ([64.233.166.177]:31412 "EHLO py-out-1112.google.com") by vger.kernel.org with ESMTP id S1750894AbWHGCS1 (ORCPT ); Sun, 6 Aug 2006 22:18:27 -0400 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=a2UnF2xtC1vY58OVMX0S/qmt1jhhMlPgp+89AXac0F+3t9xDuESBLVsB41UrDwiNSOyGvH+b7JOSvNv+445f8FOFofMH4EFyqV8anivocm0HWTZwaB/EdCCETr431tlv3fDXhGeZij/kyXNWkhHImeEw1Hd/4EV8MTiapA4DfMk= Message-ID: <4745278c0608061918m1c77234crc5d9bc1c215549f9@mail.gmail.com> Date: Sun, 6 Aug 2006 22:18:23 -0400 From: "Vishal Patil" To: "Andrea Arcangeli" Subject: Re: Generic B-tree implementation Cc: "Anton Altaparmakov" , "Gary Funck" , "Linux Kernel Mailing List" In-Reply-To: <4745278c0607190926l57556563t410ca63514c8ca2f@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_33970_17874812.1154917103763" References: <4745278c0607180630m39040ad7neac25c1a64399aff@mail.gmail.com> <4745278c0607180822u55ffe5b4g333e2e6457b37d02@mail.gmail.com> <1153294394.13071.3.camel@imp.csi.cam.ac.uk> <4745278c0607190634l3ab43bb7t3d2a7b80c22d44c4@mail.gmail.com> <20060719161427.GN5726@opteron.random> <4745278c0607190926l57556563t410ca63514c8ca2f@mail.gmail.com> Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 79167 Lines: 1078 ------=_Part_33970_17874812.1154917103763 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Folks Following Andrea's suggestions I have implemented the Linux kernel page cache using B-Trees. I am attaching the patch along with this email. Note that the patch was developed against 2.6.16.2. Also the patch offers the B-tree data structure as a library (like the radix tree) Also I haven't made any performance measurements to compare it with the radix tree implementation. However ideas to do this are most welcome. Thanks - Vishal On 7/19/06, Vishal Patil wrote: > Andrea > > Thank you for your time and a very valuable input. I was thinking of > implementing the VM management using B-trees because I wanted to play > with something interesting in the kernel. However I will definately > look into your idea of page cache as well. > > Will keep everyone informed about my progress. > > - Vishal > > > On 7/19/06, Andrea Arcangeli wrote: > > On Wed, Jul 19, 2006 at 09:34:43AM -0400, Vishal Patil wrote: > > > I can get rid of recursions using loops, will need to work a little more on > > > it. > > > > Before doing the above you may want to learn about all possible malloc > > retvals too and to make sure the interface has all needed oom failure > > paths that you're obviously missing. > > > > One of the advantages of rbtree vs b-trees (and vs radixtrees too) is > > the fact they require zero dynamic metadata allocations of ram. They > > use the same trick of list.h to avoid it while still being mostly > > generic and sharable library code. Imagine rbtrees like scalable > > lists. The kernel usage is quite optimized too, the mmap path for > > example does a single lookup and it stores the last "lookup" point > > before restarting with an insertion while keeping the mmap_sem (or > > mutex renaming of the day) on hold so to avoid the insertion operation > > to start over with a second (wasteful) lookup (again very similar to > > what you could do if you had list, and the rebalancing is a very > > immediate operation too involving only a limited number of pointers). > > > > > Also I will be working on developing a patch for VM management using > > > B-trees instead of RB-trees. > > > > Once you start changing those bits, you'll notice the further > > requirement of the btrees due to the oom failures in code paths that > > are already reasonably complex with vma oom failures. > > > > As speed of cache raises faster than speed of ram, memory seeks tends > > to cost more than they did in the past, but I doubt it worth it, most > > important especially in the common case of very few vmas. I like the > > common case of only a few dozen vmas to be so fast and low > > overhead. The corner cases like uml and oracle already use nonlinear, > > to also avoid the ram overhead of the vmas, with btree the lowmem > > overhead would be even higher (the only 4/8 bytes of overhead of the > > rbtrees would even be fixable with David's patch, but nobody > > considered it very important so far to eliminate those 4/8 bytes > > 32bit/64bit per vma, though we can do that in the future). So even if > > btree would be faster for those extreme corner cases, it would still > > not be a replacement for the nonlinear (I wish there was a decent > > replacement for nonlinear, whose only reason to exist seems to be uml > > on 64bit archs). > > > > If I would be in you, as a slightly more likely to succeed experiment, > > I would be looking into replacing the pagecache radix-tree with a > > btree, as long as you can leave intact the tagging properties we have > > in the radix-tree needed for finding only dirty elements in the tree > > etc... (we use that to avoid separate dirty lists for the pages). You > > should also size the order to automatically match the cache size of > > the arch (dunno if it's better at compile or run time). I'm no a > > radix-tree guru but the btree may save some ram if you've all > > pagecache pages scattered all over the place with random access. It > > also won't require all levels to be allocated. However it will require > > rebalancing, something the radix tree doesn't require, it seems a bit > > of a tradeoff, and I suspect the radix-tree will still win in all > > common cases. But at least all oom failure paths should already exists > > for you, so that should avoid you having to touch much code externally > > to your own btree files. > > > > I wish you to have fun with the btrees, I remember I had fun back then > > when I was playing with the rbtrees ;). > > > > > -- > Motivation will almost always beat mere talent. > -- Motivation will almost always beat mere talent. ------=_Part_33970_17874812.1154917103763 Content-Type: text/x-patch; name=btree.rc1.patch; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: base64 X-Attachment-Id: f_eqk7shrs Content-Disposition: attachment; filename="btree.rc1.patch" ZGlmZiAtdXJOIGxpbnV4LTIuNi4xNi4yL21tL2ZpbGVtYXAuYyBsaW51eC0yLjYuMTYuMi1idHJl ZS9tbS9maWxlbWFwLmMKLS0tIGxpbnV4LTIuNi4xNi4yL21tL2ZpbGVtYXAuYwkyMDA2LTA0LTA3 IDEyOjU2OjQ3LjAwMDAwMDAwMCAtMDQwMAorKysgbGludXgtMi42LjE2LjItYnRyZWUvbW0vZmls ZW1hcC5jCTIwMDYtMDgtMDYgMjE6Mzc6NTUuMDAwMDAwMDAwIC0wNDAwCkBAIC0xMTIsMTAgKzEx MiwxNiBAQAogICovCiB2b2lkIF9fcmVtb3ZlX2Zyb21fcGFnZV9jYWNo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OwkJICAgICAg ICAvLyBQb2ludGVyIHVzZWQgZm9yIGxpbmtlZCBsaXN0IAorCWJvb2wgbGVhZjsJCQkgICAgICAg IC8vIFVzZWQgdG8gaW5kaWNhdGUgd2hldGhlciBsZWFmIG9yIG5vdAorICAgICAgICB1bnNpZ25l ZCBpbnQgbnJfYWN0aXZlOwkJICAgICAgICAvLyBOdW1iZXIgb2YgYWN0aXZlIGtleXMKKwl1bnNp Z25lZCBpbnQgbGV2ZWw7CQkgICAgICAgIC8vIExldmVsIGluIHRoZSBCLVRyZWUKKyAgICAgICAg YnRfa2V5X3ZhbCBrZXlfdmFsc1syKkJUUkVFX09SREVSIC0gMV07CS8vIEFycmF5IG9mIGtleXMg YW5kIHZhbHVlcworICAgICAgICBzdHJ1Y3QgYnRyZWVfbm9kZSAqIGNoaWxkcmVuWzIqQlRSRUVf T1JERVJdOwkvLyBBcnJheSBvZiBwb2ludGVycyB0byBjaGlsZCBub2RlcworICAgICAgICB1bnNp Z25lZCBsb25nIHRhZ3NbQlRSRUVfVEFHU11bQlRSRUVfVEFHX0xPTkdTXTsKKyAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vIEJpdG1hcCByZXF1aXJlZCBi eSBwYWdlCisgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAv LyBjYWNoZQorCXVuc2lnbmVkIGxvbmcgcGFkZGluZ1s2XTsKK30gOworCisvKgorKiAgICAgICBC LVRyZWUgbm9kZSBhbmQga2V5IHZhbCBjYWNoZQorKi8KK3N0YXRpYyBrbWVtX2NhY2hlX3QgKmJ0 cmVlX25vZGVfY2FjaGVwOworCisvKgorICogUGVyLWNwdSBwb29sIG9mIHByZWxvYWRlZCBub2Rl cworICovCitzdHJ1Y3QgYnRyZWVfcHJlbG9hZCB7CisgICAgICAgIGludCBucjsKKyAgICAgICAg c3RydWN0IGJ0cmVlX25vZGUgKm5vZGVzW0JUUkVFX01BWF9QQVR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lZC4K KyAqLworaW50IGJ0cmVlX3ByZWxvYWQoZ2ZwX3QgZ2ZwX21hc2spIHsKKyAgICAgICAgc3RydWN0 IGJ0cmVlX3ByZWxvYWQgKmJ0cDsKKyAgICAgICAgc3RydWN0IGJ0cmVlX25vZGUgKm5vZGU7Cisg ICAgICAgIGludCByZXQgPSAtRU5PTUVNOworCisgICAgICAgIHByZWVtcHRfZGlzYWJsZSgpOwor ICAgICAgICBidHAgPSAmX19nZXRfY3B1X3ZhcihidHJlZV9wcmVsb2Fkcyk7CisgICAgICAgIHdo aWxlIChidHAtPm5yIDwgQVJSQVlfU0laRShidHAtPm5vZGVzKSkgeworICAgICAgICAgICAgICAg IHByZWVtcHRfZW5hYmxlKCk7CisgICAgICAgICAgICAgICAgbm9kZSA9IGttZW1fY2FjaGVfYWxs b2MoYnRyZWVfbm9kZV9jYWNoZXAsIGdmcF9tYXNrKTsKKyAgICAgICAgICAgICAgICBpZiAobm9k ZSA9PSBOVUxMKQorICAgICAgICAgICAgICAgICAgICAgICAgZ290byBvdXQ7CisgICAgICAgICAg ICAgICAgcHJlZW1wdF9kaXNhYmxlKCk7CisgICAgICAgICAgICAgICAgYnRwID0gJl9fZ2V0X2Nw dV92YXIoYnRyZWVfcHJlbG9hZHMpOworICAgICAgICAgICAgICAgIGlmIChidHAtPm5yIDwgQVJS QVlfU0laRShidHAtPm5vZGVzKSkKKyAgICAgICAgICAgICAgICAgICAgICAgIGJ0cC0+bm9kZXNb YnRwLT5ucisrXSA9IG5vZGU7CisgICAgICAgICAgICAgICAgZWxzZQorICAgICAgICAgICAgICAg ICAgICAgICAga21lbV9jYWNoZV9mcmVlKGJ0cmVlX25vZGVfY2FjaGVwLCBub2RlKTsKKyAgICAg ICAgfQorICAgICAgICByZXQgPSAwOworb3V0OgorICAgICAgICByZXR1cm4gcmV0OworfQorCisv KioKKyogICAgICAgRnVuY3Rpb24gdXNlZCB0byBhbGxvY2F0ZSBtZW1vcnkgZm9yIHRoZSBidHJl ZSBub2RlCisqICAgICAgIEBwYXJhbSBidHJlZSBUaGUgYnRyZWUKKyogICAgICAgQHBhcmFtIG9y ZGVyIE9yZGVyIG9mIHRoZSBCLVRyZWUKKyogICAgICAgQHJldHVybiBUaGUgYWxsb2NhdGVkIEIt dHJlZSBub2RlCisqLworc3RhdGljIGJ0cmVlX25vZGUgKiBhbGxvY2F0ZV9idHJlZV9ub2RlIChi dHJlZSAqIGJ0cmVlLHVuc2lnbmVkIGludCBvcmRlcikgeworICAgICAgICBidHJlZV9ub2RlICog bm9kZTsKKworICAgICAgICAvLyBBbGxvY2F0ZSBtZW1vcnkgZm9yIHRoZSBub2RlCisgICAgICAg IG5vZGUgPSBrbWVtX2NhY2hlX2FsbG9jKGJ0cmVlX25vZGVfY2FjaGVwLGJ0cmVlLT5nZnBfbWFz ayk7CisKKyAgICAgICAgLy8gSWYgdGhpcyBpcyBOVUxMIGdldCBwcmVsb2FkZWQgbm9kZQorICAg ICAgICBpZiAobm9kZSAgPT0gTlVMTCAmJiAhKGJ0cmVlLT5nZnBfbWFzayAmIF9fR0ZQX1dBSVQp KSB7CisgICAgICAgICAgICAgICAgc3RydWN0IGJ0cmVlX3ByZWxvYWQgKmJ0cDsKKworICAgICAg ICAgICAgICAgIGJ0cCA9ICZfX2dldF9jcHVfdmFyKGJ0cmVlX3ByZWxvYWRzKTsKKyAgICAgICAg ICAgICAgICBpZiAoYnRwLT5ucikgeworICAgICAgICAgICAgICAgICAgICAgICAgbm9kZSA9IGJ0 cC0+bm9kZXNbYnRwLT5uciAtIDFdOworICAgICAgICAgICAgICAgICAgICAgICAgYnRwLT5ub2Rl c1tidHAtPm5yIC0gMV0gPSBOVUxMOworICAgICAgICAgICAgICAgICAgICAgICAgYnRwLT5uci0t OworICAgICAgICAgICAgICAgIH0KKyAgICAgICAgfQorICAgICAgIAorICAgICAgICAvLyBJbml0 aWFsaXplIHRoZSBudW1iZXIgb2YgYWN0aXZlIG5vZGVzCisgICAgICAgIG5vZGUtPm5yX2F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l bnRfbm9kZTsKKwkKK2luc2VydDoJaSA9IG5vZGUtPm5yX2FjdGl2ZSAtIDE7CisJaWYobm9kZS0+ bGVhZikgeworCQl3aGlsZShpID49IDAgJiYga2V5IDwgbm9kZS0+a2V5X3ZhbHNbaV0ua2V5KSB7 CisJCQlub2RlLT5rZXlfdmFsc1tpICsgMV0gPSBub2RlLT5rZXlfdmFsc1tpXTsKKyAgICAgICAg ICAgICAgICAgICAgICAgIHRyYW5zZmVyX3RhZ3Mobm9kZSxpLG5vZGUsaSArIDEpOworCQkJaS0t OworCQl9CisKKwkJbm9kZS0+a2V5X3ZhbHNbaSArIDFdLmtleSA9IGtleTsKKyAgICAgICAgICAg ICAgICBub2RlLT5rZXlfdmFsc1tpICsgMV0udmFsID0ga2V5X3ZhbC0+dmFsOworCisJCS8vIElk ZW50aWNhbCBrZXkgZm91bmQKKyAgICAgICAgICAJaWYgKGkgPj0gMCAmJiAKKwkJCWtleSA9PSBu b2RlLT5rZXlfdmFsc1tpXS5rZXkpIHsKKyAgICAgICAgICAgICAgICAgICAgICAgIGZvciAoaiA9 IGkgKyAxOyBqIDxub2RlLT5ucl9hY3RpdmU7IGorKyApIHsKKyAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgbm9kZS0+a2V5X3ZhbHNbal0gPQorICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgIG5vZGUtPmtleV92YWxzW2ogKyAxXTsKKwkJCQl0cmFuc2Zlcl90YWdz KG5vZGUsaixub2RlLGogKyAxKTsKKyAgICAgICAgICAgICAgICAgICAgICAgIH0KKwkJCXJldHVy biAtRUVYSVNUOworICAgICAgICAgICAgICAgIH0gZWxzZQorCQlub2RlLT5ucl9hY3RpdmUrKzsg CisJfSBlbHNlIHsKKwkJd2hpbGUgKGkgPj0gMCAmJiBrZXkgPCBub2RlLT5rZXlfdmFsc1tpXS5r ZXkpIHsKKwkJCWktLTsKKwkJfQorCisgICAgICAgICAgICAgICAgLy8gSWRlbnRpY2FsIGtleSBm b3VuZCAgCisgICAgICAgICAgICAgICAgaWYgKGkgPj0gMCAmJiBrZXkgPT0gbm9kZS0+a2V5X3Zh bHNbaV0ua2V5KSB7CisgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gLUVFWElTVDsKKyAg ICAgICAgICAgICAgICB9CisKKwkJaSsrOworCQljaGlsZCA9IG5vZGUtPmNoaWxkcmVuW2ldOyAK KwkJCisJCWlmKGNoaWxkLT5ucl9hY3RpdmUgPT0gMipidHJlZS0+b3JkZXIgLSAxKSB7CisKKyAJ CQkvLyBDaGVjayBmb3IgaWRlbnRpY2FsIGtleSBoZXJlCisgICAgICAgICAgICAgICAgICAgICAg ICBmb3IgKGo9MDtqPGNoaWxkLT5ucl9hY3RpdmU7aisrKSB7CisgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgIGlmIChrZXkgPT0gY2hpbGQtPmtleV92YWxzW2pdLmtleSkgeworICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiAtRUVYSVNUOworICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICB9CisKKyAgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgaWYgKGtleSA8IGNoaWxkLT5rZXlfdmFsc1tqXS5rZXkpIHsKKyAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKKyAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgfQorICAgICAgICAgICAgICAgICAgICAgICAgfQorCisJCQlidHJlZV9zcGxpdF9j aGlsZChidHJlZSxub2RlLGksY2hpbGQpOworCQkJaWYoa2V5ID4gCisJCQkJbm9kZS0+a2V5X3Zh bHNbaV0ua2V5KSB7CisJCQkJaSsrOwkKKwkJCX0JCisJCX0KKwkJbm9kZSA9IG5vZGUtPmNoaWxk cmVuW2ldOworCQlnb3RvIGluc2VydDsJCisJfQorICAgICAgIHJldHVybiAwOwkKK30KKworCisv KioKKyogICAgICAgRnVuY3R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b24gc3VjY2VzcyAt MSBvbiBlcnJvciAKKyovCisKK2J0X2tleV92YWwgcmVtb3ZlX2tleV9mcm9tX2xlYWYoYnRyZWUg KiBidHJlZSwgbm9kZV9wb3MgKiBub2RlX3BvcykgeworCXVuc2lnbmVkIGludCBrZXlzX21heCA9 IDIqYnRyZWUtPm9yZGVyIC0gMTsKKwl1bnNpZ25lZCBpbnQgaTsKKwlidF9rZXlfdmFsIGtleV92 YWw7CisJYnRyZWVfbm9kZSAqIG5vZGUgPSBub2RlX3Bvcy0+bm9kZTsKKworICAgICAgICBrZXlf dmFsLmtleSA9IC0xOworICAgICAgICBrZXlfdmFsLnZhbCA9IE5VTEw7CisKKwlpZihub2RlLT5s ZWFmID09IGZhbHNlKSB7CisJCXJldHVybiBrZXlfdmFsOworCX0JCisJCisJa2V5X3ZhbCA9IG5v ZGUtPmtleV92YWxzW25vZGVfcG9zLT5pbmRleF07CisKKwlmb3IoaT1ub2RlX3Bvcy0+aW5kZXg7 aTwga2V5c19tYXggLSAxO2krKykgeworCQlub2RlLT5rZXlfdmFsc1tpXSA9IG5vZGUtPmtleV92 YWxzW2kgKyAxXTsKKyAgICAgICAgICAgICAgICB0cmFuc2Zlcl90YWdzKG5vZGUsaSArIDEsbm9k ZSxpKTsKKwl9CisJCisJbm9kZS0+bnJfYWN0aXZlLS07CisKKwlpZihub2RlLT5ucl9hY3RpdmUg PT0gMCApIHsKKyAgICAgICAgICAgICAgICBpZiAoYnRyZWUtPnJvb3QgPT0gbm9kZSkgeworICAg ICAgICAgICAgICAgICAgICAgICAgYnRyZWUtPnJvb3QgPSBOVUxMOworICAgICAgICAgICAgICAg IH0KKwkJZnJlZV9idHJlZV9ub2RlKG5vZGUpOworCX0KKwlyZXR1cm4ga2V5X3ZhbDsKK30KKwor LyoqCisqICAgICAgIEZ1bmN0aW9uIHVzZWQgdG8gcmVtb3ZlIGEgbm9kZSBmcm9tIGEgIEItVHJl ZQorKiAgICAgICBAcGFyYW0gYnRyZWUgVGh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c2ltcGx5IHJldHVy bgorICAgICAgICAgICAgaWYoIW5vZGUtPm5yX2FjdGl2ZSkKKyAgICAgICAgICAgICAgICByZXR1 cm4gcmVtb3ZlZF9rdjsKKworCSAgICAvLyBGaXggdGhlIGluZGV4IG9mIHRoZSBrZXkgZ3JlYXRl ciB0aGFuIG9yIGVxdWFsCisJICAgIC8vIHRvIHRoZSBrZXkgdGhhdCB3ZSB3b3VsZCBsaWtlIHRv IHNlYXJjaAorCQkKKwkgICAgd2hpbGUgKGkgPCBub2RlLT5ucl9hY3RpdmUgJiYga3YgPiAKKwkJ CSAgICBub2RlLT5rZXlfdmFsc1tpXS5rZXkpIHsKKwkJICAgIGkrKzsKKwkgICAgfQorCSAgICBp bmRleCA9IGk7CisKKwkgICAgLy8gSWYgd2UgZmluZCBzdWNoIGtleSBicmVhawkJICAgIAorCSAg ICBpZihpIDwgbm9kZS0+bnJfYWN0aXZlICYmIAorCQkJa3YgPT0gbm9kZS0+a2V5X3ZhbHNbaV0u a2V5KSB7CisJCQlicmVhazsKKwkgICAgfQorICAgICAgICAgICAgaWYobm9kZS0+bGVhZikKKyAg ICAgICAgICAgICAgICByZXR1cm4gcmVtb3ZlZF9rdjsKKyAgICAgICAgICAgICAgICAKKyAgICAJ ICAgIC8vU3RvcmUgdGhlIHBhcmVudCBub2RlCisJICAgIHBhcmVudCA9IG5vZGU7CisKKwkgICAg Ly8gVG8gZ2V0IGEgY2hpbGQgbm9kZSAKKwkgICAgbm9kZSA9IG5vZGUtPmNoaWxkcmVuW2ldOwor CisgICAgICAgICAgICAvL0lmIE5VTEwgbm90IGZvdW5kCisgICAgICAgICAgICBpZiAobm9kZSA9 PSBOVUxMKQorICAgICAgICAgICAgICAgIHJldHVybiByZW1vdmVkX2t2OworCisgICAgICAgICAg ICBpZiAoaW5kZXggPT0gKHBhcmVudC0+bnJfYWN0aXZlKSkgeyAgIAorICAgICAgICAgICAgICAg IGxzaWJsaW5nID0gIHBhcmVudC0+Y2hpbGRyZW5b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bltpbmRleCAr IDFdLT5ucl9hY3RpdmUgPiBidHJlZS0+b3JkZXIgLSAxKSApIHsKKwkJCXRvX3JlbW92ZV9rdiA9 IG5vZGUtPmtleV92YWxzW2luZGV4XTsKKworCQkJc3ViX25vZGVfcG9zID0gCisgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgIGdldF9taW5fa2V5X3BvcyhidHJlZSxub2RlLT5jaGlsZHJl bltpbmRleCArIDFdKTsKKyAgICAgICAgICAgICAgICAgICAgICAgIGtleV92YWwgPSBzdWJfbm9k ZV9wb3Mubm9kZS0+a2V5X3ZhbHNbc3ViX25vZGVfcG9zLmluZGV4XTsKKyAgICAgICAgCQlub2Rl LT5rZXlfdmFsc1tpbmRleF0gPSBrZXlfdmFsOwkKKyAgICAgICAgICAgICAgICAgICAgICAgIHRy YW5zZmVyX3RhZ3Mobm9kZSxpbmRleCxzdWJfbm9kZV9wb3Mubm9kZSwKKyAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgc3ViX25vZGVfcG9zLmluZGV4KTsKKworCQkJc3ViX25vZGVfcG9z Lm5vZGUtPmtleV92YWxzW3N1Yl9ub2RlX3Bvcy5pbmRleF0gPSAKKwkJCQl0b19yZW1vdmVfa3Y7 CisKKyAgICAgICAgICAgICAgICAgICAgICAgIG5vZGUgPSBub2RlLT5jaGlsZHJlbltpbmRleCAr IDFdOworICAgICAgICAgICAgICAgICAgICAgICAgZ290byBkZWxfbG9vcDsKKyAgICAgICAgICAg ICAgCisJCX0gZWxzZSBpZiAoIAorCQkJbm9kZS0+Y2hpbGRyZW5baW5kZXhdLT5ucl9hY3RpdmUg PT0gYnRyZWUtPm9yZGVyIC0gMSAmJgorCQkJbm9kZS0+Y2hpbGRyZW5baW5kZXggKyAxXS0+bnJf YWN0aXZlID09IGJ0cmVlLT5vcmRlciAtIDEpIHsKKworCQkJY29tYl9ub2RlID0gbWVyZ2Vfbm9k ZXMoYnRyZWUsbm9kZS0+Y2hpbGRyZW5baW5kZXhdLAorICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICBub2RlLT5rZXlfdmFsc1tpbmRleF0sCisJCQkJbm9kZS0+Y2hpbGRyZW5baW5kZXgg KyAxXSk7CisJCQlub2RlLT5jaGlsZHJlbltpbmRleF0gPSBjb21iX25vZGU7CisJCQkKKwkJCWZv cihpPWluZGV4ICsgMTtpPG5vZGUtPm5yX2FjdGl2ZTtpKyspIHsKKwkJCQlub2RlLT5jaGlsZHJl bltpXSA9IG5vZGUtPmNoaWxkcmVuW2kgKyAxXTsKKwkJCQlub2RlLT5rZXlfdmFsc1tpIC0gMV0g PSBub2RlLT5rZXlfdmFsc1tpXTsKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdHJh bnNmZXJfdGFncyhub2RlLGksbm9kZSxpIC0gMSk7CisJCQl9CisJCQlub2RlLT5ucl9hY3RpdmUt LTsKKyAgICAgICAgICAgICAgICAgICAgICAgIGlmIChub2RlLT5ucl9hY3RpdmUgPT0gMCAmJiBi dHJlZS0+cm9vdCA9PSBub2RlKSB7CisgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZy ZWVfYnRyZWVfbm9kZShub2RlKTsKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYnRy ZWUtPnJvb3QgPSBjb21iX25vZGU7ICAgICAgICAKKyAgICAgICAgICAgICAgICAgICAgICAgIH0g CisgICAgICAgICAgICAgICAgICAgICAgICBub2RlID0gY29tYl9ub2RlOworICAgICAgICAgICAg ICAgICAgICAgICAgZ290byBkZWxfbG9vcDsKKwkJfQkJCisgICAgICAgICAgfQorCQorCS8vIENh c2UgMzoKKwkvLyBJbiB0aGlzIGNhc2Ugc3RhcnQgZnJvbSB0aGUgdG9wIG9mIHRoZSB0cmVlIGFu ZCBjb250aW51ZQorCS8vIG1vdmluZyB0byB0aGUgbGVhZiBub2RlIG1ha2luZyBzdXJlIHRoYXQg ZWFjaCBub2RlIHRoYXQKKwkvLyB3ZSBlbmNvdW50ZXI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LCAqIG5vZGU7CisgICAgICAgYnRyZWVfbm9kZSAqIGNoaWxk LCAqIGRlbF9ub2RlOworCisgICAgICAgbm9kZSA9IGJ0cmVlLT5yb290OworICAgICAgIGN1cnJl bnRfbGV2ZWwgPSBub2RlLT5sZXZlbDsKKyAgICAgICBoZWFkID0gbm9kZTsKKyAgICAgICB0YWls ID0gbm9kZTsKKworICAgICAgIHdoaWxlKHRydWUpIHsKKyAgICAgICAgICAgICAgIGlmKGhlYWQg PT0gTlVMTCkgeworICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKKyAgICAgICAgICAgICAg IH0KKyAgICAgICAgICAgICAgIGlmIChoZWFkLT5sZXZlbCA8IGN1cnJlbnRfbGV2ZWwpIHsKKyAg ICAgICAgICAgICAgICAgICAgICAgY3VycmVudF9sZXZlbCA9IGhlYWQtPmxldmVsOworICAgICAg ICAgICAgICAgfQorCisgICAgICAgICAgICAgICBpZihoZWFkLT5sZWFmID09IGZhbHNlKSB7Cisg ICAgICAgICAgICAgICAgICAgICAgIGZvcihpID0gMCA7IGkgPCBoZWFkLT5ucl9hY3RpdmUgKyAx OyBpKyspIHsKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjaGlsZCA9IGhlYWQtPmNo aWxkcmVuW2ldOworICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRhaWwtPm5leHQgPSBj aGlsZDsKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0YWlsID0gY2hpbGQ7CisgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgY2hpbGQtPm5leHQgPSBOVUxMOworICAgICAgICAg ICAgICAgICAgICAgICB9CisgICAgICAgICAgICAgICB9CisgICAgICAgICAgICAgICBkZWxfbm9k ZSA9IGhlYWQ7CisgICAgICAgICAgICAgICBoZWFkID0gaGVhZC0+bmV4dDsKKyAgICAgICAgICAg ICAgIGZyZWVfYnRyZWVfbm9kZShkZWxfbm9kZSk7CisgICAgICAgfQorCit9CisKK2ludCBidHJl ZV90YWdnZWQoYnRyZWUgKiBidHJlZSwgaW50IHRhZykgeworICAgICAgICBpbnQgaSA9IDA7Cisg ICAgICAgIGJ0cmVlX25vZGUgKiBoZWFkLCAqIHRhaWw7CisgICAgICAgIGJ0cmVlX25vZGUgKiBj aGlsZDsKKworICAgICAgICBoZWFkID0gYnRyZWUtPnJvb3Q7CisgICAgICAgIHRhaWwgPSBidHJl ZS0+cm9vdDsKKworICAgICAgICB3aGlsZSh0cnVlKSB7CisgICAgICAgICAgICAgICAgaWYoaGVh ZCA9PSBOVUxMKSB7CisgICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKKyAgICAgICAgICAg ICAgICB9CisKKyAgICAgICAgICAgICAgICBmb3IgKGkgPSAwOyBpIDwgaGVhZC0+bnJfYWN0aXZl OyBpKysgKSB7CisgICAgICAgICAgICAgICAgICAKKyAgICAgICAgICAgICAgICAgIGlmICh0YWcg IT0gLTEgJiYgdGFnX2dldChoZWFkLHRhZyxpKSkgCisgICAgICAgICAgICAgICAgICAgICByZXR1 cm4gMTsKKyAgICAgICAgICAgICAgICAgIAorICAgICAgICAgICAgICAgIH0gICAgIAorCisgICAg ICAgICAgICAgICAgaWYoaGVhZC0+bGVhZiA9PSBmYWxzZSkgeworICAgICAgICAgICAgICAgICAg ICAgICAgZm9yKGkgPSAwIDsgaSA8IGhlYWQtPm5yX2FjdGl2ZSArIDE7IGkrKykgeworICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICBjaGlsZCA9IGhlYWQtPmNoaWxkcmVuW2ldOworICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0YWlsLT5uZXh0ID0gY2hpbGQ7CisgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgIHRhaWwgPSBjaGlsZDsKKyAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgY2hpbGQtPm5leHQgPSBOVUxMOworICAgICAgICAgICAgICAgICAgICAg ICAgfQorICAgICAgICAgICAgICAgIH0KKyAgICAgICAgICAgICAgICBoZWFkID0gaGVhZC0+bmV4 dDsKKyAgICAgICAgfQorICAgICAgICByZXR1cm4gMDsKK30KK0VYUE9SVF9TWU1CT0woYnRyZWVf dGFnZ2VkKTsKKworLyoKKyAqIFJldHVybnMgMSBpZiBhbnkgc2xvdCBpbiB0aGUgbm9kZSBoYXMg dGhpcyB0YWcgc2V0LgorICogT3RoZXJ3aXNlIHJldHVybnMgMC4KKyAqLworc3RhdGljIGlubGlu ZSBpbnQgYW55X3RhZ19zZXQoc3RydWN0IGJ0cmVlX25vZGUgKm5vZGUsIGludCB0YWcpCit7Cisg ICAgICAgIGludCBpZHg7CisgICAgICAgIGZvciAoaWR4ID0gMDsgaWR4IDwgQlRSRUVfVEFHX0xP TkdTOyBpZHgrKykgeworICAgICAgICAgICAgICAgIGlmIChub2RlLT50YWdzW3RhZ11baWR4XSkK KyAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiAxOworICAgICAgICB9CisgICAgICAgIHJl dHVybiAwOworfQorCitzdGF0aWMgdm9pZCBjbGVhcl90YWdzKGJ0cmVlX25vZGUgKiBub2RlLCBp bnQgaW5kZXgpIHsKKwkgaW50IHRhZzsKKyAgICAgICAgZm9yICh0YWcgPSAwO3RhZzwgQlRSRUVf VEFHUzsgdGFnKyspIHsKKwkJdGFnX2NsZWFyKG5vZGUsdGFnLGluZGV4KTsKKyAgICAgICAgfQor fQorCitzdGF0aWMgdm9pZCB0cmFuc2Zlcl90YWdzKGJ0cmVlX25vZGUgKiBzb3VyY2Vfbm9kZSwg aW50IHNvdXJjZV9pbmRleCwKKyAgICAgICAgICAgICAgICBidHJlZV9ub2RlICogZGVzdF9ub2Rl LGludCBkZXN0X2luZGV4KSB7CisKKyAgICAgICAgaW50IHRhZzsKKyAgICAgICAgZm9yICh0YWcg PSAwO3RhZzwgQlRSRUVfVEFHUzsgdGFnKyspIHsKKyAgICAgICAgICAgICAgICBpZiAodGFnX2dl dChzb3VyY2Vfbm9kZSx0YWcsc291cmNlX2luZGV4KSkgeworICAgICAgICAgICAgICAgICAgICAg ICAgdGFnX3NldChkZXN0X25vZGUsdGFnLGRlc3RfaW5kZXgpOworICAgICAgICAgICAgICAgICAg ICAgICAgdGFnX2NsZWFyKHNvdXJjZV9ub2RlLHRhZyxzb3VyY2VfaW5kZXgpOworICAgICAgICAg ICAgICAgIH0gZWxzZSB7CisgICAgICAgICAgICAgICAgICAgICAgICB0YWdfY2xlYXIoZGVzdF9u b2RlLHRhZyxkZXN0X2luZGV4KTsKKyAgICAgICAgICAgICAgICB9CisgICAgICAgIH0KK30KKwor c3RhdGljIHVuc2lnbmVkIGludCBfX2xvb2t1cChidHJlZSAqIGJ0cmVlLCB2b2lkICoqIHJlc3Vs dHMsCisgICAgICAgIHVuc2lnbmVkIGxvbmcgZmlyc3RfaW5kZXgsdW5zaWduZWQgaW50IG1heF9p dGVtcywgaW50IHRhZykgeworCisgICAgICAgIGludCBpID0gMCwgaiA9IDA7CisgICAgICAgIGlu dCByZXQgPSAwOworICAgICAgICB1bnNpZ25lZCBsb25nIGtleTsKKyAgICAgICAgYnRyZWVfbm9k ZSAqIGhlYWQsICogdGFpbDsKKyAgICAgICAgYnRyZWVfbm9kZSAqIGNoaWxkOworCisgICAgICAg IGhlYWQgPSBidHJlZS0+cm9vdDsKKyAgICAgICAgdGFpbCA9IGJ0cmVlLT5yb290OworCisgICAg ICAgIHdoaWxlKHRydWUpIHsKKyAgICAgICAgICAgICAgICBpZihoZWFkID09IE5VTEwpIHsKKyAg ICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOworICAgICAgICAgICAgICAgIH0KKworICAgICAg ICAgICAgICAgIGlmICgoaGVhZC0+a2V5X3ZhbHNbaGVhZC0+bnJfYWN0aXZlIC0gMV0ua2V5IAor ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA+PSBmaXJzdF9pbmRleCkgJiYgKHJldCA8 IG1heF9pdGVtcykpIHsKKyAgICAgICAgICAgICAgICAgICBmb3IgKGkgPSAwOyBpIDwgaGVhZC0+ bnJfYWN0aXZlOyBpKysgKSB7CisgICAgICAgICAgICAgICAgICAgICAKKyAgICAgICAgICAgICAg ICAgICAgIGlmICh0YWcgIT0gLTEgJiYgIXRhZ19nZXQoaGVhZCx0YWcsaSkpIAorICAgICAgICAg ICAgICAgICAgICAgICAgY29udGludWU7CisgICAgICAgICAgICAgICAgICAgICAKKyAgICAgICAg ICAgICAgICAgICAgIGlmICgoa2V5ID0gaGVhZC0+a2V5X3ZhbHNbaV0ua2V5KSAKKyAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgID49IGZpcnN0X2luZGV4KSB7 CisgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vIEluc2VydGlvbiBzb3J0ICAgICAg ICAgICAgICAgIAorICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmb3IgKGogPSAocmV0 IC0gMSk7aj49MDtqLS0pIHsKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg aWYgKGJ0cmVlLT5rZXkocmVzdWx0c1tqXSkgPiBrZXkpIHsKKyAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdHNbaiArIDFdID0KKyAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXN1bHRzW2pdOyAgICAK KyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKKyAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOworICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CisgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgIH0KKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKKyAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgcmVzdWx0c1srK2pdID0gaGVhZC0+a2V5X3ZhbHNbaV0udmFsOyAK KyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0Kys7CisKKyAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgaWYocmV0ID09IG1heF9pdGVtcykgeworICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOworICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICB9CisgICAgICAgICAgICAgICAgICAgICB9ICAgICAgICAgICAKKyAgICAgICAgICAg ICAgICAgICB9ICAgICAKKyAgICAgICAgICAgICAgICB9CisKKyAgICAgICAgICAgICAgICBpZiho ZWFkLT5sZWFmID09IGZhbHNlKSB7CisgICAgICAgICAgICAgICAgICAgICAgICBmb3IoaSA9IDAg OyBpIDwgaGVhZC0+bnJfYWN0aXZlICsgMTsgaSsrKSB7CisgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgIGNoaWxkID0gaGVhZC0+Y2hpbGRyZW5baV07CisgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgIHRhaWwtPm5leHQgPSBjaGlsZDsKKyAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgdGFpbCA9IGNoaWxkOworICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBj aGlsZC0+bmV4dCA9IE5VTEw7CisgICAgICAgICAgICAgICAgICAgICAgICB9CisgICAgICAgICAg ICAgICAgfQorICAgICAgICAgICAgICAgIGhlYWQgPSBoZWFkLT5uZXh0OworICAgICAgICB9Cisg ICAgICAgIHJldHVybiByZXQ7Cit9CisKKy8qKgorKiAgICAgICBQZXJmb3JtIG11bHRpcGxlIGxv b2t1cCBvbiB0aGUgQi1UcmVlCisqICAgICAgIEBwYXJhbSBidHJlZSBUaGUgYnRyZWUKKyogICAg ICAgQHBhcmFtIHJlc3VsdHMgd2hlcmUgdGhlIHJlc3VsdHMgd2lsbCBiZSBwbGFjZWQKKyogICAg ICAgQHBhcmFtIGZpcnN0X2luZGV4IHN0YXJ0IHRoZSBsb29rdXAgZnJvbSB0aGlz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FWFBPUlRfU1lNQk9MKGJ0cmVlX3RhZ19j bGVhcik7CisKKy8qKgorKiAgICAgICBVc2VkIHRvIHZlcmlmeSB3aGV0aGVyIGEgdGFnIGlzIHNl dAorKiAgICAgICBAcGFyYW0gYnRyZWUgVGhlIGJ0cmVlCisqICAgICAgIEBwYXJhbSBrZXkgVGhl IGtleQorKiAgICAgICBAcGFyYW0gdGFnIFRoZSB0YWcKKyogICAgICAgQHJldHVybgorKiAgICAg ICAwOiB0YWcgbm90IHByZXNlbnQKKyogICAgICAgMTogdGFnIHByZXNlbnQsIHNldAorKiAgICAg ICAtMTogdGFnIHByZXNlbnQsIHVuc2V0IAorKi8KK2ludCBidHJlZV90YWdfZ2V0KGJ0cmVlICog YnRyZWUsdW5zaWduZWQgbG9uZyBrZXksIGludCB0YWcpIHsKKyAgICAgICAgaW50IHJldCA9IDA7 CisgICAgICAgIGJ0X2tleV92YWwgKiBrZXlfdmFsID0gTlVMTDsKKwlub2RlX3BvcyBrcCA9IGdl dF9idHJlZV9ub2RlKGJ0cmVlLGtleSk7CisKKwlpZihrcC5ub2RlKSB7CisJCWtleV92YWwgPSAm a3Aubm9kZS0+a2V5X3ZhbHNba3AuaW5kZXhdOworICAgICAgICAgICAgICAgIHJldCA9IHRhZ19n ZXQoa3Aubm9kZSx0YWcsa3AuaW5kZXgpOworICAgICAgICAgICAgICAgIHJldHVybiByZXQ/IDEg OiAtMTsKKwl9CisgICAgICAgIEJVR19PTihrZXlfdmFsID09IE5VTEwpOworCXJldHVybiByZXQ7 IAorfQorRVhQT1JUX1NZTUJPTChidHJlZV90YWdfZ2V0KTsKKworCisvKioKKyoJR2V0IHRoZSBt YXgga2V5IGluIHRoZSBidHJlZQorKglAcGFyYW0gYnRyZWUgVGhlIGJ0cmVlCisqCUByZXR1cm4g VGhlIG1heCBrZXkgCisqLwordW5zaWduZWQgbG9uZyBidHJlZV9nZXRfbWF4X2tleShidHJlZSAq IGJ0cmVlKSB7CisJbm9kZV9wb3Mgbm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WUgKiBidHJlZSk7CitleHRlcm4gdW5zaWduZWQgbG9uZyBidHJlZV9nZXRfbWF4 X2tleShidHJlZSAqIGJ0cmVlKTsKK2V4dGVybiB1bnNpZ25lZCBsb25nIGJ0cmVlX2dldF9taW5f a2V5KGJ0cmVlICogYnRyZWUpOworZXh0ZXJuIHVuc2lnbmVkIGxvbmcgYnRyZWVfdmFsdWVfZm4o dW5zaWduZWQgbG9uZyBrZXkpOworZXh0ZXJuIHVuc2lnbmVkIGxvbmcgYnRyZWVfa2V5X2ZuKHZv aWQgKiBwYWdlKTsKK2V4dGVybiB2b2lkIGJ0cmVlX3ByaW50X2ZuKHVuc2lnbmVkIGxvbmcga2V5 KTsKK2V4dGVybiBpbnQgYnRyZWVfcHJlbG9hZChnZnBfdCBnZnBfbWFzayk7CitleHRlcm4gaW50 IGJ0cmVlX3RhZ2dlZChidHJlZSAqIGJ0cmVlLCBpbnQgdGFnKTsKKworc3RhdGljIGlubGluZSB2 b2lkIGJ0cmVlX3ByZWxvYWRfZW5kKHZvaWQpCit7CisgICAgICAgIHByZWVtcHRfZW5hYmxlKCk7 Cit9CisKKyNkZWZpbmUgQlRSRUVfSU5JVChtYXNrKSB7IFwKKyAgICAgICAgLm9yZGVyICAgICAg ICAgID0gQlRSRUVfT1JERVIsICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKKyAgICAgICAg LnJvb3QgICAgICAgICAgID0gTlVMTCwgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg IFwKKyAgICAgICAgLnZhbHVlICAgICAgICAgID0gYnRyZWVfdmFsdWVfZm4sICAgICAgICAgICAg ICAgICAgICAgICAgIFwKKyAgICAgICAgLmtleSAgICAgICAgICAgID0gYnRyZWVfa2V5X2ZuLCAg ICAgICAgICAgICAgICAgICAgICAgICAgIFwKKyAgICAgICAgLnByaW50X2tleSAgICAgID0gYnRy ZWVfcHJpbnRfZm4sICAgICAgICAgICAgICAgICAgICAgICAgIFwKKyAgICAgICAgLmdmcF9tYXNr ICAgICAgID0gKG1hc2spICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKK30KKwor I2RlZmluZSBJTklUX0JUUkVFKGJ0cmVlLG1hc2spICAgICAgICAgICAgICAgICAgICAgICAgICAg IFwKK2RvIHsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICBcCisgICAgICAgIChidHJlZSktPm9yZGVyID0gQlRSRUVfT1JERVI7ICAgICAgICAgICAg ICAgICAgICAgXAorICAgICAgICAoYnRyZWUpLT5yb290ID0gTlVMTDsgICAgICAgICAgICAgICAg ICAgICAgICAgICAgIFwKKyAgICAgICAgKGJ0cmVlKS0+dmFsdWUgICAgICAgICAgICA9IGJ0cmVl X3ZhbHVlX2ZuOyAgICAgICBcCisgICAgICAgIChidHJlZSktPmtleSAgICAgICAgICAgICAgPSBi dHJlZV9rZXlfZm47ICAgICAgICAgXAorICAgICAgICAoYnRyZWUpLT5wcmludF9rZXkgICAgICAg ID0gYnRyZWVfcHJpbnRfZm47ICAgICAgIFwKKyAgICAgICAgKGJ0cmVlKS0+Z2ZwX21hc2sgICAg ICAgICA9IChtYXNrKTsgICAgICAgICAgICAgICBcCit9IHdoaWxlICgwKQorCisKK2V4dGVybiB2 b2lkIHByaW50X3N1YnRyZWUoYnRyZWUgKiBidHJlZSxidHJlZV9ub2RlICogbm9kZSk7CisKKyNl bmRpZgpkaWZmIC11ck4gbGludXgtMi42LjE2LjIvaW5jbHVkZS9saW51eC9mcy5oIGxpbnV4LTIu Ni4xNi4yLWJ0cmVlL2luY2x1ZGUvbGludXgvZnMuaAotLS0gbGludXgtMi42LjE2LjIvaW5jbHVk ZS9saW51eC9mcy5oCTIwMDYtMDQtMDcgMTI6NTY6NDcuMDAwMDAwMDAwIC0wNDAwCisrKyBsaW51 eC0yLjYuMTYuMi1idHJlZS9pbmNsdWRlL2xpbnV4L2ZzLmgJMjAwNi0wOC0wNSAxMDo1NzoxMi4w MDAwMDAwMDAgLTA0MDAKQEAgLTIxNCw2ICsyMTQsNyBAQAogI2luY2x1ZGUgPGxpbnV4L2tvYmpl Y3QuaD4KICNpbmNsdWRlIDxsaW51eC9saXN0Lmg+CiAjaW5jbHVkZSA8bGludXgvcmFkaXgtdHJl ZS5oPgorI2luY2x1ZGUgPGxpbnV4L2J0cmVlLmg+CiAjaW5jbHVkZSA8bGludXgvcHJpb190cmVl Lmg+CiAjaW5jbHVkZSA8bGludXgvaW5pdC5oPgogI2luY2x1ZGUgPGxpbnV4L3NjaGVkLmg+CkBA IC0zNzIsNiArMzczLDcgQEAKIHN0cnVjdCBhZGRyZXNzX3NwYWNlIHsKIAlzdHJ1Y3QgaW5vZGUJ CSpob3N0OwkJLyogb3duZXI6IGlub2RlLCBibG9ja19kZXZpY2UgKi8KIAlzdHJ1Y3QgcmFkaXhf dHJlZV9yb290CXBhZ2VfdHJlZTsJLyogcmFkaXggdHJlZSBvZiBhbGwgcGFnZXMgKi8KKyAgICAg ICAgc3RydWN0IGJ0cmVlICAgICAgICAgICAgYnRyZWU7ICAgICAgICAgIC8qIEJUcmVlIG9mIGFs bCBwYWdlcyovCiAJcndsb2NrX3QJCXRyZWVfbG9jazsJLyogYW5kIHJ3bG9jayBwcm90ZWN0aW5n IGl0ICovCiAJdW5zaWduZWQgaW50CQlpX21tYXBfd3JpdGFibGU7LyogY291bnQgVk1fU0hBUkVE IG1hcHBpbmdzICovCiAJc3RydWN0IHByaW9fdHJlZV9yb290CWlfbW1hcDsJCS8qIHRyZWUgb2Yg cHJpdmF0ZSBhbmQgc2hhcmVkIG1hcHBpbmdzICovCg== ------=_Part_33970_17874812.1154917103763-- - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/