Xen Security Advisory 206 - xenstore denial of service via repeated update
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Xen Security Advisory XSA-206
version 9
xenstore denial of service via repeated update
UPDATES IN VERSION 9
====================
More exhaustive testing discovered a further bug in the oxenstored
patches: if no transactions are performed (ie, only atomic writes), the new in-memory history record can grow without bound. This means that an attacker could be able to render oxenstored slow and eventually unuseable, and/or run dom0 out of memory. Running any transaction (even one which aborts) will clear the history, so periodically running the command
xenstore-write /xsa206-v7-leak 1 /xsa206-v7-leak 2
will mitigate the problem.
This bug is fixed in the new final patch attached to this version,
"oxenstored: trim history in the frequent_ops function"
The other patches remain unchanged.
ISSUE DESCRIPTION
=================
xenstored supports transactions, such that if writes which would invalidate assumptions of a transaction occur, the entire transaction fails. Typical response on a failed transaction is to simply retry the transaction until it succeeds.
Unprivileged domains may issue writes to xenstore which conflict with transactions either of the toolstack or of backends such as the driver domain. Depending on the exact timing, repeated writes may cause transactions made by these entities to fail indefinitely.
IMPACT
======
Unprivileged guests may be able to stall progress of the control domain or driver domain, possibly leading to a Denial of Service (DoS) of the entire host.
In most systems, the impact is limited to the delay or prevention of control operations (such as domain creation, reconfiguration, configuration enquiry, or destruction).
VULNERABLE SYSTEMS
==================
All Xen versions are vulnerable.
Both "cxenstored" (the version of xenstored written in C) and "oxenstored" (the version of xenstored written in ocaml) are vulnerable. oxenstored in Xen 4.7 and later is more difficult to exploit because it has more fine-grained detection of conflicts.
MITIGATION
==========
If the rogue domain(s) can be identified, it will usually be possible to pause them with "xl pause" and/or destroy them with "xl destroy". Note that if the toolstack is not simply "xl", the toolstack may be confused by use of "xl" to pause or destroy domains.
The output of commands such as "xl top" and "xenstore-ls -fp" may be helpful to find the rogue domain(s).
When the rogue domain(s) are paused or destroyed, the stuck operations will become unstuck.
CREDITS
=======
This issue was discovered by Jürgen Groß of SUSE.
RESOLUTION
==========
Applying the appropriate attached patches resolves this issue by limiting the rate at which it is possible to invalidate transactions.
C xenstored
- -----------
Only the first of the patches is strictly necessary to solve the issue; the second patch adds logging for when the situation occurs, so may be useful in detecting attacks or debugging issues.
ocaml xenstored
- ---------------
The oxenstored patches depend on some patches to reduce false conflicts in transactions that were introduced in Xen 4.7. The patches for 4.4-4.6 include backported versions of these patches in addition to backported versions of the ratelimiting patches.
Xen 4.4 requires some further backports in order to allow the ratelimiting patches to apply cleanly without significant reworking. These have been kept to a minimum.
Identification of patch files
- -----------------------------
The patch number ranges are:
xen-unstable, 4.8, and 4.7:
0001-0002: cxenstored
0003-0016: oxenstored ratelimiting
4.6, 4.5:
0001-0002: cxenstored
0003-0010: oxenstored avoidance of needless conflicts 0011-0024: oxenstored ratelimiting
4.4:
0001-0002: cxenstored
0003-0009: oxenstored further prerequisites 0009-0017: oxenstored avoidance of needless conflicts 0018-0031: oxenstored ratelimiting
xsa206-unstable/*.patch xen-unstable xsa206-4.8/*.patch xen-4.8 xsa206-4.7/*.patch xen-4.7 xsa206-4.6/*.patch xen-4.6 xsa206-4.5/*.patch xen-4.5 xsa206-4.4/*.patch xen-4.4
$ sha256sum xsa206*/* 9a4854117c15f1994f4398b0db24c771143766e759c23b332ddef0c65d6f6214 xsa206-unstable/0001-xenstored-apply-a-write-transaction-rate-limit.patch 6b9bce3d231fcd43b8f6a23f9da4a11a8bf9991009e89b1b1be9e22f358b3676 xsa206-unstable/0002-xenstored-Log-when-the-write-transaction-rate-limit-.patch 2e7a3e79188a2477054ccd9146a877ce4cf35679e846f279030775ba5905a825 xsa206-unstable/0003-oxenstored-comments-explaining-some-variables.patch bdde472ebbdd9e8654a8e5c5881723adefeb6cd217b2e73810cb99c7404763a1 xsa206-unstable/0004-oxenstored-handling-of-domain-conflict-credit.patch cfd1b2ef7d37666b99b5b95d317650d856af087d2588bb76b4e3c74b44e82f0c xsa206-unstable/0005-oxenstored-ignore-domains-with-no-conflict-credit.patch 8dcf3f3232116ab4611ae7016a749280ee2d4fe750de20db2bce458fbc8ff5d5 xsa206-unstable/0006-oxenstored-add-transaction-info-relevant-to-history-.patch c65c6d4e02d9e06db1667334f6006c5d9935824f927cab30852b3c8d1bdc6209 xsa206-unstable/0007-oxenstored-support-commit-history-tracking.patch 1266f764156b5f7d694c77d76457653ce8003dab155fd61db7e1a26eebc27d78 xsa206-unstable/0008-oxenstored-only-record-operations-with-side-effects-.patch 93f4b6aa2396d51e91b3c817dc582ea028d6c273732ace795c64154b9a498cf3 xsa206-unstable/0009-oxenstored-discard-old-commit-history-on-txn-end.patch 7c9472d6ffb4c1fe3d368d407bb214a0c5eec7b67d717288a6a3866af9ed67b1 xsa206-unstable/0010-oxenstored-track-commit-history.patch f8908981d25f9e3db4b764b9175e80ea7e97ed288293daaab53e7e653100a3a2 xsa206-unstable/0011-oxenstored-blame-the-connection-that-caused-a-transa.patch 558ccbc92c7a79930571edc41490f92ca25bd2f801e980c29487a4d5c336149f xsa206-unstable/0012-oxenstored-allow-self-conflicts.patch f8d5ee900c945c7a402f1e3e450824cd4c935bbd8679575cf7750f1302b8b4a1 xsa206-unstable/0013-oxenstored-do-not-commit-read-only-transactions.patch ffa38d660dcd0ba4da05740674e2fb4f252dab702cfd4a19ccd7e74d97f906aa xsa206-unstable/0014-oxenstored-don-t-wake-to-issue-no-conflict-credit.patch aa7d38f2bb373fcb96cf5c834f35687cc8781f6bbe0f34af3bd7207d411352f4 xsa206-unstable/0015-oxenstored-transaction-conflicts-improve-logging.patch 9fb5551d3b18bd3c0d7760b92b581ca9207aca6fd9ef23feeee9a279b2fcf470 xsa206-unstable/0016-oxenstored-trim-history-in-the-frequent_ops-function.patch 04658b55b68d6ad783a362e815180f2a56a5d554125dde6fae69410475e1e889 xsa206-4.4/0001-xenstored-apply-a-write-transaction-rate-limit.patch 37a0f00a195da50a68e51a801c352bb37619bd29652f257f213070eca07201bf xsa206-4.4/0002-xenstored-Log-when-the-write-transaction-rate-limit-.patch 52a3f1e9c61e648fb3c673a4c3ae93118e5e9086290a3f3ccc977424d455eaee xsa206-4.4/0003-oxenstored-exempt-dom0-from-domU-node-quotas.patch ba1f3f9f36401939c6757f53f9c91222287edcbd52275f3d428152600b7529ef xsa206-4.4/0004-oxenstored-perform-a-3-way-merge-of-the-quota-after-.patch 29afc8bf1ba4e18d64c873bac2d92482513eba8dc9c39418b97cb0a44edc4d27 xsa206-4.4/0005-oxenstored-catch-the-error-when-a-connection-is-alre.patch 79a726984b51c2a1ee0785cd2a4088c5e26cca70224130133a2f5938574f8bd3 xsa206-4.4/0006-oxenstored-use-hash-table-to-store-socket-connection.patch 203422dd170cc4d946b399e01aac90895518fa05c9ac6fdaf56dcb72f671110e xsa206-4.4/0007-oxenstored-enable-domain-connection-indexing-based-o.patch b3dcdbc7890e12b7529c9e7f912d3db62bf0a7f384f77d7b6976ec6c515d9247 xsa206-4.4/0008-oxenstored-only-process-domain-connections-that-noti.patch 5d811aa442eb871d737e6e3e338f288a7213fa70e7621a11810e9343dcb1ced1 xsa206-4.4/0009-oxenstored-add-a-safe-net-mechanism-for-existing-ill.patch 61c503e814bf8e9109598f7e9373d42f2663c0d70eda149505ba33803f9f4f16 xsa206-4.4/0010-oxenstored-refactor-putting-response-on-wire.patch f2cae0c5f1d46a8261bc4b3b5fa9080d1ab86112dcb12a78a1df0dbd3144024a xsa206-4.4/0011-oxenstored-remove-some-unused-parameters.patch 1e69cb6547bb90ea01d1cf1367318eb42543676ccaaf5dd408b3b82cc252f90a xsa206-4.4/0012-oxenstored-refactor-request-processing.patch e2ba9e2f57a9798d555245c3fd0d484816b4196f0a88faa8a27958fb552405c3 xsa206-4.4/0013-oxenstored-keep-track-of-each-transaction-s-operatio.patch 3d54ae0faf7e2b1f8090bfdafe2a09294fcc1a310e5949b055827628bc6a235c xsa206-4.4/0014-oxenstored-move-functions-that-process-simple-operat.patch 8303b1116f81763b95473381d8ab3743761f10bdcb8b9e39e0b93dcaaa6768c8 xsa206-4.4/0015-oxenstored-replay-transaction-upon-conflict.patch 5cd63211b371a4e4a8067839fd114f51b0afc62a805ef22e4c13893d95bb0dc8 xsa206-4.4/0016-oxenstored-log-request-and-response-during-transacti.patch c42a8395cfe5d9f417776de7517d27db4e46c3f9c3b9f56ef3fb465949f63c08 xsa206-4.4/0017-oxenstored-allow-compilation-prior-to-OCaml-3.12.0.patch dd9e70e7e924f568e7d7807e2edc992c4dac1986b2b9b91226d5ac70ff028c6f xsa206-4.4/0018-oxenstored-comments-explaining-some-variables.patch ba2f035815b44bc8f4c4831bf1aa602ec553800aa3693fc0ca69878764c912e1 xsa206-4.4/0019-oxenstored-handling-of-domain-conflict-credit.patch c693d3d28136a030d033b9a2017ec0a3f7a580da909034d3ac4c4188cb4cc540 xsa206-4.4/0020-oxenstored-ignore-domains-with-no-conflict-credit.patch 471e1904a453f03fee09d78f2d9ca25790e2619327b232566a06fd4f35ed3066 xsa206-4.4/0021-oxenstored-add-transaction-info-relevant-to-history-.patch 59756b7edacea62f0e283a16fd68a43cbc639ee32ac00b9519f2183d4cdfa7bc xsa206-4.4/0022-oxenstored-support-commit-history-tracking.patch 35916183640b29a474ed87c56c784cc28716ce896471bc8ae9363b48af5fcaa4 xsa206-4.4/0023-oxenstored-only-record-operations-with-side-effects-.patch 98d17240fe7c2dc4380e9e8991abbe1f1fdfbe1cc676e52fa96fcf567d5502a6 xsa206-4.4/0024-oxenstored-discard-old-commit-history-on-txn-end.patch 6e9f0c33b555e1f69ef236e63f495a920b84022ed48ee50b1bb53f96216d3fb8 xsa206-4.4/0025-oxenstored-track-commit-history.patch 742d69846211969de623bf4c6106d09b761e6d261b138b63677fc401d2c5f3f3 xsa206-4.4/0026-oxenstored-blame-the-connection-that-caused-a-transa.patch ede1c388e6aed671a5a6648b94ef5caf3cc6093b9c010d56ac25a61ba657557e xsa206-4.4/0027-oxenstored-allow-self-conflicts.patch 8c0caf3c9458afb5620130c9abca6913a9e82270e7e2bebaa156a19dc72c2119 xsa206-4.4/0028-oxenstored-do-not-commit-read-only-transactions.patch ac3611d7d358a71f0d5295e6d3d72502aeda61222a48cfa8bf1dbcd4def80f6e xsa206-4.4/0029-oxenstored-don-t-wake-to-issue-no-conflict-credit.patch 036eb78cfe0e724e9f3082cbacec0401a1893665490aae6423bbe8ad85a07977 xsa206-4.4/0030-oxenstored-transaction-conflicts-improve-logging.patch fdbaaaceade568047ceccf516c9126c40a977b45fa4a4d6491ba93acb760ad0b xsa206-4.4/0031-oxenstored-trim-history-in-the-frequent_ops-function.patch 3317d5492e053a67ee795e414907b24c7a7963b12b66fc7a3575b202ba072bd6 xsa206-4.5/0001-xenstored-apply-a-write-transaction-rate-limit.patch 160d0be576fbde34a1c325d7101028bf5818496ab7b03543ec9a04ffd21a0276 xsa206-4.5/0002-xenstored-Log-when-the-write-transaction-rate-limit-.patch f6198807f1ca21681fc90c95be6a0e90d38d0ab5d926e89cecbfc59cbde119a8 xsa206-4.5/0003-oxenstored-refactor-putting-response-on-wire.patch de6e1a7232b7f8e553978021a7d14714b1fa8ce9ce79d93d0ae6350bdf79462d xsa206-4.5/0004-oxenstored-remove-some-unused-parameters.patch de2dac3b07917294eb49918e3bbc14469c94d4db52652484ff571abb13d5deb0 xsa206-4.5/0005-oxenstored-refactor-request-processing.patch 2388e08c59013b9f999727173f01d1ea235cb5e6e345361766de7cc25f77064f xsa206-4.5/0006-oxenstored-keep-track-of-each-transaction-s-operatio.patch 9230cd86aabf980c8bda424675139085782baed9a1b07d212013cea4761f852b xsa206-4.5/0007-oxenstored-move-functions-that-process-simple-operat.patch 9f8f26afa776fc36a1b823f0dc9130397047074bb6c354cace4fecd302fb7376 xsa206-4.5/0008-oxenstored-replay-transaction-upon-conflict.patch a0656e0864562467cb02b89159a5d4514ae3a1b6f30f2f31938667b91640443b xsa206-4.5/0009-oxenstored-log-request-and-response-during-transacti.patch ed7e623a556e4505eff5080e71476070338c903e4d8b6312fff320d6d376c5a8 xsa206-4.5/0010-oxenstored-allow-compilation-prior-to-OCaml-3.12.0.patch a80e40456249f15555870f0a4f67555f31aab90199b3b1989508c4f42feec6b1 xsa206-4.5/0011-oxenstored-comments-explaining-some-variables.patch f5b9e650a4c484ce336525dfa43612f76c52f1f0e951360f872e69ca9c1a6773 xsa206-4.5/0012-oxenstored-handling-of-domain-conflict-credit.patch 12c44371d379eeeee37325e1d7116e9d95a236c30197fd6252e1b4cbeda56c57 xsa206-4.5/0013-oxenstored-ignore-domains-with-no-conflict-credit.patch a126b22908280ecb0a561f19e2781538333c236da74f23600cf1899f32fc2532 xsa206-4.5/0014-oxenstored-add-transaction-info-relevant-to-history-.patch 899d01c7b211851e31262fab59d8285a5c078d551b61ef94720c81a95f114b24 xsa206-4.5/0015-oxenstored-support-commit-history-tracking.patch 1b828006bc62094de570e8880ae19a66517c02938bab49130e5751b9eebb2bce xsa206-4.5/0016-oxenstored-only-record-operations-with-side-effects-.patch fe2d3a01b0e322fe7a9f7e50bf21d43b9d4ee6e663c76af745b6668a50903eba xsa206-4.5/0017-oxenstored-discard-old-commit-history-on-txn-end.patch fdef41093921d22a2be1bf80f92df4c2feb728f4e1feab4a587c528d7df68a0f xsa206-4.5/0018-oxenstored-track-commit-history.patch 868d06a41a054df7b875587ccc574d6a6df833882d1a52260fb171637e1e1aa9 xsa206-4.5/0019-oxenstored-blame-the-connection-that-caused-a-transa.patch f20d7ffe6bae21b0c2b90b675fdcd5d6e37bf88bd52a27dfc31f00d087fcccbe xsa206-4.5/0020-oxenstored-allow-self-conflicts.patch b496ce132ad8742e7e3060812b5dd7ab073d8e2655a7da9504460f64f90d4938 xsa206-4.5/0021-oxenstored-do-not-commit-read-only-transactions.patch 0b6efaa1985ad52eca341f368ebaaf5d8991bcad61a31e04ea2323ab84b664d2 xsa206-4.5/0022-oxenstored-don-t-wake-to-issue-no-conflict-credit.patch 100b7ba3a8f28fb730f050368b0ebb339713d9efac5b531e46953c07bc3a6d82 xsa206-4.5/0023-oxenstored-transaction-conflicts-improve-logging.patch 8a4c175ccecf97a1e5bad361ea4190f7575df90e5ff850f7ee533e81832d85e4 xsa206-4.5/0024-oxenstored-trim-history-in-the-frequent_ops-function.patch d331d26f4a7ab85a410697f533a5cbd379c712e403b3b81dbfde6d7da6ffbfec xsa206-4.6/0001-xenstored-apply-a-write-transaction-rate-limit.patch 4d366ad26daeb65e9f5f0587401401c66bc9bcf8c559e6f7b055b37b837c50b2 xsa206-4.6/0002-xenstored-Log-when-the-write-transaction-rate-limit-.patch ea645aeeb9b535314a4e8983514768105daa43ae051b95766aa6850ed62b8d75 xsa206-4.6/0003-oxenstored-refactor-putting-response-on-wire.patch 5a24b811e7e8e5305c87b276151ee50f1b5d9de4f5d0229eb31ff65b5db4db99 xsa206-4.6/0004-oxenstored-remove-some-unused-parameters.patch 4f51c38419a2c4c29ecbc05b418ba4f336b020fef9c7958f0a8820efd0c16967 xsa206-4.6/0005-oxenstored-refactor-request-processing.patch bd7c50391cd4cdd6907d8d8e219f86fd39ab724e8e2ae7d8cbefbb58b6f9aa38 xsa206-4.6/0006-oxenstored-keep-track-of-each-transaction-s-operatio.patch c429c207476e1fee3ed10d72ec50a101724dbcc3b207736461e65d3a34d03750 xsa206-4.6/0007-oxenstored-move-functions-that-process-simple-operat.patch 594cf57750f6593c018834d4e8f115c84e63df0597397861fa651d5903a9e9ae xsa206-4.6/0008-oxenstored-replay-transaction-upon-conflict.patch 5ae3c81c26377d32702a5783541cafe177923a000ec01b5a1525cc8a5d34890f xsa206-4.6/0009-oxenstored-log-request-and-response-during-transacti.patch 04cde40696cd93522a739946709122aab4e31da493fc28f8a905b082c1897640 xsa206-4.6/0010-oxenstored-allow-compilation-prior-to-OCaml-3.12.0.patch f11b549b9d9070e08fd84ccdd1ab0339a38798ae0354d97171cc5ade3ee7c2de xsa206-4.6/0011-oxenstored-comments-explaining-some-variables.patch b79b36bea4cb3b5b549e6ae3be6bec45a54615cc58cb0337a8539dd5d1a613eb xsa206-4.6/0012-oxenstored-handling-of-domain-conflict-credit.patch eb8dd4a24f51ee1ec9a2a2b06de12826633236f2c1f12845b72fca7d798519b0 xsa206-4.6/0013-oxenstored-ignore-domains-with-no-conflict-credit.patch bdf0ecbf22734e76389153dc7794bb16bc577053c7a7815f7f9c86e69385f0b9 xsa206-4.6/0014-oxenstored-add-transaction-info-relevant-to-history-.patch 8d4bf5be08ca9a27d1a0cab8a7d4eacf79ed427a877f6a79d4309f0bcfec0e3c xsa206-4.6/0015-oxenstored-support-commit-history-tracking.patch 0bcf04291afea26b916314b93e1c32b75cd3ac176f0f50b6697745940aa3194e xsa206-4.6/0016-oxenstored-only-record-operations-with-side-effects-.patch 53d707bc2d933faabf2dcf469d256b01ea8c696a6aea3d98fe3fc3a86f6da5fe xsa206-4.6/0017-oxenstored-discard-old-commit-history-on-txn-end.patch e297f3de87216b25d9329fc8946ad409827ce99bea0a2b8debeff485168adad8 xsa206-4.6/0018-oxenstored-track-commit-history.patch 6ad756977f2dcdee219d04f287d5b165391f8d949103420fdf0d5085aafae507 xsa206-4.6/0019-oxenstored-blame-the-connection-that-caused-a-transa.patch f3769eb343896c5119f507bf699bb6e595a4e59d50095fbded17cb66be7336c1 xsa206-4.6/0020-oxenstored-allow-self-conflicts.patch 2d040a7500cb272f225dab53eb82d4b3b82609b8128f9fba180e71b97b5d1fe4 xsa206-4.6/0021-oxenstored-do-not-commit-read-only-transactions.patch ea28e29a2f06423d849888ec97ee369fa5ddd2b15abdfe2588e20e3d03455b0d xsa206-4.6/0022-oxenstored-don-t-wake-to-issue-no-conflict-credit.patch 9a7994d86fc49ac5ebcec63fcf6dae9501e84559adc8a650a2a0f125e251cc01 xsa206-4.6/0023-oxenstored-transaction-conflicts-improve-logging.patch 8a4c175ccecf97a1e5bad361ea4190f7575df90e5ff850f7ee533e81832d85e4 xsa206-4.6/0024-oxenstored-trim-history-in-the-frequent_ops-function.patch 66023f442b3d9c2f03565312b8b7df67f5e60873dfc3d3cae9f1f5e48be240bf xsa206-4.7/0001-xenstored-apply-a-write-transaction-rate-limit.patch 886da41986b3789c4d469a7a317671cfcfd63fe779436a4d966d0b8268ba5ea7 xsa206-4.7/0002-xenstored-Log-when-the-write-transaction-rate-limit-.patch f90e94dde95a519661bc49a106b0431408cefb6d6838e65238fbb5be63a96390 xsa206-4.7/0003-oxenstored-comments-explaining-some-variables.patch 2d645680487ff2d1e632ee1e42d1db9b4d2a5c60c65d115d48dc81cfbdcea923 xsa206-4.7/0004-oxenstored-handling-of-domain-conflict-credit.patch b16cc0ee957f10b704c31b93e1a27183c55df1aa8d573985407189335eb5259e xsa206-4.7/0005-oxenstored-ignore-domains-with-no-conflict-credit.patch 82dad324ef34455beccecb3ff3bf306cd2975a0a631d31653d33ace3e82ab768 xsa206-4.7/0006-oxenstored-add-transaction-info-relevant-to-history-.patch a16a3cddbe02979e11079735a50e8f0aad027788834ca098ef44af10b448209e xsa206-4.7/0007-oxenstored-support-commit-history-tracking.patch e306f8b860965c671bd09f10b7a6b2aa02d141a9cf0d19e8604fd61e0bc4676f xsa206-4.7/0008-oxenstored-only-record-operations-with-side-effects-.patch 3cb0ffe7f5a3461799add9ad06e199bd485345c9319c02ff3dcc5c645118c8d6 xsa206-4.7/0009-oxenstored-discard-old-commit-history-on-txn-end.patch 2349825d20e5cd4546c0ea40a3b47567d65e1e1136e3dd0b8b53252833735dc6 xsa206-4.7/0010-oxenstored-track-commit-history.patch 364297e468989f266e6690661aadd1ce69d52046a0cd6f823b8a5677a5b6b55d xsa206-4.7/0011-oxenstored-blame-the-connection-that-caused-a-transa.patch dfc134667b142541e3cd2d938332ab1aefae358f7f18ddf2a481da3810246065 xsa206-4.7/0012-oxenstored-allow-self-conflicts.patch edcf3c4c5c0b7a48b5467a7a5287f750cbdd71456d2ec94fecd3bac71b618060 xsa206-4.7/0013-oxenstored-do-not-commit-read-only-transactions.patch 9d683f41138926cc2273765b7e887abf1ba80f75de3065b70c99444d6bb1ec67 xsa206-4.7/0014-oxenstored-don-t-wake-to-issue-no-conflict-credit.patch 341bb09db621d45514f4acdb4cd7c2f51d58d75eedcd44dcddc0e56728b762ba xsa206-4.7/0015-oxenstored-transaction-conflicts-improve-logging.patch 9fb5551d3b18bd3c0d7760b92b581ca9207aca6fd9ef23feeee9a279b2fcf470 xsa206-4.7/0016-oxenstored-trim-history-in-the-frequent_ops-function.patch 4892ae70f81f9e32b1c3c6cae19870387ab0efde2e7ac98e87e8a06e6a4f3cf0 xsa206-4.8/0001-xenstored-apply-a-write-transaction-rate-limit.patch f5c61dffb1f500bdc05b9561a960d803b9a5ad47544eca46ca06e4eff731609c xsa206-4.8/0002-xenstored-Log-when-the-write-transaction-rate-limit-.patch 2224c440995033ea650658874a131dd440708635fc6c463184d742f94248d537 xsa206-4.8/0003-oxenstored-comments-explaining-some-variables.patch f5dd1be2f693e9bf84b0c2ac06c11784f972aa211c5e44b9b60fbad8f7a67a31 xsa206-4.8/0004-oxenstored-handling-of-domain-conflict-credit.patch 3a7b2cc69bb42e027e6ec33c5f47eb9ecddcb66dafec3dab8b59088959829298 xsa206-4.8/0005-oxenstored-ignore-domains-with-no-conflict-credit.patch 642feeb68393378feb6d4ce7ead8408120002382e0cf5655c24165f976f3e762 xsa206-4.8/0006-oxenstored-add-transaction-info-relevant-to-history-.patch 0b790e361f8b1ecb3381240789808cbdbc4b24ad39af7673f4c4b2ac340e9522 xsa206-4.8/0007-oxenstored-support-commit-history-tracking.patch 052ae69b9ff689e56d79a6a7fea5bdc7e3d31960fce125c1465e1d005e0120f6 xsa206-4.8/0008-oxenstored-only-record-operations-with-side-effects-.patch fbc0d1e68d6caaefc629439ffb9a7eeb95e6118289679be13012d850b97b00c1 xsa206-4.8/0009-oxenstored-discard-old-commit-history-on-txn-end.patch 78c75dde183e0ca5008e6593e9df9001b1f1ff46e841bb8b2c8da4a211f7bda5 xsa206-4.8/0010-oxenstored-track-commit-history.patch 9ed684c344e8fcf5e2a6836106c0c77be7b5ae947c1928b5c83473bce75db3fa xsa206-4.8/0011-oxenstored-blame-the-connection-that-caused-a-transa.patch bb7f93df3bdaf6571ddef1e8ebcae3e331b4a84c43b474adaf59192c32b6eed6 xsa206-4.8/0012-oxenstored-allow-self-conflicts.patch 23fc369224df75157e402505bb5631f8500e3d3b21e310b8c6a61833bab27db8 xsa206-4.8/0013-oxenstored-do-not-commit-read-only-transactions.patch c96bc121a68910e59ca6b4abfdc2f3653d45decfbb9063544a5e6ac4191352d5 xsa206-4.8/0014-oxenstored-don-t-wake-to-issue-no-conflict-credit.patch 873db68b4e26c0ac08e400bfea4e7908db95184dcc24b98e7003f04091814f62 xsa206-4.8/0015-oxenstored-transaction-conflicts-improve-logging.patch 9fb5551d3b18bd3c0d7760b92b581ca9207aca6fd9ef23feeee9a279b2fcf470 xsa206-4.8/0016-oxenstored-trim-history-in-the-frequent_ops-function.patch $
DEPLOYMENT DURING EMBARGO
=========================
Deployment of the patches and/or mitigations described above (or others which are substantially similar) is permitted during the embargo, even on public-facing systems with untrusted guest users and administrators.
But: Distribution of updated software is prohibited (except to other members of the predisclosure list).
Predisclosure list members who wish to deploy significantly different patches and/or mitigations, please contact the Xen Project Security Team.
(Note: this during-embargo deployment notice is retained in post-embargo publicly released Xen Project advisories, even though it is then no longer applicable. This is to enable the community to have oversight of the Xen Project Security Team's decisionmaking.)
For more information about permissible uses of embargoed information, consult the Xen Project community's agreed Security Policy:
http://www.xenproject.org/security-policy.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iQEcBAEBAgAGBQJY281CAAoJEIP+FMlX6CvZiQQH/1ceRJjfX0/5Ni850AGbDm1L cm9rkBIaXsUClO2rcLU6M05tzyiRm3nuEe/HccX8L0M9gw5DdUKIgFl4ojYhubwj VWByc9niB7Fz4r26xc+ekajV7XbPjQl911ClQvgpmxF3Fnk+p65sRsCya0A9SFaj d87yC5fmBdyXea/3qA41r8x/2r7vZUCpBOpjWjb42Eub76474d/nWYhHDA7iqXsG nHGJk7Ea8Crcj0t6wK78Unba/JwfBwfOn24ajuU/0lqfwWW09SK+iOVTM7t6e7DJ Z0A5OLDXT9YNaJ5vKhZ+Xk3Ta689/IO66sGoUGZ3d86/lITf/37/Zf8cXsApz3Q= =xWsj
-----END PGP SIGNATURE-----
From 3afb825a7c0252655fe3cd702a58a23602a96a33 Mon Sep 17 00:00:00 2001
From: Ian Jackson <[email protected]>
Date: Tue, 7 Mar 2017 16:09:12 +0000
Subject: [PATCH 01/15] xenstored: apply a write transaction rate limit
This avoids a rogue client being about to stall another client (eg the toolstack) indefinitely.
This is XSA-206.
--- tools/xenstore/Makefile | 3 +- tools/xenstore/xenstored_core.c | 9 +- tools/xenstore/xenstored_core.h | 6 + tools/xenstore/xenstored_domain.c | 215 +++++++++++++++++++++++++++++++++ tools/xenstore/xenstored_domain.h | 25 ++++ tools/xenstore/xenstored_transaction.c | 5 + 6 files changed, 261 insertions(+), 2 deletions(-)
tools/xenstore/Makefile +2 -1
@@ -34,6 +34,7 @@ XENSTORED_OBJS_$(CONFIG_FreeBSD) = xenstored_posix.o XENSTORED_OBJS_$(CONFIG_MiniOS) = xenstored_minios.o XENSTORED_OBJS += $(XENSTORED_OBJS_y) +LDLIBS_xenstored += -lrt ifneq ($(XENSTORE_STATIC_CLIENTS),y) LIBXENSTORE := libxenstore.so
@@ -75,7 +76,7 @@ endif $(XENSTORED_OBJS): CFLAGS += $(CFLAGS_libxengnttab) xenstored: $(XENSTORED_OBJS) - $(CC) $^ $(LDFLAGS) $(LDLIBS_libxenevtchn) $(LDLIBS_libxengnttab) $(LDLIBS_libxenctrl) $(SOCKET_LIBS) -o $@ $(APPEND_LDFLAGS) + $(CC) $^ $(LDFLAGS) $(LDLIBS_libxenevtchn) $(LDLIBS_libxengnttab) $(LDLIBS_libxenctrl) $(LDLIBS_xenstored) $(SOCKET_LIBS) -o $@ $(APPEND_LDFLAGS) xenstored.a: $(XENSTORED_OBJS) $(AR) cr $@ $^
tools/xenstore/xenstored_core.c +8 -1
@@ -336,6 +336,7 @@ static void initialize_fds(int sock, int *p_sock_pollfd_idx, int *ptimeout) {struct connection *conn; +struct wrl_timestampt now;if (fds)memset (fds,0 ,sizeof (struct pollfd ) * current_array_size);
@@ -355,8 +356,11 @@ static void initialize_fds(int sock, int *p_sock_pollfd_idx, xce_pollfd_idx =set_fd (xenevtchn_fd (xce_handle),POLLIN |POLLPRI ); +wrl_gettime_now (&now); +list_for_each_entry (conn, &connections, list) {if (conn->domain) { +wrl_check_timeout (conn->domain, now, ptimeout);if (domain_can_read (conn) || (domain_can_write (conn) && !list_empty (&conn->out_list)))
@@ -450,6 +454,7 @@ static bool write_node(struct connection *conn, struct node *node) goto error;add_change_node (conn, node, false); +wrl_apply_debit_direct (conn); data.dptr =talloc_size (node, data.dsize); hdr = (void *)data.dptr;
@@ -907,8 +912,10 @@ static void delete_node_single(struct connection *conn, struct node *node,return ; } -if (changed) +if (changed) {add_change_node (conn, node, true); +wrl_apply_debit_direct (conn); + }domain_entry_dec (conn, node); }
tools/xenstore/xenstored_core.h +6 -0
@@ -36,6 +36,12 @@/* DEFAULT_BUFFER_SIZE should be large enough for each errno string. */ #define DEFAULT_BUFFER_SIZE 16 +#define MIN (a, b) (((a) < (b))? (a) : (b)) + +typedef int32_t wrl_creditt ; +#define WRL_CREDIT_MAX (1000*1000*1000) +/* ^ satisfies non-overflow condition for wrl_xfer_credit */ +struct buffered_data {struct list_head list;
tools/xenstore/xenstored_domain.c +215 -0
251 lines not on this page · raw message
tools/xenstore/xenstored_domain.h +25 -0
@@ -65,4 +65,29 @@ void domain_watch_inc(struct connection *conn);void domain_watch_dec (struct connection *conn);int domain_watch (struct connection *conn); +/* Write rate limiting */ + +#define WRL_FACTOR 1000/* for fixed-point arithmetic */ +#define WRL_RATE 200 +#define WRL_DBURST 10 +#define WRL_GBURST 1000 +#define WRL_NEWDOMS 5 + +struct wrl_timestampt { +time_t sec; +int msec; +}; + +extern long wrl_ntransactions; + +void wrl_gettime_now (struct wrl_timestampt *now_ts); +void wrl_domain_new (struct domain *domain); +void wrl_domain_destroy (struct domain *domain); +void wrl_credit_update (struct domain *domain,struct wrl_timestampt now); +void wrl_check_timeout (struct domain *domain, +struct wrl_timestampt now, +int *ptimeout); +void wrl_apply_debit_direct (struct connection *conn); +void wrl_apply_debit_trans_commit (struct connection *conn); +#endif /* _XENSTORED_DOMAIN_H */
tools/xenstore/xenstored_transaction.c +5 -0
@@ -139,6 +139,7 @@ static int destroy_transaction(void *_transaction) {struct transaction *trans = _transaction; + wrl_ntransactions--;trace_destroy (trans,"transaction" );if (trans->tdb)tdb_close (trans->tdb);
@@ -201,6 +202,7 @@ int do_transaction_start(struct connection *conn, struct buffered_data *in)talloc_steal (conn, trans);talloc_set_destructor (trans, destroy_transaction); conn->transaction_started++; + wrl_ntransactions++;snprintf (id_str,sizeof (id_str),"%u" , trans->id);send_reply (conn,XS_TRANSACTION_START , id_str,strlen (id_str)+1 );
@@ -232,6 +234,9 @@ int do_transaction_end(struct connection *conn, struct buffered_data *in)/* FIXME: Merge, rather failing on any change. */ if (trans->generation != generation)return EAGAIN ; + +wrl_apply_debit_trans_commit (conn); +if (!replace_tdb (trans->tdb_name, trans->tdb))return errno;/* Don't close this: we won! */
Signature · 1 line
2.1.4
From 2a3dffb4da4982f35bcc6b7394e88825e08d9b34 Mon Sep 17 00:00:00 2001
From: Ian Jackson <[email protected]>
Date: Tue, 7 Mar 2017 16:09:13 +0000
Subject: [PATCH 02/15] xenstored: Log when the write transaction rate limit
bites
--- tools/xenstore/xenstored_core.c | 1 + tools/xenstore/xenstored_domain.c | 25 +++++++++++++++++++++++++ tools/xenstore/xenstored_domain.h | 2 ++ 3 files changed, 28 insertions(+)
tools/xenstore/xenstored_core.c +1 -0
@@ -357,6 +357,7 @@ static void initialize_fds(int sock, int *p_sock_pollfd_idx, POLLIN|POLLPRI);wrl_gettime_now (&now); +wrl_log_periodic (now);list_for_each_entry (conn, &connections, list) {if (conn->domain) {
tools/xenstore/xenstored_domain.c +25 -0
@@ -22,6 +22,7 @@#include <stdlib.h> #include <stdarg.h> #include <time.h> +#include <syslog.h> #include "utils.h" #include "talloc.h"
@@ -79,6 +80,7 @@ struct domain/* write rate limit */ wrl_creditt wrl_credit;/* [ -wrl_config_writecost, +_dburst ] */ struct wrl_timestampt wrl_timestamp; +bool wrl_delay_logged; };static LIST_HEAD (domains);
@@ -746,6 +748,7 @@ long wrl_ntransactions;static long wrl_ndomains;static wrl_creditt wrl_reserve;/* [-wrl_config_newdoms_dburst, +_gburst ] */ +static time_t wrl_log_last_warning;/* 0: no previous warning */ void wrl_gettime_now (struct wrl_timestampt *now_wt) {
@@ -895,6 +898,9 @@ void wrl_check_timeout(struct domain *domain, wakeup); } +#define WRL_LOG (now, ...) \ + (syslog(LOG_WARNING, "write rate limit: " __VA_ARGS__)) +void wrl_apply_debit_actual (struct domain *domain) {struct wrl_timestampt now;
@@ -910,6 +916,25 @@ void wrl_apply_debit_actual(struct domain *domain)trace ("wrl: domain %u credit=%ld (reserve=%ld)\n" , domain->domid, (long )domain->wrl_credit, (long )wrl_reserve); + +if (domain->wrl_credit <0 ) { +if (!domain->wrl_delay_logged++) { +WRL_LOG (now,"domain %ld is affected" , + (long )domain->domid); + }else if (!wrl_log_last_warning) { +WRL_LOG (now,"rate limiting restarts" ); + } + wrl_log_last_warning = now.sec; + } +} + +void wrl_log_periodic (struct wrl_timestampt now) +{ +if (wrl_log_last_warning && + (now.sec - wrl_log_last_warning) >WRL_LOGEVERY ) { +WRL_LOG (now,"not in force recently" ); + wrl_log_last_warning =0 ; + } }void wrl_apply_debit_direct (struct connection *conn)
tools/xenstore/xenstored_domain.h +2 -0
@@ -72,6 +72,7 @@ int domain_watch(struct connection *conn);#define WRL_DBURST 10#define WRL_GBURST 1000#define WRL_NEWDOMS 5 +#define WRL_LOGEVERY 120/* seconds */ struct wrl_timestampt {time_t sec;
@@ -87,6 +88,7 @@ void wrl_credit_update(struct domain *domain, struct wrl_timestampt now);void wrl_check_timeout (struct domain *domain,struct wrl_timestampt now,int *ptimeout); +void wrl_log_periodic (struct wrl_timestampt now);void wrl_apply_debit_direct (struct connection *conn);void wrl_apply_debit_trans_commit (struct connection *conn);
Signature · 1 line
2.1.4
From e859446454253c4964613818663ff4998766fb1c Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Tue, 14 Mar 2017 12:15:52 +0000
Subject: [PATCH 03/15] oxenstored: comments explaining some variables
It took a while of reading and reasoning to work out what these are for, so here are comments to make life easier for everyone reading this code in future.
--- tools/ocaml/xenstored/store.ml | 1 + tools/ocaml/xenstored/transaction.ml | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-)
tools/ocaml/xenstored/store.ml +1 -0
@@ -211,6 +211,7 @@ let apply rnode path fct = lookup rnode path fct end +(* The Store.t type *) type t = { mutable stat_transaction_coalesce: int;
tools/ocaml/xenstored/transaction.ml +7 -3
@@ -69,11 +69,15 @@ let can_coalesce oldroot currentroot path = else false -type ty = No | Full of (int * Store.Node.t * Store.t) +type ty = No | Full of ( + int * (* Transaction id *) + Store.Node.t * (* Original root *) + Store.t (* A pointer to the canonical store: its root changes on each transaction-commit *) +) type t = { ty: ty; - store: Store.t; + store: Store.t; (* This is the store that we change in write operations. *) quota: Quota.t; mutable paths: (Xenbus.Xb.Op.operation * Store.Path.t) list; mutable operations: (Packet.request * Packet.response) list;
@@ -155,7 +159,7 @@ let commit ~con t = let has_commited = match t.ty with | No -> true - | Full (id, oldroot, cstore) -> + | Full (id, oldroot, cstore) -> (* "cstore" meaning current canonical store *) let commit_partial oldroot cstore store = (* get the lowest path of the query and verify that it hasn't been modified by others transactions. *)
Signature · 1 line
2.1.4
From 8e7bd265eed25a5fe0cf7fba73fba4f4aaebe57e Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Tue, 14 Mar 2017 12:15:52 +0000
Subject: [PATCH 04/15] oxenstored: handling of domain conflict-credit
This commit gives each domain a conflict-credit variable, which will later be used for limiting how often a domain can cause other domain's transaction-commits to fail.
This commit also provides functions and data for manipulating domains and their conflict-credit, and checking whether they have credit.
--- tools/ocaml/xenstored/connection.ml | 5 ++ tools/ocaml/xenstored/define.ml | 3 + tools/ocaml/xenstored/domain.ml | 11 +++- tools/ocaml/xenstored/domains.ml | 103 ++++++++++++++++++++++++++++++- tools/ocaml/xenstored/oxenstored.conf.in | 32 ++++++++++ tools/ocaml/xenstored/transaction.ml | 2 + tools/ocaml/xenstored/xenstored.ml | 2 + 7 files changed, 154 insertions(+), 4 deletions(-)
tools/ocaml/xenstored/connection.ml +5 -0
@@ -293,3 +293,8 @@ let debug con = let domid = get_domstr con in let watches = List.map (fun (path, token) -> Printf.sprintf "watch %s: %s %s\n" domid path token) (list_watches con) in String.concat "" watches + +let decr_conflict_credit doms con = + match con.dom with + | None -> () (* It's a socket connection. We don't know which domain we're in, so treat it as if it's free to conflict *) + | Some dom -> Domains.decr_conflict_credit doms dom
tools/ocaml/xenstored/define.ml +3 -0
@@ -29,6 +29,9 @@ let maxwatch = ref (50) let maxtransaction = ref (20) let maxrequests = ref (-1) (* maximum requests per transaction *) +let conflict_burst_limit = ref 5.0 +let conflict_rate_limit_is_aggregate = ref true + let domid_self = 0x7FF0 exception Not_a_directory of string
tools/ocaml/xenstored/domain.ml +9 -2
@@ -31,8 +31,12 @@ type t = mutable io_credit: int; (* the rounds of ring process left to do, default is 0, usually set to 1 when there is work detected, could also set to n to give "lazy" clients extra credit *) + mutable conflict_credit: float; (* Must be positive to perform writes; a commit + that later causes conflict with another + domain's transaction costs credit. *) } +let is_dom0 d = d.id = 0 let get_path dom = "/local/domain/" ^ (sprintf "%u" dom.id) let get_id domain = domain.id let get_interface d = d.interface
@@ -48,6 +52,10 @@ let set_io_credit ?(n=1) domain = domain.io_credit <- max 0 n let incr_io_credit domain = domain.io_credit <- domain.io_credit + 1 let decr_io_credit domain = domain.io_credit <- max 0 (domain.io_credit - 1) +let is_paused_for_conflict dom = dom.conflict_credit <= 0.0 + +let is_free_to_conflict = is_dom0 + let string_of_port = function | None -> "None" | Some x -> string_of_int (Xeneventchn.to_int x)
@@ -84,6 +92,5 @@ let make id mfn remote_port interface eventchn = { port = None; bad_client = false; io_credit = 0; + conflict_credit = !Define.conflict_burst_limit; } - -let is_dom0 d = d.id = 0
tools/ocaml/xenstored/domains.ml +101 -2
130 lines not on this page · raw message
tools/ocaml/xenstored/oxenstored.conf.in +32 -0
@@ -9,6 +9,38 @@ test-eagain = false # Activate transaction merge support merge-activate = true +# Limits applied to domains whose writes cause other domains' transaction +# commits to fail. Must include decimal point. + +# The burst limit is the number of conflicts a domain can cause to +# fail in a short period; this value is used for both the initial and +# the maximum value of each domain's conflict-credit, which falls by +# one point for each conflict caused, and when it reaches zero the +# domain's requests are ignored. +conflict-burst-limit = 5.0 + +# The conflict-credit is replenished over time: +# one point is issued after each conflict-max-history-seconds, so this +# is the minimum pause-time during which a domain will be ignored. +# conflict-max-history-seconds = 0.05 + +# If the conflict-rate-limit-is-aggregate flag is true then after each +# tick one point of conflict-credit is given to just one domain: the +# one at the front of the queue. If false, then after each tick each +# domain gets a point of conflict-credit. +# +# In environments where it is known that every transaction will +# involve a set of nodes that is writable by at most one other domain, +# then it is safe to set this aggregate-limit flag to false for better +# performance. (This can be determined by considering the layout of +# the xenstore tree and permissions, together with the content of the +# transactions that require protection.) +# +# A transaction which involves a set of nodes which can be modified by +# multiple other domains can suffer conflicts caused by any of those +# domains, so the flag must be set to true. +conflict-rate-limit-is-aggregate = true + # Activate node permission system perms-activate = true
tools/ocaml/xenstored/transaction.ml +2 -0
@@ -14,6 +14,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. *) +let error fmt = Logging.error "transaction" fmt + open Stdext let none = 0
tools/ocaml/xenstored/xenstored.ml +2 -0
@@ -89,6 +89,8 @@ let parse_config filename = let pidfile = ref default_pidfile in let options = [ ("merge-activate", Config.Set_bool Transaction.do_coalesce); + ("conflict-burst-limit", Config.Set_float Define.conflict_burst_limit); + ("conflict-rate-limit-is-aggregate", Config.Set_bool Define.conflict_rate_limit_is_aggregate); ("perms-activate", Config.Set_bool Perms.activate); ("quota-activate", Config.Set_bool Quota.activate); ("quota-maxwatch", Config.Set_int Define.maxwatch);
Signature · 1 line
2.1.4
From 310a9b4d6afe59c8f62c89f2f85ccc5b3a8c35aa Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Tue, 14 Mar 2017 12:15:52 +0000
Subject: [PATCH 05/15] oxenstored: ignore domains with no conflict-credit
When processing connections, skip those from domains with no remaining conflict-credit.
Also, issue a point of conflict-credit at regular intervals, the period being set by the configuration option "conflict-max-history- seconds". When issuing conflict-credit, we give a point either to every domain at once (one each) or only to the single domain at the front of the queue, depending on the configuration option "conflict-rate-limit-is-aggregate".
--- tools/ocaml/xenstored/connections.ml | 14 ++++--- tools/ocaml/xenstored/define.ml | 1 + tools/ocaml/xenstored/domains.ml | 4 +- tools/ocaml/xenstored/oxenstored.conf.in | 2 +- tools/ocaml/xenstored/xenstored.ml | 65 +++++++++++++++++++++++--------- 5 files changed, 60 insertions(+), 26 deletions(-)
tools/ocaml/xenstored/connections.ml +8 -6
@@ -44,12 +44,14 @@ let add_domain cons dom = | Some p -> Hashtbl.add cons.ports p con; | None -> () -let select cons = - Hashtbl.fold - (fun _ con (ins, outs) -> - let fd = Connection.get_fd con in - (fd :: ins, if Connection.has_output con then fd :: outs else outs)) - cons.anonymous ([], []) +let select ?(only_if = (fun _ -> true)) cons = + Hashtbl.fold (fun _ con (ins, outs) -> + if (only_if con) then ( + let fd = Connection.get_fd con in + (fd :: ins, if Connection.has_output con then fd :: outs else outs) + ) else (ins, outs) + ) + cons.anonymous ([], []) let find cons = Hashtbl.find cons.anonymous
tools/ocaml/xenstored/define.ml +1 -0
@@ -30,6 +30,7 @@ let maxtransaction = ref (20) let maxrequests = ref (-1) (* maximum requests per transaction *) let conflict_burst_limit = ref 5.0 +let conflict_max_history_seconds = ref 0.05 let conflict_rate_limit_is_aggregate = ref true let domid_self = 0x7FF0
tools/ocaml/xenstored/domains.ml +2 -2
@@ -39,12 +39,12 @@ type domains = { mutable n_paused: int; } -let init eventchn = { +let init eventchn on_first_conflict_pause = { eventchn = eventchn; table = Hashtbl.create 10; doms_conflict_paused = Queue.create (); doms_with_conflict_penalty = Queue.create (); - on_first_conflict_pause = (fun () -> ()); (* Dummy value for now, pending subsequent commit. *) + on_first_conflict_pause = on_first_conflict_pause; n_paused = 0; } let del doms id = Hashtbl.remove doms.table id
tools/ocaml/xenstored/oxenstored.conf.in +1 -1
@@ -22,7 +22,7 @@ conflict-burst-limit = 5.0 # The conflict-credit is replenished over time: # one point is issued after each conflict-max-history-seconds, so this # is the minimum pause-time during which a domain will be ignored. -# conflict-max-history-seconds = 0.05 +conflict-max-history-seconds = 0.05 # If the conflict-rate-limit-is-aggregate flag is true then after each # tick one point of conflict-credit is given to just one domain: the
tools/ocaml/xenstored/xenstored.ml +48 -17
110 lines not on this page · raw message
Signature · 1 line
2.1.4
From 665c6664ce4f42f01d6083dce0a16e45a09ef9de Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Tue, 14 Mar 2017 12:17:38 +0000
Subject: [PATCH 06/15] oxenstored: add transaction info relevant to
history-tracking
Specifically:
* retain the original store (not just the root) in full transactions
* store commit count at the time of the start of the transaction
--- tools/ocaml/xenstored/process.ml | 2 +- tools/ocaml/xenstored/transaction.ml | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-)
tools/ocaml/xenstored/process.ml +1 -1
@@ -286,7 +286,7 @@ let transaction_replay c t doms cons = | Transaction.No -> error "attempted to replay a non-full transaction"; false - | Transaction.Full(id, oldroot, cstore) -> + | Transaction.Full(id, oldstore, cstore) -> let tid = Connection.start_transaction c cstore in let new_t = Transaction.make tid cstore in let con = sprintf "r(%d):%s" id (Connection.get_domstr c) in
tools/ocaml/xenstored/transaction.ml +8 -4
@@ -73,12 +73,13 @@ let can_coalesce oldroot currentroot path = type ty = No | Full of ( int * (* Transaction id *) - Store.Node.t * (* Original root *) + Store.t * (* Original store *) Store.t (* A pointer to the canonical store: its root changes on each transaction-commit *) ) type t = { ty: ty; + start_count: int64; store: Store.t; (* This is the store that we change in write operations. *) quota: Quota.t; mutable paths: (Xenbus.Xb.Op.operation * Store.Path.t) list;
@@ -87,10 +88,13 @@ type t = { mutable write_lowpath: Store.Path.t option; } +let counter = ref 0L + let make id store = - let ty = if id = none then No else Full(id, Store.get_root store, store) in + let ty = if id = none then No else Full(id, Store.copy store, store) in { ty = ty; + start_count = !counter; store = if id = none then store else Store.copy store; quota = Quota.copy store.Store.quota; paths = [];
@@ -161,7 +165,7 @@ let commit ~con t = let has_commited = match t.ty with | No -> true - | Full (id, oldroot, cstore) -> (* "cstore" meaning current canonical store *) + | Full (id, oldstore, cstore) -> (* "cstore" meaning current canonical store *) let commit_partial oldroot cstore store = (* get the lowest path of the query and verify that it hasn't been modified by others transactions. *)
@@ -204,7 +208,7 @@ let commit ~con t = if !test_eagain && Random.int 3 = 0 then false else - try_commit oldroot cstore t.store + try_commit (Store.get_root oldstore) cstore t.store in if has_commited && has_write_ops then Disk.write t.store;
Signature · 1 line
2.1.4
From 920851cb806c1427b1ac0d5e8a694b06d741b5e0 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Tue, 14 Mar 2017 13:20:07 +0000
Subject: [PATCH 07/15] oxenstored: support commit history tracking
Add ability to track xenstore tree operations -- either non-transactional operations or committed transactions.
For now, the call to actually retain commits is commented out because history can grow without bound.
For now, we call record_commit for all non-transactional operations. A subsequent patch will make it retain only the ones with side-effects.
--- tools/ocaml/xenstored/Makefile | 1 + tools/ocaml/xenstored/history.ml | 43 ++++++++++++++++++++++++++++++++++++++ tools/ocaml/xenstored/process.ml | 24 +++++++++++++++++++-- tools/ocaml/xenstored/xenstored.ml | 1 + 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 tools/ocaml/xenstored/history.ml
tools/ocaml/xenstored/Makefile +1 -0
@@ -53,6 +53,7 @@ OBJS = paths \ domains \ connection \ connections \ + history \ parse_arg \ process \ xenstored
tools/ocaml/xenstored/history.ml new file +43 -0
43 lines not on this page · raw message
tools/ocaml/xenstored/process.ml +22 -2
@@ -278,6 +278,16 @@ let write_response_log ~ty ~tid ~con ~response = | Packet.Reply x -> write_answer_log ~ty ~tid ~con ~data:x | Packet.Error e -> write_answer_log ~ty:(Xenbus.Xb.Op.Error) ~tid ~con ~data:e +let record_commit ~con ~tid ~before ~after = + let inc r = r := Int64.add 1L !r in + let finish_count = inc Transaction.counter; !Transaction.counter in + (* This call would leak memory if historic activity is retained forever + so can only be uncommented if history is guaranteed not to grow + unboundedly. + History.push {History.con=con; tid=tid; before=before; after=after; finish_count=finish_count} + *) + () + (* Replay a stored transaction against a fresh store, check the responses are all equivalent: if so, commit the transaction. Otherwise send the abort to the client. *)
@@ -348,8 +358,14 @@ let do_transaction_end con t domains cons data = Connection.end_transaction con (Transaction.get_id t) commit in if not success then raise Transaction_again; - if commit then - process_watch (List.rev (Transaction.get_paths t)) cons + if commit then begin + process_watch (List.rev (Transaction.get_paths t)) cons; + match t.Transaction.ty with + | Transaction.No -> + () (* no need to record anything *) + | Transaction.Full(id, oldstore, cstore) -> + record_commit ~con ~tid:id ~before:oldstore ~after:cstore + end let do_introduce con t domains cons data = if not (Connection.is_dom0 con)
@@ -432,7 +448,11 @@ let process_packet ~store ~cons ~doms ~con ~req = else Connection.get_transaction con tid in + + let before = Store.copy store in let response = input_handle_error ~cons ~doms ~fct ~con ~t ~req in + let after = Store.copy store in + if tid = Transaction.none then record_commit ~con ~tid ~before ~after; let response = try if tid <> Transaction.none then
tools/ocaml/xenstored/xenstored.ml +1 -0
@@ -385,6 +385,7 @@ let _ = Symbol.mark_all_as_unused (); Store.mark_symbols store; Connections.iter cons Connection.mark_symbols; + History.mark_symbols (); Symbol.garbage () end;
Signature · 1 line
2.1.4
From 74321358c3afdb793975fa84fe1ef69d8f5dcaae Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 14:20:33 +0000
Subject: [PATCH 08/15] oxenstored: only record operations with side-effects in
history
There is no need to record "read" operations as they will never cause another transaction to fail.
Forward port to xen-unstable:
* Remove Xenbus.Xb.Op.Restrict
--- tools/ocaml/xenstored/process.ml | 46 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-)
tools/ocaml/xenstored/process.ml +42 -4
58 lines not on this page · raw message
Signature · 1 line
2.1.4
From f30a4150376e7279936131f6651cf6731880e785 Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Thu, 23 Mar 2017 14:25:16 +0000
Subject: [PATCH 09/15] oxenstored: discard old commit-history on txn end
The history of commits is to be used for working out which historical commit(s) (including atomic writes) caused conflicts with a currently-failing commit of a transaction. Any commit that was made before the current transaction started cannot be relevant. Therefore we never need to keep history from before the start of the longest-running transaction that is open at any given time: whenever a transaction ends (with or without a commit) then if it was the longest-running open transaction we can delete history up until start of the the next-longest-running open transaction.
Some transactions might stay open for a very long time, so if any transaction exceeds conflict_max_history_seconds then we remove it from consideration in this context, and will not guarantee to keep remembering about historical commits made during such a transaction.
We implement this by keeping a list of all open transactions that have not been open too long. When a transaction ends, we remove it from the list, along with any that have been open longer than the maximum; then we delete any history from before the start of the longest-running transaction remaining in the list.
--- tools/ocaml/xenstored/history.ml | 17 +++++++++++++++++ tools/ocaml/xenstored/process.ml | 4 ++-- tools/ocaml/xenstored/transaction.ml | 29 +++++++++++++++++++++++++---- 3 files changed, 44 insertions(+), 6 deletions(-)
tools/ocaml/xenstored/history.ml +17 -0
@@ -36,6 +36,23 @@ let mark_symbols () = ) !history +(* Keep only enough commit-history to protect the running transactions that we are still tracking *) +(* There is scope for optimisation here, replacing List.filter with something more efficient, + * probably on a different list-like structure. *) +let trim () = + history := match Transaction.oldest_short_running_transaction () with + | None -> [] (* We have no open transaction, so no history is needed *) + | Some (_, txn) -> ( + (* keep records with finish_count recent enough to be relevant *) + List.filter (fun r -> r.finish_count > txn.Transaction.start_count) !history + ) + +let end_transaction txn con tid commit = + let success = Connection.end_transaction con tid commit in + Transaction.end_transaction txn; + trim (); + success + let push (x: history_record) = let dom = x.con.Connection.dom in match dom with
tools/ocaml/xenstored/process.ml +2 -2
@@ -298,7 +298,7 @@ let transaction_replay c t doms cons = false | Transaction.Full(id, oldstore, cstore) -> let tid = Connection.start_transaction c cstore in - let new_t = Transaction.make tid cstore in + let new_t = Transaction.make ~internal:true tid cstore in let con = sprintf "r(%d):%s" id (Connection.get_domstr c) in let perform_exn (request, response) = write_access_log ~ty:request.Packet.ty ~tid ~con ~data:request.Packet.data;
@@ -355,7 +355,7 @@ let do_transaction_end con t domains cons data = in let success = let commit = if commit then Some (fun con trans -> transaction_replay con trans domains cons) else None in - Connection.end_transaction con (Transaction.get_id t) commit in + History.end_transaction t con (Transaction.get_id t) commit in if not success then raise Transaction_again; if commit then begin
tools/ocaml/xenstored/transaction.ml +25 -4
@@ -87,12 +87,29 @@ type t = { mutable read_lowpath: Store.Path.t option; mutable write_lowpath: Store.Path.t option; } +let get_id t = match t.ty with No -> none | Full (id, _, _) -> id let counter = ref 0L -let make id store = +(* Scope for optimisation: different data-structure and functions to search/filter it *) +let short_running_txns = ref [] + +let oldest_short_running_transaction () = + let rec last = function + | [] -> None + | [x] -> Some x + | x :: xs -> last xs + in last !short_running_txns + +let end_transaction txn = + let cutoff = Unix.gettimeofday () -. !Define.conflict_max_history_seconds in + short_running_txns := List.filter + (function (start_time, tx) -> start_time >= cutoff && tx != txn) + !short_running_txns + +let make ?(internal=false) id store = let ty = if id = none then No else Full(id, Store.copy store, store) in - { + let txn = { ty = ty; start_count = !counter; store = if id = none then store else Store.copy store;
@@ -101,9 +118,13 @@ let make id store = operations = []; read_lowpath = None; write_lowpath = None; - } + } in + if id <> none && not internal then ( + let now = Unix.gettimeofday () in + short_running_txns := (now, txn) :: !short_running_txns + ); + txn -let get_id t = match t.ty with No -> none | Full (id, _, _) -> id let get_store t = t.store let get_paths t = t.paths
Signature · 1 line
2.1.4
From a5d8b21fefc396d6c815d6f98dc986fa958d64a1 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Mon, 27 Mar 2017 08:58:29 +0000
Subject: [PATCH 10/15] oxenstored: track commit history
Since the list of historic activity cannot grow without bound, it is safe to use this to track commits.
--- tools/ocaml/xenstored/process.ml | 5 ----- 1 file changed, 5 deletions(-)
tools/ocaml/xenstored/process.ml +0 -5
@@ -281,12 +281,7 @@ let write_response_log ~ty ~tid ~con ~response = let record_commit ~con ~tid ~before ~after = let inc r = r := Int64.add 1L !r in let finish_count = inc Transaction.counter; !Transaction.counter in - (* This call would leak memory if historic activity is retained forever - so can only be uncommented if history is guaranteed not to grow - unboundedly. History.push {History.con=con; tid=tid; before=before; after=after; finish_count=finish_count} - *) - () (* Replay a stored transaction against a fresh store, check the responses are all equivalent: if so, commit the transaction. Otherwise send the abort to
Signature · 1 line
2.1.4
From d5eab8a91d878d63389cd5a40ddc7bbde0afc642 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 14:28:16 +0000
Subject: [PATCH 11/15] oxenstored: blame the connection that caused a
transaction conflict
Blame each connection found to have made a commit that would cause this transaction to fail. Each blamed connection is penalised by having its conflict-credit decremented.
Note the change in semantics for the replay function: we no longer stop after finding the first operation that can't be replayed. This allows us to identify all operations that conflicted with this transaction, not just the one that conflicted first.
v1 Reviewed-by: Christian Lindig <[email protected]>
Changes since v1:
* use correct log levels for informational messages
Changes since v2:
* fix the blame algorithm and improve logging (fix was reviewed by Jonathan Davies)
--- tools/ocaml/xenstored/history.ml | 12 ++++++++++ tools/ocaml/xenstored/process.ml | 50 ++++++++++++++++++++++++++++++++-------- 2 files changed, 52 insertions(+), 10 deletions(-)
tools/ocaml/xenstored/history.ml +12 -0
@@ -58,3 +58,15 @@ let push (x: history_record) = match dom with | None -> () (* treat socket connections as always free to conflict *) | Some d -> if not (Domain.is_free_to_conflict d) then history := x :: !history + +(* Find the connections from records since commit-count [since] for which [f record] returns [true] *) +let filter_connections ~since ~f = + (* The "mem" call is an optimisation, to avoid calling f if we have picked con already. *) + (* Using a hash table rather than a list is to optimise the "mem" call. *) + List.fold_left (fun acc hist_rec -> + if hist_rec.finish_count > since + && not (Hashtbl.mem acc hist_rec.con) + && f hist_rec + then Hashtbl.replace acc hist_rec.con (); + acc + ) (Hashtbl.create 1023) !history
tools/ocaml/xenstored/process.ml +40 -10
75 lines not on this page · raw message
Signature · 1 line
2.1.4
From 92e738109255d83bdb928ea5ef34db8a25333fcf Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Thu, 23 Mar 2017 19:06:54 +0000
Subject: [PATCH 12/15] oxenstored: allow self-conflicts
We already avoid inter-domain conflicts but now allow intra-domain conflicts. Although there are no known practical examples of a domain that might perform operations that conflict with its own transactions, this is conceivable, so here we avoid changing those semantics unnecessarily.
When a transaction commit fails with a conflict and we look through the history of commits to see which connection(s) to blame, ignore historical commits that were made by the same connection as the failing commit.
--- tools/ocaml/xenstored/history.ml | 3 ++- tools/ocaml/xenstored/process.ml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)
tools/ocaml/xenstored/history.ml +2 -1
@@ -60,11 +60,12 @@ let push (x: history_record) = | Some d -> if not (Domain.is_free_to_conflict d) then history := x :: !history (* Find the connections from records since commit-count [since] for which [f record] returns [true] *) -let filter_connections ~since ~f = +let filter_connections ~ignore ~since ~f = (* The "mem" call is an optimisation, to avoid calling f if we have picked con already. *) (* Using a hash table rather than a list is to optimise the "mem" call. *) List.fold_left (fun acc hist_rec -> if hist_rec.finish_count > since + && not (hist_rec.con == ignore) && not (Hashtbl.mem acc hist_rec.con) && f hist_rec then Hashtbl.replace acc hist_rec.con ();
tools/ocaml/xenstored/process.ml +1 -1
@@ -335,7 +335,7 @@ let transaction_replay c t doms cons = then (punish hist_rec.History.con; true) else false ) in - let guilty_cons = History.filter_connections ~since:t.Transaction.start_count ~f:judge_and_sentence in + let guilty_cons = History.filter_connections ~ignore:c ~since:t.Transaction.start_count ~f:judge_and_sentence in if Hashtbl.length guilty_cons = 0 then debug "Found no culprit for conflict in %s: must be self or not in history." con; false )
Signature · 1 line
2.1.4
From 8a3587845697ef454b26f2bd44f892f7452eb8b7 Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Fri, 24 Mar 2017 16:16:10 +0000
Subject: [PATCH 13/15] oxenstored: do not commit read-only transactions
The packet telling us to end the transaction has always carried an argument telling us whether to commit.
If the transaction made no modifications to the tree, now we ignore that argument and do not commit: it is just a waste of effort.
This makes read-only transactions immune to conflicts, and means that we do not need to store any of their details in the history that is used for assigning blame for conflicts.
We count a transaction as a read-only transaction only if it contains no operations that modified the tree.
This means that (for example) a transaction that creates a new node then deletes it would NOT count as read-only, even though it makes no change overall. A more sophisticated algorithm could judge the transaction based on comparison of its initial and final states, but this would add complexity and computational cost.
--- tools/ocaml/xenstored/process.ml | 1 + tools/ocaml/xenstored/transaction.ml | 1 + 2 files changed, 2 insertions(+)
tools/ocaml/xenstored/process.ml +1 -0
@@ -378,6 +378,7 @@ let do_transaction_end con t domains cons data = | x :: _ -> raise (Invalid_argument x) | _ -> raise Invalid_Cmd_Args in + let commit = commit && not (Transaction.is_read_only t) in let success = let commit = if commit then Some (fun con trans -> transaction_replay con trans domains cons) else None in History.end_transaction t con (Transaction.get_id t) commit in
tools/ocaml/xenstored/transaction.ml +1 -0
@@ -128,6 +128,7 @@ let make ?(internal=false) id store = let get_store t = t.store let get_paths t = t.paths +let is_read_only t = t.paths = [] let add_wop t ty path = t.paths <- (ty, path) :: t.paths let add_operation ~perm t request response = if !Define.maxrequests >= 0
Signature · 1 line
2.1.4
From 8552124ec0f09a21b8d3e125aa6f1fc008d9fd23 Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Fri, 24 Mar 2017 19:55:03 +0000
Subject: [PATCH 14/15] oxenstored: don't wake to issue no conflict-credit
In the main loop, when choosing the timeout for the select function call, we were setting it so as to wake up to issue conflict-credit to any domains that could accept it. When xenstore is idle, this would mean waking up every 50ms (by default) to do no work. With this commit, we check whether any domain is below its cap, and if not then we set the timeout for longer (the same timeout as before the conflict-protection feature was added).
--- tools/ocaml/xenstored/domains.ml | 51 ++++++++++++++++++++++++++++++-------- tools/ocaml/xenstored/xenstored.ml | 5 +++- 2 files changed, 44 insertions(+), 12 deletions(-)
tools/ocaml/xenstored/domains.ml +40 -11
91 lines not on this page · raw message
tools/ocaml/xenstored/xenstored.ml +4 -1
@@ -437,7 +437,10 @@ let _ = peaceful_mw; let start_time = Unix.gettimeofday () in let timeout = - let until_next_activity = min (max 0. (!next_frequent_ops -. start_time)) period_ops_interval in + let until_next_activity = + if Domains.all_at_max_credit domains + then period_ops_interval + else min (max 0. (!next_frequent_ops -. start_time)) period_ops_interval in if peaceful_mw <> [] then 0. else until_next_activity in let inset, outset = Connections.select ~only_if:is_peaceful cons in
Signature · 1 line
2.1.4
From f08c8ee1d52fe7ee3918adfa4636a6fd7821d7ca Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Mon, 27 Mar 2017 14:36:34 +0100
Subject: [PATCH 15/15] oxenstored transaction conflicts: improve logging
For information related to transaction conflicts, potentially frequent logging at "info" priority has been changed to "debug" priority, and once per two minutes there is an "info" priority summary.
Additional detailed logging has been added at "debug" priority.
--- tools/ocaml/xenstored/domain.ml | 8 ++++++++ tools/ocaml/xenstored/domains.ml | 5 +++++ tools/ocaml/xenstored/process.ml | 6 +++++- tools/ocaml/xenstored/transaction.ml | 5 +++++ tools/ocaml/xenstored/xenstored.ml | 6 ++++++ 5 files changed, 29 insertions(+), 1 deletion(-)
tools/ocaml/xenstored/domain.ml +8 -0
@@ -34,6 +34,7 @@ type t = mutable conflict_credit: float; (* Must be positive to perform writes; a commit that later causes conflict with another domain's transaction costs credit. *) + mutable caused_conflicts: int64; } let is_dom0 d = d.id = 0
@@ -93,4 +94,11 @@ let make id mfn remote_port interface eventchn = { bad_client = false; io_credit = 0; conflict_credit = !Define.conflict_burst_limit; + caused_conflicts = 0L; } + +let log_and_reset_conflict_stats logfn dom = + if dom.caused_conflicts > 0L then ( + logfn dom.id dom.caused_conflicts; + dom.caused_conflicts <- 0L + )
tools/ocaml/xenstored/domains.ml +5 -0
@@ -146,8 +146,10 @@ let create0 doms = dom let decr_conflict_credit doms dom = + dom.Domain.caused_conflicts <- Int64.add 1L dom.Domain.caused_conflicts; let before = dom.Domain.conflict_credit in let after = max (-1.0) (before -. 1.0) in + debug "decr_conflict_credit dom%d %F -> %F" (Domain.get_id dom) before after; dom.Domain.conflict_credit <- after; let newly_penalised = before >= !Define.conflict_burst_limit
@@ -178,7 +180,9 @@ let decr_conflict_credit doms dom = let incr_conflict_credit_from_queue doms = let process_queue q requeue_test = let d = pop q in + let before = d.Domain.conflict_credit in (* just for debug-logging *) d.Domain.conflict_credit <- min (d.Domain.conflict_credit +. 1.0) !Define.conflict_burst_limit; + debug "incr_conflict_credit_from_queue: dom%d: %F -> %F" (Domain.get_id d) before d.Domain.conflict_credit; if requeue_test d.Domain.conflict_credit then ( push d q (* Make it queue up again for its next point of credit. *) )
@@ -200,6 +204,7 @@ let incr_conflict_credit doms = let before = dom.Domain.conflict_credit in let after = min (before +. 1.0) !Define.conflict_burst_limit in dom.Domain.conflict_credit <- after; + debug "incr_conflict_credit dom%d: %F -> %F" (Domain.get_id dom) before after; if before <= 0.0 && after > 0.0 then doms.n_paused <- doms.n_paused - 1;
tools/ocaml/xenstored/process.ml +5 -1
@@ -315,6 +315,7 @@ let transaction_replay c t doms cons = Transaction.commit ~con replay_t with | Transaction_again -> ( + Transaction.failed_commits := Int64.add !Transaction.failed_commits 1L; let victim_domstr = Connection.get_domstr c in debug "Apportioning blame for EAGAIN in txn %d, domain=%s" id victim_domstr; let punish guilty_con =
@@ -336,7 +337,10 @@ let transaction_replay c t doms cons = else false ) in let guilty_cons = History.filter_connections ~ignore:c ~since:t.Transaction.start_count ~f:judge_and_sentence in - if Hashtbl.length guilty_cons = 0 then debug "Found no culprit for conflict in %s: must be self or not in history." con; + if Hashtbl.length guilty_cons = 0 then ( + debug "Found no culprit for conflict in %s: must be self or not in history." con; + Transaction.failed_commits_no_culprit := Int64.add !Transaction.failed_commits_no_culprit 1L + ); false ) | e ->
tools/ocaml/xenstored/transaction.ml +5 -0
@@ -90,6 +90,11 @@ type t = { let get_id t = match t.ty with No -> none | Full (id, _, _) -> id let counter = ref 0L +let failed_commits = ref 0L +let failed_commits_no_culprit = ref 0L +let reset_conflict_stats () = + failed_commits := 0L; + failed_commits_no_culprit := 0L (* Scope for optimisation: different data-structure and functions to search/filter it *) let short_running_txns = ref []
tools/ocaml/xenstored/xenstored.ml +6 -0
@@ -376,6 +376,7 @@ let _ = let last_scan_time = ref 0. in let periodic_ops now = + debug "periodic_ops starting"; (* we garbage collect the string->int dictionary after a sizeable amount of operations, * there's no need to be really fast even if we got loose * objects since names are often reuse.
@@ -395,7 +396,11 @@ let _ = (* make sure we don't print general stats faster than 2 min *) if now > (!last_stat_time +. 120.) then ( + info "Transaction conflict statistics for last %F seconds:" (now -. !last_stat_time); last_stat_time := now; + Domains.iter domains (Domain.log_and_reset_conflict_stats (info "Dom%d caused %Ld conflicts")); + info "%Ld failed transactions; of these no culprit was found for %Ld" !Transaction.failed_commits !Transaction.failed_commits_no_culprit; + Transaction.reset_conflict_stats (); let gc = Gc.stat () in let (lanon, lanon_ops, lanon_watchs,
@@ -415,6 +420,7 @@ let _ = gc.Gc.free_words gc.Gc.free_blocks ); let elapsed = Unix.gettimeofday () -. now in + debug "periodic_ops took %F seconds." elapsed; delay_next_frequent_ops_by elapsed in
Signature · 1 line
2.1.4
From 26b15d4eb7ac71fcab28a7fca664afa0549c135c Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Tue, 28 Mar 2017 18:57:52 +0100
Subject: [PATCH 16/15] oxenstored: trim history in the frequent_ops function
We were trimming the history of commits only at the end of each transaction (regardless of how it ended).
Therefore if non-transactional writes were being made but no transactions were being ended, the history would grow indefinitely. Now we trim the history at regular intervals.
--- tools/ocaml/xenstored/history.ml | 6 +++--- tools/ocaml/xenstored/transaction.ml | 8 ++++++-- tools/ocaml/xenstored/xenstored.ml | 1 + 3 files changed, 10 insertions(+), 5 deletions(-)
tools/ocaml/xenstored/history.ml +3 -3
@@ -39,7 +39,8 @@ let mark_symbols () = (* Keep only enough commit-history to protect the running transactions that we are still tracking *) (* There is scope for optimisation here, replacing List.filter with something more efficient, * probably on a different list-like structure. *) -let trim () = +let trim ?txn () = + Transaction.trim_short_running_transactions txn; history := match Transaction.oldest_short_running_transaction () with | None -> [] (* We have no open transaction, so no history is needed *) | Some (_, txn) -> (
@@ -49,8 +50,7 @@ let trim () = let end_transaction txn con tid commit = let success = Connection.end_transaction con tid commit in - Transaction.end_transaction txn; - trim (); + trim ~txn (); success let push (x: history_record) =
tools/ocaml/xenstored/transaction.ml +6 -2
@@ -106,10 +106,14 @@ let oldest_short_running_transaction () = | x :: xs -> last xs in last !short_running_txns -let end_transaction txn = +let trim_short_running_transactions txn = let cutoff = Unix.gettimeofday () -. !Define.conflict_max_history_seconds in + let keep = match txn with + | None -> (function (start_time, _) -> start_time >= cutoff) + | Some t -> (function (start_time, tx) -> start_time >= cutoff && tx != t) + in short_running_txns := List.filter - (function (start_time, tx) -> start_time >= cutoff && tx != txn) + keep !short_running_txns let make ?(internal=false) id store =
tools/ocaml/xenstored/xenstored.ml +1 -0
@@ -280,6 +280,7 @@ let _ = * than the periodic_ops function *) let frequent_ops () = if Unix.gettimeofday () > !next_frequent_ops then ( + History.trim (); Domains.incr_conflict_credit domains; advance_next_frequent_ops () ) in
Signature · 1 line
1.7.9.5
From 7df6157ccf3dd8f9d6fae690be3f6216b0c2dd2b Mon Sep 17 00:00:00 2001
From: Ian Jackson <[email protected]>
Date: Sat, 18 Mar 2017 17:12:39 +0000
Subject: [PATCH 01/30] xenstored: apply a write transaction rate limit
This avoids a rogue client being about to stall another client (eg the toolstack) indefinitely.
This is XSA-206.
--- tools/xenstore/Makefile | 3 +- tools/xenstore/xenstored_core.c | 9 ++ tools/xenstore/xenstored_core.h | 6 + tools/xenstore/xenstored_domain.c | 215 +++++++++++++++++++++++++++++++++ tools/xenstore/xenstored_domain.h | 25 ++++ tools/xenstore/xenstored_transaction.c | 5 + 6 files changed, 262 insertions(+), 1 deletion(-)
tools/xenstore/Makefile +2 -1
@@ -19,6 +19,7 @@ XENSTORED_OBJS_$(CONFIG_NetBSD) = xenstored_netbsd.o xenstored_posix.o XENSTORED_OBJS_$(CONFIG_MiniOS) = xenstored_minios.o XENSTORED_OBJS += $(XENSTORED_OBJS_y) +LDLIBS_xenstored += -lrt ifneq ($(XENSTORE_STATIC_CLIENTS),y) LIBXENSTORE := libxenstore.so
@@ -61,7 +62,7 @@ init-xenstore-domain: init-xenstore-domain.o $(LIBXENSTORE) $(CC) $(LDFLAGS) $^ $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) -o $@ $(APPEND_LDFLAGS) xenstored: $(XENSTORED_OBJS) - $(CC) $(LDFLAGS) $^ $(LDLIBS_libxenctrl) $(SOCKET_LIBS) -o $@ $(APPEND_LDFLAGS) + $(CC) $(LDFLAGS) $^ $(LDLIBS_libxenctrl) $(LDLIBS_xenstored) $(SOCKET_LIBS) -o $@ $(APPEND_LDFLAGS) xenstored.a: $(XENSTORED_OBJS) $(AR) cr $@ $^
tools/xenstore/xenstored_core.c +9 -0
@@ -342,6 +342,7 @@ static void initialize_fds(int sock, int *p_sock_pollfd_idx, int *ptimeout) {struct connection *conn; +struct wrl_timestampt now;if (fds)memset (fds,0 ,sizeof (struct pollfd ) * current_array_size);
@@ -361,8 +362,11 @@ static void initialize_fds(int sock, int *p_sock_pollfd_idx, xce_pollfd_idx =set_fd (xc_evtchn_fd (xce_handle),POLLIN |POLLPRI ); +wrl_gettime_now (&now); +list_for_each_entry (conn, &connections, list) {if (conn->domain) { +wrl_check_timeout (conn->domain, now, ptimeout);if (domain_can_read (conn) || (domain_can_write (conn) && !list_empty (&conn->out_list)))
@@ -795,6 +799,7 @@ static void delete_node_single(struct connection *conn, struct node *node)corrupt (conn,"Could not delete '%s'" , node->name);return ; } +domain_entry_dec (conn, node); }
@@ -934,6 +939,7 @@ static void do_write(struct connection *conn, struct buffered_data *in) }add_change_node (conn->transaction, name, false); +wrl_apply_debit_direct (conn);fire_watches (conn, name, false);send_ack (conn,XS_WRITE ); }
@@ -958,6 +964,7 @@ static void do_mkdir(struct connection *conn, const char *name)return ; }add_change_node (conn->transaction, name, false); +wrl_apply_debit_direct (conn);fire_watches (conn, name, false); }send_ack (conn,XS_MKDIR );
@@ -1083,6 +1090,7 @@ static void do_rm(struct connection *conn, const char *name)if (_rm (conn, node, name)) {add_change_node (conn->transaction, name, true); +wrl_apply_debit_direct (conn);fire_watches (conn, name, true);send_ack (conn,XS_RM ); }
@@ -1158,6 +1166,7 @@ static void do_set_perms(struct connection *conn, struct buffered_data *in) }add_change_node (conn->transaction, name, false); +wrl_apply_debit_direct (conn);fire_watches (conn, name, false);send_ack (conn,XS_SET_PERMS ); }
tools/xenstore/xenstored_core.h +6 -0
@@ -31,6 +31,12 @@#include "list.h" #include "tdb.h" +#define MIN (a, b) (((a) < (b))? (a) : (b)) + +typedef int32_t wrl_creditt ; +#define WRL_CREDIT_MAX (1000*1000*1000) +/* ^ satisfies non-overflow condition for wrl_xfer_credit */ +struct buffered_data {struct list_head list;
tools/xenstore/xenstored_domain.c +215 -0
251 lines not on this page · raw message
tools/xenstore/xenstored_domain.h +25 -0
@@ -66,4 +66,29 @@ void domain_watch_inc(struct connection *conn);void domain_watch_dec (struct connection *conn);int domain_watch (struct connection *conn); +/* Write rate limiting */ + +#define WRL_FACTOR 1000/* for fixed-point arithmetic */ +#define WRL_RATE 200 +#define WRL_DBURST 10 +#define WRL_GBURST 1000 +#define WRL_NEWDOMS 5 + +struct wrl_timestampt { +time_t sec; +int msec; +}; + +extern long wrl_ntransactions; + +void wrl_gettime_now (struct wrl_timestampt *now_ts); +void wrl_domain_new (struct domain *domain); +void wrl_domain_destroy (struct domain *domain); +void wrl_credit_update (struct domain *domain,struct wrl_timestampt now); +void wrl_check_timeout (struct domain *domain, +struct wrl_timestampt now, +int *ptimeout); +void wrl_apply_debit_direct (struct connection *conn); +void wrl_apply_debit_trans_commit (struct connection *conn); +#endif /* _XENSTORED_DOMAIN_H */
tools/xenstore/xenstored_transaction.c +5 -0
@@ -117,6 +117,7 @@ static int destroy_transaction(void *_transaction) {struct transaction *trans = _transaction; + wrl_ntransactions--;trace_destroy (trans,"transaction" );if (trans->tdb)tdb_close (trans->tdb);
@@ -180,6 +181,7 @@ void do_transaction_start(struct connection *conn, struct buffered_data *in)talloc_steal (conn, trans);talloc_set_destructor (trans, destroy_transaction); conn->transaction_started++; + wrl_ntransactions++;snprintf (id_str,sizeof (id_str),"%u" , trans->id);send_reply (conn,XS_TRANSACTION_START , id_str,strlen (id_str)+1 );
@@ -214,6 +216,9 @@ void do_transaction_end(struct connection *conn, const char *arg)send_error (conn,EAGAIN );return ; } + +wrl_apply_debit_trans_commit (conn); +if (!replace_tdb (trans->tdb_name, trans->tdb)) {send_error (conn, errno);return ;
Signature · 1 line
2.1.4
From 8153049d49e5669418dd1ee88b2d793ccbabede6 Mon Sep 17 00:00:00 2001
From: Ian Jackson <[email protected]>
Date: Sat, 18 Mar 2017 17:13:27 +0000
Subject: [PATCH 02/30] xenstored: Log when the write transaction rate limit
bites
--- tools/xenstore/xenstored_core.c | 1 + tools/xenstore/xenstored_domain.c | 25 +++++++++++++++++++++++++ tools/xenstore/xenstored_domain.h | 2 ++ 3 files changed, 28 insertions(+)
tools/xenstore/xenstored_core.c +1 -0
@@ -363,6 +363,7 @@ static void initialize_fds(int sock, int *p_sock_pollfd_idx, POLLIN|POLLPRI);wrl_gettime_now (&now); +wrl_log_periodic (now);list_for_each_entry (conn, &connections, list) {if (conn->domain) {
tools/xenstore/xenstored_domain.c +25 -0
@@ -24,6 +24,7 @@#include <stdarg.h> #include <xenctrl.h> #include <time.h> +#include <syslog.h> #include "utils.h" #include "talloc.h"
@@ -80,6 +81,7 @@ struct domain/* write rate limit */ wrl_creditt wrl_credit;/* [ -wrl_config_writecost, +_dburst ] */ struct wrl_timestampt wrl_timestamp; +bool wrl_delay_logged; };static LIST_HEAD (domains);
@@ -771,6 +773,7 @@ long wrl_ntransactions;static long wrl_ndomains;static wrl_creditt wrl_reserve;/* [-wrl_config_newdoms_dburst, +_gburst ] */ +static time_t wrl_log_last_warning;/* 0: no previous warning */ void wrl_gettime_now (struct wrl_timestampt *now_wt) {
@@ -920,6 +923,9 @@ void wrl_check_timeout(struct domain *domain, wakeup); } +#define WRL_LOG (now, ...) \ + (syslog(LOG_WARNING, "write rate limit: " __VA_ARGS__)) +void wrl_apply_debit_actual (struct domain *domain) {struct wrl_timestampt now;
@@ -935,6 +941,25 @@ void wrl_apply_debit_actual(struct domain *domain)trace ("wrl: domain %u credit=%ld (reserve=%ld)\n" , domain->domid, (long )domain->wrl_credit, (long )wrl_reserve); + +if (domain->wrl_credit <0 ) { +if (!domain->wrl_delay_logged++) { +WRL_LOG (now,"domain %ld is affected" , + (long )domain->domid); + }else if (!wrl_log_last_warning) { +WRL_LOG (now,"rate limiting restarts" ); + } + wrl_log_last_warning = now.sec; + } +} + +void wrl_log_periodic (struct wrl_timestampt now) +{ +if (wrl_log_last_warning && + (now.sec - wrl_log_last_warning) >WRL_LOGEVERY ) { +WRL_LOG (now,"not in force recently" ); + wrl_log_last_warning =0 ; + } }void wrl_apply_debit_direct (struct connection *conn)
tools/xenstore/xenstored_domain.h +2 -0
@@ -73,6 +73,7 @@ int domain_watch(struct connection *conn);#define WRL_DBURST 10#define WRL_GBURST 1000#define WRL_NEWDOMS 5 +#define WRL_LOGEVERY 120/* seconds */ struct wrl_timestampt {time_t sec;
@@ -88,6 +89,7 @@ void wrl_credit_update(struct domain *domain, struct wrl_timestampt now);void wrl_check_timeout (struct domain *domain,struct wrl_timestampt now,int *ptimeout); +void wrl_log_periodic (struct wrl_timestampt now);void wrl_apply_debit_direct (struct connection *conn);void wrl_apply_debit_trans_commit (struct connection *conn);
Signature · 1 line
2.1.4
From 59bb62aa888cd4b94510e4d16003077ab1d77e9b Mon Sep 17 00:00:00 2001
From: Vincent Bernardoff <[email protected]>
Date: Fri, 24 Mar 2017 16:57:02 +0000
Subject: [PATCH 03/30] oxenstored: exempt dom0 from domU node quotas
If a domU has exhausted its quota we still want the toolstack in dom0 to be able to create new nodes in places like
/local/domain/%d/control/shutdown
Without this patch, a domU which has exhausted its quota can only be powered off, which is not as good as being able to request a clean shutdown.
--- tools/ocaml/xenstored/store.ml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/ocaml/xenstored/store.ml +3 -3
@@ -383,7 +383,7 @@ let set_node store path node = let write store perm path value = let node, existing = get_deepest_existing_node store path in let owner = Node.get_owner node in - if existing then + if existing || (Perms.Connection.is_dom0 perm) then (* Only check the string length limit *) Quota.check store.quota (-1) (String.length value) else
@@ -398,7 +398,7 @@ let mkdir store perm path = let node, existing = get_deepest_existing_node store path in let owner = Node.get_owner node in (* It's upt to the mkdir logic to decide what to do with existing path *) - if not existing then Quota.check store.quota owner 0; + if not (existing || (Perms.Connection.is_dom0 perm)) then Quota.check store.quota owner 0; store.root <- path_mkdir store perm path; Quota.add_entry store.quota owner
@@ -416,7 +416,7 @@ let setperms store perm path nperms = | Some node -> let old_owner = Node.get_owner node in let new_owner = Perms.Node.get_owner nperms in - if old_owner <> new_owner then Quota.check store.quota new_owner 0; + if not ((old_owner = new_owner) || (Perms.Connection.is_dom0 perm)) then Quota.check store.quota new_owner 0; store.root <- path_setperms store perm path nperms; Quota.del_entry store.quota old_owner; Quota.add_entry store.quota new_owner
Signature · 1 line
2.1.4
From a0cdc0e823117ff32560822e16f44260983b5142 Mon Sep 17 00:00:00 2001
From: Jerome Maloberti <[email protected]>
Date: Fri, 24 Mar 2017 16:57:40 +0000
Subject: [PATCH 04/30] oxenstored: perform a 3-way merge of the quota after a
transaction
At a beginning of a transaction, the quotas from the global store are duplicated and modified by the transaction. If during the transaction, an action associated to no transaction is concurrently executed, the quotas of the global store are updated, and then the updates are lost when the transaction merges.
We fix this problem by keeping another copy of the quota at the beginning of the transaction, and performing a 3-way merge between the quotas from the transaction and the "original" copy of the quota onto the quota of the global store.
--- tools/ocaml/xenstored/quota.ml | 5 +++++ tools/ocaml/xenstored/store.ml | 13 +++++-------- tools/ocaml/xenstored/transaction.ml | 4 +++- 3 files changed, 13 insertions(+), 9 deletions(-)
tools/ocaml/xenstored/quota.ml +5 -0
@@ -81,3 +81,8 @@ let add_entry quota id = let add quota diff = Hashtbl.iter (fun id nb -> set_entry quota id (get_entry quota id + nb)) diff.cur + +let merge orig_quota mod_quota dest_quota = + Hashtbl.iter (fun id nb -> let diff = nb - (get_entry orig_quota id) in + if diff <> 0 then + set_entry dest_quota id ((get_entry dest_quota id) + diff)) mod_quota.cur
tools/ocaml/xenstored/store.ml +5 -8
@@ -188,20 +188,17 @@ let rec get_deepest_existing_node node = function with Not_found -> node, false let set_node rnode path nnode = - let quota = Quota.create () in - if !Quota.activate then Node.recurse (fun node -> Quota.add_entry quota (Node.get_owner node)) nnode; if path = [] then - nnode, quota + nnode else let set_node node name = try let ent = Node.find node name in - if !Quota.activate then Node.recurse (fun node -> Quota.del_entry quota (Node.get_owner node)) ent; Node.replace_child node ent nnode with Not_found -> Node.add_child node nnode in - apply_modify rnode path set_node, quota + apply_modify rnode path set_node (* read | ls | getperms use this *) let rec lookup node path fct =
@@ -375,10 +372,10 @@ let dump_buffer store = dump_store_buf store.root (* modifying functions with quota udpate *) -let set_node store path node = - let root, quota_diff = Path.set_node store.root path node in +let set_node store path node orig_quota mod_quota = + let root = Path.set_node store.root path node in store.root <- root; - Quota.add store.quota quota_diff + Quota.merge orig_quota mod_quota store.quota let write store perm path value = let node, existing = get_deepest_existing_node store path in
tools/ocaml/xenstored/transaction.ml +3 -1
@@ -74,6 +74,7 @@ type ty = No | Full of (int * Store.Node.t * Store.t) type t = { ty: ty; store: Store.t; + quota: Quota.t; mutable ops: (Xenbus.Xb.Op.operation * Store.Path.t) list; mutable read_lowpath: Store.Path.t option; mutable write_lowpath: Store.Path.t option;
@@ -84,6 +85,7 @@ let make id store = { ty = ty; store = if id = none then store else Store.copy store; + quota = Quota.copy store.Store.quota; ops = []; read_lowpath = None; write_lowpath = None;
@@ -155,7 +157,7 @@ let commit ~con t = (* it has to be in the store, otherwise it means bugs in the lowpath registration. we don't need to handle none. *) - maybe (fun n -> Store.set_node cstore p n) n; + maybe (fun n -> Store.set_node cstore p n t.quota store.Store.quota) n; Logging.write_coalesce ~tid:(get_id t) ~con (Store.Path.to_string p); ) t.write_lowpath; maybe (fun p ->
Signature · 1 line
2.1.4
From 63e01804c4ba80816af7f5a12786fb45ee2d194b Mon Sep 17 00:00:00 2001
From: Zheng Li <[email protected]>
Date: Fri, 24 Mar 2017 17:01:08 +0000
Subject: [PATCH 05/30] oxenstored: catch the error when a connection is
already deleted
The function process_fdset_with is called on the read set connections first. During the process, it might destroy a connection and remove it from the connections database if some errors occur. However, a reference to the same connection might still exist in the write set, which is awaiting to be processed next. In this case, a Not_found error will be raised and the process is aborted.
This patch changes the logic to ignore connections just missing from the connection database and continue the rest part of the work.
--- tools/ocaml/xenstored/xenstored.ml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
tools/ocaml/xenstored/xenstored.ml +5 -2
@@ -43,8 +43,11 @@ let process_connection_fds store cons domains rset wset = debug "closing socket connection" in let process_fdset_with fds fct = - List.iter (fun fd -> try_fct fct (Connections.find cons fd)) fds - in + List.iter + (fun fd -> + try try_fct fct (Connections.find cons fd) + with Not_found -> () + ) fds in process_fdset_with rset Process.do_input; process_fdset_with wset Process.do_output
Signature · 1 line
2.1.4
From efa34c63e8a62dab87918c7854e51291bd8fabeb Mon Sep 17 00:00:00 2001
From: Zheng Li <[email protected]>
Date: Fri, 24 Mar 2017 17:02:08 +0000
Subject: [PATCH 06/30] oxenstored: use hash table to store socket connections
Currently we use list to store socket connections. This is fine for smaller number of connections. But when we scale up, traveling through a list of hundreds or thousands of connections just to find a single one of them is very low efficient.
This patch replaces the list with a (Unix.file_descr -> Connection.t) hash table.
--- tools/ocaml/xenstored/connections.ml | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
tools/ocaml/xenstored/connections.ml +14 -14
@@ -18,17 +18,17 @@ let debug fmt = Logging.debug "connections" fmt type t = { - mutable anonymous: Connection.t list; + anonymous: (Unix.file_descr, Connection.t) Hashtbl.t; domains: (int, Connection.t) Hashtbl.t; mutable watches: (string, Connection.watch list) Trie.t; } -let create () = { anonymous = []; domains = Hashtbl.create 8; watches = Trie.create () } +let create () = { anonymous = Hashtbl.create 37; domains = Hashtbl.create 37; watches = Trie.create () } let add_anonymous cons fd can_write = let xbcon = Xenbus.Xb.open_fd fd in let con = Connection.create xbcon None in - cons.anonymous <- con :: cons.anonymous + Hashtbl.add cons.anonymous (Xenbus.Xb.get_fd xbcon) con let add_domain cons dom = let xbcon = Xenbus.Xb.open_mmap (Domain.get_interface dom) (fun () -> Domain.notify dom) in
@@ -36,14 +36,14 @@ let add_domain cons dom = Hashtbl.add cons.domains (Domain.get_id dom) con let select cons = - let inset = List.map (fun c -> Connection.get_fd c) cons.anonymous - and outset = List.fold_left (fun l c -> if Connection.has_output c - then Connection.get_fd c :: l - else l) [] cons.anonymous in - inset, outset + Hashtbl.fold + (fun _ con (ins, outs) -> + let fd = Connection.get_fd con in + (fd :: ins, if Connection.has_output con then fd :: outs else outs)) + cons.anonymous ([], []) -let find cons fd = - List.find (fun c -> Connection.get_fd c = fd) cons.anonymous +let find cons = + Hashtbl.find cons.anonymous let find_domain cons id = Hashtbl.find cons.domains id
@@ -55,7 +55,7 @@ let del_watches_of_con con watches = let del_anonymous cons con = try - cons.anonymous <- Utils.list_remove con cons.anonymous; + Hashtbl.remove cons.anonymous (Connection.get_fd con); cons.watches <- Trie.map (del_watches_of_con con) cons.watches; Connection.close con with exn ->
@@ -74,7 +74,7 @@ let iter_domains cons fct = Hashtbl.iter (fun k c -> fct c) cons.domains let iter_anonymous cons fct = - List.iter (fun c -> fct c) (List.rev cons.anonymous) + Hashtbl.iter (fun _ c -> fct c) cons.anonymous let iter cons fct = iter_domains cons fct; iter_anonymous cons fct
@@ -163,10 +163,10 @@ let stats cons = nb_ops_dom := !nb_ops_dom + con_ops; nb_watchs_dom := !nb_watchs_dom + con_watchs; ); - (List.length cons.anonymous, !nb_ops_anon, !nb_watchs_anon, + (Hashtbl.length cons.anonymous, !nb_ops_anon, !nb_watchs_anon, Hashtbl.length cons.domains, !nb_ops_dom, !nb_watchs_dom) let debug cons = - let anonymous = List.map Connection.debug cons.anonymous in + let anonymous = Hashtbl.fold (fun _ con accu -> Connection.debug con :: accu) cons.anonymous [] in let domains = Hashtbl.fold (fun _ con accu -> Connection.debug con :: accu) cons.domains [] in String.concat "" (domains @ anonymous)
Signature · 1 line
2.1.4
From 3595258f4a60dd49a75b6229e623ec478eaf239b Mon Sep 17 00:00:00 2001
From: Zheng Li <[email protected]>
Date: Fri, 24 Mar 2017 17:02:55 +0000
Subject: [PATCH 07/30] oxenstored: enable domain connection indexing based on
eventchn port
Currently in xenstore connection database, we use a hash table of (domid -> connection) to store domain connections. This allows fast indexing based on dom ids.
This patch adds another dimention of fast indexing that is based on eventchn port number. This is useful when doing selective connection processing based on the port numbers of incoming events.
--- tools/ocaml/xenstored/connections.ml | 26 ++++++++++++++++++++++---- tools/ocaml/xenstored/domain.ml | 1 + 2 files changed, 23 insertions(+), 4 deletions(-)
tools/ocaml/xenstored/connections.ml +22 -4
@@ -20,10 +20,16 @@ let debug fmt = Logging.debug "connections" fmt type t = { anonymous: (Unix.file_descr, Connection.t) Hashtbl.t; domains: (int, Connection.t) Hashtbl.t; + ports: (Xeneventchn.t, Connection.t) Hashtbl.t; mutable watches: (string, Connection.watch list) Trie.t; } -let create () = { anonymous = Hashtbl.create 37; domains = Hashtbl.create 37; watches = Trie.create () } +let create () = { + anonymous = Hashtbl.create 37; + domains = Hashtbl.create 37; + ports = Hashtbl.create 37; + watches = Trie.create () +} let add_anonymous cons fd can_write = let xbcon = Xenbus.Xb.open_fd fd in
@@ -33,7 +39,10 @@ let add_anonymous cons fd can_write = let add_domain cons dom = let xbcon = Xenbus.Xb.open_mmap (Domain.get_interface dom) (fun () -> Domain.notify dom) in let con = Connection.create xbcon (Some dom) in - Hashtbl.add cons.domains (Domain.get_id dom) con + Hashtbl.add cons.domains (Domain.get_id dom) con; + match Domain.get_port dom with + | Some p -> Hashtbl.add cons.ports p con; + | None -> () let select cons = Hashtbl.fold
@@ -45,8 +54,11 @@ let select cons = let find cons = Hashtbl.find cons.anonymous -let find_domain cons id = - Hashtbl.find cons.domains id +let find_domain cons = + Hashtbl.find cons.domains + +let find_domain_by_port cons port = + Hashtbl.find cons.ports port let del_watches_of_con con watches = match List.filter (fun w -> Connection.get_con w != con) watches with
@@ -65,6 +77,12 @@ let del_domain cons id = try let con = find_domain cons id in Hashtbl.remove cons.domains id; + (match Connection.get_domain con with + | Some d -> + (match Domain.get_port d with + | Some p -> Hashtbl.remove cons.ports p + | None -> ()) + | None -> ()); cons.watches <- Trie.map (del_watches_of_con con) cons.watches; Connection.close con with exn ->
tools/ocaml/xenstored/domain.ml +1 -0
@@ -35,6 +35,7 @@ let get_id domain = domain.id let get_interface d = d.interface let get_mfn d = d.mfn let get_remote_port d = d.remote_port +let get_port d = d.port let is_bad_domain domain = domain.bad_client let mark_as_bad domain = domain.bad_client <- true
Signature · 1 line
2.1.4
From b10466d49d925e5c9bb360847e92a8cb7f899ac9 Mon Sep 17 00:00:00 2001
From: Zheng Li <[email protected]>
Date: Fri, 24 Mar 2017 17:03:31 +0000
Subject: [PATCH 08/30] oxenstored: only process domain connections that notify
us by events
Currently, upon receiving an event, oxenstored will always scan/process all the domain connections (xs rings), disregarding which domain sent that event. This is rather costy and inefficient. It also shadows and indulges client for not correctly communicating with us on message/space availability.
With this patch, oxenstore will only scan/process the domain connections that have correctly notified us by events or have IO actions leftover from previous communication.
--- tools/ocaml/xenstored/connection.ml | 4 ++++ tools/ocaml/xenstored/connections.ml | 9 ++++----- tools/ocaml/xenstored/xenstored.ml | 13 ++++++++++--- 3 files changed, 18 insertions(+), 8 deletions(-)
tools/ocaml/xenstored/connection.ml +4 -0
@@ -223,10 +223,14 @@ let pop_in con = Xenbus.Xb.get_in_packet con.xb let has_more_input con = Xenbus.Xb.has_more_input con.xb let has_output con = Xenbus.Xb.has_output con.xb +let has_old_output con = Xenbus.Xb.has_old_output con.xb let has_new_output con = Xenbus.Xb.has_new_output con.xb let peek_output con = Xenbus.Xb.peek_output con.xb let do_output con = Xenbus.Xb.output con.xb +let has_more_work con = + has_more_input con || not (has_old_output con) && has_new_output con + let incr_ops con = con.stat_nb_ops <- con.stat_nb_ops + 1 let mark_symbols con =
tools/ocaml/xenstored/connections.ml +4 -5
@@ -98,11 +98,10 @@ let iter cons fct = iter_domains cons fct; iter_anonymous cons fct let has_more_work cons = - Hashtbl.fold (fun id con acc -> - if Connection.has_more_input con then - con :: acc - else - acc) cons.domains [] + Hashtbl.fold + (fun id con acc -> + if Connection.has_more_work con then con :: acc else acc) + cons.domains [] let key_of_str path = if path.[0] = '@'
tools/ocaml/xenstored/xenstored.ml +10 -3
@@ -57,7 +57,10 @@ let process_domains store cons domains = let con = Connections.find_domain cons (Domain.get_id domain) in Process.do_input store cons domains con; Process.do_output store cons domains con in - Domains.iter domains do_io_domain + List.iter + (fun c -> + match Connection.get_domain c with + | Some d -> do_io_domain d | _ -> ()) let sigusr1_handler store = try
@@ -303,6 +306,7 @@ let _ = Connections.add_anonymous cons cfd can_write and handle_eventchn fd = let port = Event.pending eventchn in + debug "pending port %d" (Xeneventchn.to_int port); finally (fun () -> if Some port = eventchn.Event.virq_port then ( let (notify, deaddom) = Domains.cleanup xc domains in
@@ -310,7 +314,10 @@ let _ = if deaddom <> [] || notify then Connections.fire_spec_watches cons "@releaseDomain" ) - ) (fun () -> Event.unmask eventchn port); + else + let c = Connections.find_domain_by_port cons port in + process_domains store cons domains [c] + ) (fun () -> Event.unmask eventchn port) and do_if_set fd set fct = if List.mem fd set then fct fd in
@@ -380,7 +387,7 @@ let _ = process_special_fds sfds; if List.length cfds > 0 || List.length wset > 0 then process_connection_fds store cons domains cfds wset; - process_domains store cons domains + process_domains store cons domains mw in while not !quit
Signature · 1 line
2.1.4
From af37817fe5c03f17855b27f7b768783797318987 Mon Sep 17 00:00:00 2001
From: Zheng Li <[email protected]>
Date: Fri, 24 Mar 2017 17:04:23 +0000
Subject: [PATCH 09/30] oxenstored: add a safe net mechanism for existing
ill-behaved clients
In previous commit, we moved from exhaustively scanning all domain connections to only processing those have correctly notified us by events. The benefits are not only efficiency but also correctness, because it could potentially block an ill-behaved client and have it waiting on its own mistake. If someone makes a mistake on this when developing a piece of code, he/she would immediately notice the problem (as the process being blocked), so that he/she could fix it rightaway before anything else. Note that the chances of making such mistakes are rare in reality, because most client code would use the libxenstore library (which has all the notification logic built in correctly) instead of having to implement raw accessing from scratch.
On the other hand, we did notice that there were some legacy code that didn't do the notification correctly. As some code might be still running in wild, it would be bad if they break by this change (e.g. after an upgrade). This patch introduces a safe net mechanism to ensure ill-behaved clients continue to work, but still retain most of the performance benefits here.
* We add a checker to still scan all the rings periodically, so that we can still pick up these messages at an acceptable frequency.
* Internally, we introduce an io_credit concept for domain connections. It represents the rounds of ring scan we are going to perform on a domain connection. For well-behaved connections, this value is changing between 0 and 1; but for connections detected as ill-behaved, we'll bump its credit to a high value so that we'll unconditionally scan its ring for the next $n$ rounds. This way, the client won't hiccupped by the interval between checker's running (especially during periods when it continously interacts with oxenstored); and oxenstored doesn't have to keep scanning these rings indefinitely (with the credit running out), as they are usually quite most of the time.
* We log an message when a domain connection is suspected as ill-behaved. Enable [info] level logging if you want/need to see it in action. Note that this information won't be accurate, as false positives are possible due to time window (e.g. we detect a client has written to the ring and we get no notificiation from it for the time being, but still the notification could potentially arrive at some time later). It's no harm to give a domain connection extra credit though.
--- tools/ocaml/xenstored/domain.ml | 11 ++++- tools/ocaml/xenstored/oxenstored.conf | 3 ++ tools/ocaml/xenstored/xenstored.ml | 76 ++++++++++++++++++++++++++--------- 3 files changed, 69 insertions(+), 21 deletions(-)
tools/ocaml/xenstored/domain.ml +10 -1
@@ -28,6 +28,9 @@ type t = eventchn: Event.t; mutable port: Xeneventchn.t option; mutable bad_client: bool; + mutable io_credit: int; (* the rounds of ring process left to do, default is 0, + usually set to 1 when there is work detected, could + also set to n to give "lazy" clients extra credit *) } let get_path dom = "/local/domain/" ^ (sprintf "%u" dom.id)
@@ -40,6 +43,11 @@ let get_port d = d.port let is_bad_domain domain = domain.bad_client let mark_as_bad domain = domain.bad_client <- true +let get_io_credit domain = domain.io_credit +let set_io_credit ?(n=1) domain = domain.io_credit <- max 0 n +let incr_io_credit domain = domain.io_credit <- domain.io_credit + 1 +let decr_io_credit domain = domain.io_credit <- max 0 (domain.io_credit - 1) + let string_of_port = function | None -> "None" | Some x -> string_of_int (Xeneventchn.to_int x)
@@ -74,7 +82,8 @@ let make id mfn remote_port interface eventchn = { interface = interface; eventchn = eventchn; port = None; - bad_client = false + bad_client = false; + io_credit = 0; } let is_dom0 d = d.id = 0
tools/ocaml/xenstored/oxenstored.conf +3 -0
@@ -33,3 +33,6 @@ persistent = false # acesss-log-nb-chars = 180 # access-log-special-ops = false +# Perodically scanning all the rings as a safenet for lazy clients. +# Define the interval in seconds, set to negative to disable. +# ring-scan-interval = 20
tools/ocaml/xenstored/xenstored.ml +56 -20
132 lines not on this page · raw message
Signature · 1 line
2.1.4
From 3d3b87010ff9ede82cfb79aee445a30d2c9f88b8 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 17:40:00 +0000
Subject: [PATCH 10/30] oxenstored: refactor putting response on wire
Previously, the functions reply_{ack,data,data_or_ack} and input_handle_error put the response on the wire by invoking Connection.send_{ack,reply,error}.
Instead, these functions now return a value indicating what needs to be put on the wire, and that action is done by a send_response function called afterwards.
This refactoring gives us a chance to store the value of the response, useful for replaying transactions.
--- tools/ocaml/xenstored/Makefile | 1 + tools/ocaml/xenstored/packet.ml | 4 ++++ tools/ocaml/xenstored/process.ml | 34 ++++++++++++++++++++++++---------- 3 files changed, 29 insertions(+), 10 deletions(-) create mode 100644 tools/ocaml/xenstored/packet.ml
tools/ocaml/xenstored/Makefile +1 -0
@@ -17,6 +17,7 @@ OBJS = define \ stdext \ trie \ config \ + packet \ logging \ quota \ perms \
tools/ocaml/xenstored/packet.ml new file +4 -0
@@ -0,0 +1,4 @@ +type response = + | Ack of (unit -> unit) (* function is the action to execute after sending the ack *) + | Reply of string + | Error of string
tools/ocaml/xenstored/process.ml +24 -10
@@ -126,8 +126,7 @@ let do_watch con t rid domains cons data = | _ -> raise Invalid_Cmd_Args in let watch = Connections.add_watch cons con node token in - Connection.send_ack con (Transaction.get_id t) rid Xenbus.Xb.Op.Watch; - Connection.fire_single_watch watch + Packet.Ack (fun () -> Connection.fire_single_watch watch) let do_unwatch con t domains cons data = let (node, token) =
@@ -284,20 +283,32 @@ let do_set_target con t domains cons data = | _ -> raise Invalid_Cmd_Args (*------------- Generic handling of ty ------------------*) +let send_response ty con t rid response = + match response with + | Packet.Ack f -> + Connection.send_ack con (Transaction.get_id t) rid ty; + (* Now do any necessary follow-up actions *) + f () + | Packet.Reply ret -> + Connection.send_reply con (Transaction.get_id t) rid ty ret + | Packet.Error e -> + Connection.send_error con (Transaction.get_id t) rid e + let reply_ack fct ty con t rid doms cons data = fct con t doms cons data; - Connection.send_ack con (Transaction.get_id t) rid ty; - if Transaction.get_id t = Transaction.none then - process_watch (Transaction.get_ops t) cons + Packet.Ack (fun () -> + if Transaction.get_id t = Transaction.none then + process_watch (Transaction.get_ops t) cons + ) let reply_data fct ty con t rid doms cons data = let ret = fct con t doms cons data in - Connection.send_reply con (Transaction.get_id t) rid ty ret + Packet.Reply ret let reply_data_or_ack fct ty con t rid doms cons data = match fct con t doms cons data with - | Some ret -> Connection.send_reply con (Transaction.get_id t) rid ty ret - | None -> Connection.send_ack con (Transaction.get_id t) rid ty + | Some ret -> Packet.Reply ret + | None -> Packet.Ack (fun () -> ()) let reply_none fct ty con t rid doms cons data = (* let the function reply *)
@@ -329,7 +340,7 @@ let function_of_type ty = let input_handle_error ~cons ~doms ~fct ~ty ~con ~t ~rid ~data = let reply_error e = - Connection.send_error con (Transaction.get_id t) rid e in + Packet.Error e in try fct ty con t rid doms cons data with
@@ -362,7 +373,10 @@ let process_packet ~store ~cons ~doms ~con ~tid ~rid ~ty ~data = else Connection.get_transaction con tid in - input_handle_error ~cons ~doms ~fct ~ty ~con ~t ~rid ~data; + let response = input_handle_error ~cons ~doms ~fct ~ty ~con ~t ~rid ~data in + + (* Put the response on the wire *) + send_response ty con t rid response with exn -> error "process packet: %s" (Printexc.to_string exn); Connection.send_error con tid rid "EIO"
Signature · 1 line
2.1.4
From 7b5f1b6957edbcf514a74a38b6d5d810b3d9dcda Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 17:40:08 +0000
Subject: [PATCH 11/30] oxenstored: remove some unused parameters
--- tools/ocaml/xenstored/process.ml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
tools/ocaml/xenstored/process.ml +7 -7
@@ -119,7 +119,7 @@ let do_getperms con t domains cons data = let perms = Transaction.getperms t (Connection.get_perm con) path in Perms.Node.to_string perms ^ "\000" -let do_watch con t rid domains cons data = +let do_watch con t domains cons data = let (node, token) = match (split None '\000' data) with | [node; token; ""] -> node, token
@@ -294,25 +294,25 @@ let send_response ty con t rid response = | Packet.Error e -> Connection.send_error con (Transaction.get_id t) rid e -let reply_ack fct ty con t rid doms cons data = +let reply_ack fct con t doms cons data = fct con t doms cons data; Packet.Ack (fun () -> if Transaction.get_id t = Transaction.none then process_watch (Transaction.get_ops t) cons ) -let reply_data fct ty con t rid doms cons data = +let reply_data fct con t doms cons data = let ret = fct con t doms cons data in Packet.Reply ret -let reply_data_or_ack fct ty con t rid doms cons data = +let reply_data_or_ack fct con t doms cons data = match fct con t doms cons data with | Some ret -> Packet.Reply ret | None -> Packet.Ack (fun () -> ()) -let reply_none fct ty con t rid doms cons data = +let reply_none fct con t doms cons data = (* let the function reply *) - fct con t rid doms cons data + fct con t doms cons data let function_of_type ty = match ty with
@@ -342,7 +342,7 @@ let input_handle_error ~cons ~doms ~fct ~ty ~con ~t ~rid ~data = let reply_error e = Packet.Error e in try - fct ty con t rid doms cons data + fct con t doms cons data with | Define.Invalid_path -> reply_error "EINVAL" | Define.Already_exist -> reply_error "EEXIST"
Signature · 1 line
2.1.4
From 37102e74b4e974348d62082d6f68eb4313207f27 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 17:40:27 +0000
Subject: [PATCH 12/30] oxenstored: refactor request processing
Encapsulate the request in a record that is passed from do_input to process_packet and input_handle_error.
This will be helpful when keeping track of the requests made as part of a transaction.
--- tools/ocaml/xenstored/packet.ml | 7 +++++++ tools/ocaml/xenstored/process.ml | 15 ++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-)
tools/ocaml/xenstored/packet.ml +7 -0
@@ -1,3 +1,10 @@ +type request = { + tid: int; + rid: int; + ty: Xenbus.Xb.Op.operation; + data: string; +} + type response = | Ack of (unit -> unit) (* function is the action to execute after sending the ack *) | Reply of string
tools/ocaml/xenstored/process.ml +10 -5
@@ -338,11 +338,11 @@ let function_of_type ty = | Xenbus.Xb.Op.Invalid -> reply_ack do_error | _ -> reply_ack do_error -let input_handle_error ~cons ~doms ~fct ~ty ~con ~t ~rid ~data = +let input_handle_error ~cons ~doms ~fct ~con ~t ~req = let reply_error e = Packet.Error e in try - fct con t doms cons data + fct con t doms cons req.Packet.data with | Define.Invalid_path -> reply_error "EINVAL" | Define.Already_exist -> reply_error "EEXIST"
@@ -364,7 +364,10 @@ let input_handle_error ~cons ~doms ~fct ~ty ~con ~t ~rid ~data = (** * Nothrow guarantee. *) -let process_packet ~store ~cons ~doms ~con ~tid ~rid ~ty ~data = +let process_packet ~store ~cons ~doms ~con ~req = + let ty = req.Packet.ty in + let tid = req.Packet.tid in + let rid = req.Packet.rid in try let fct = function_of_type ty in let t =
@@ -373,7 +376,7 @@ let process_packet ~store ~cons ~doms ~con ~tid ~rid ~ty ~data = else Connection.get_transaction con tid in - let response = input_handle_error ~cons ~doms ~fct ~ty ~con ~t ~rid ~data in + let response = input_handle_error ~cons ~doms ~fct ~con ~t ~req in (* Put the response on the wire *) send_response ty con t rid response
@@ -401,11 +404,13 @@ let do_input store cons doms con = if newpacket then ( let packet = Connection.pop_in con in let tid, rid, ty, data = Xenbus.Xb.Packet.unpack packet in + let req = {Packet.tid; Packet.rid; Packet.ty; Packet.data} in + (* As we don't log IO, do not call an unnecessary sanitize_data info "[%s] -> [%d] %s \"%s\"" (Connection.get_domstr con) tid (Xenbus.Xb.Op.to_string ty) (sanitize_data data); *) - process_packet ~store ~cons ~doms ~con ~tid ~rid ~ty ~data; + process_packet ~store ~cons ~doms ~con ~req; write_access_log ~ty ~tid ~con ~data; Connection.incr_ops con; )
Signature · 1 line
2.1.4
From 7f3129ec15c1c459962401d2edcd9e693c698a09 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 17:40:35 +0000
Subject: [PATCH 13/30] oxenstored: keep track of each transaction's operations
A list of (request, response) pairs from the operations performed within the transaction will be useful to support transaction replay.
Since this consumes memory, the number of requests per transaction must not be left unbounded. Hence a new quota for this is introduced. This quota, configured via the configuration key 'quota-maxrequests', limits the size of transactions initiated by domUs.
After the maximum number of requests has been exhausted, any further requests will result in EQUOTA errors. The client may then choose to end the transaction; a successful commit will result in the retention of only the prior requests.
--- tools/ocaml/xenstored/define.ml | 1 + tools/ocaml/xenstored/oxenstored.conf | 1 + tools/ocaml/xenstored/process.ml | 13 +++++++++++-- tools/ocaml/xenstored/transaction.ml | 21 +++++++++++++++------ tools/ocaml/xenstored/xenstored.ml | 1 + 5 files changed, 29 insertions(+), 8 deletions(-)
tools/ocaml/xenstored/define.ml +1 -0
@@ -27,6 +27,7 @@ let default_config_dir = "/etc/xen" let maxwatch = ref (50) let maxtransaction = ref (20) +let maxrequests = ref (-1) (* maximum requests per transaction *) let domid_self = 0x7FF0
tools/ocaml/xenstored/oxenstored.conf +1 -0
@@ -18,6 +18,7 @@ quota-maxentity = 1000 quota-maxsize = 2048 quota-maxwatch = 100 quota-transaction = 10 +quota-maxrequests = 1024 # Activate filed base backend persistent = false
tools/ocaml/xenstored/process.ml +11 -2
@@ -155,7 +155,7 @@ let do_transaction_end con t domains cons data = if not success then raise Transaction_again; if commit then - process_watch (List.rev (Transaction.get_ops t)) cons + process_watch (List.rev (Transaction.get_paths t)) cons let do_introduce con t domains cons data = if not (Connection.is_dom0 con)
@@ -298,7 +298,7 @@ let reply_ack fct con t doms cons data = fct con t doms cons data; Packet.Ack (fun () -> if Transaction.get_id t = Transaction.none then - process_watch (Transaction.get_ops t) cons + process_watch (Transaction.get_paths t) cons ) let reply_data fct con t doms cons data =
@@ -378,6 +378,15 @@ let process_packet ~store ~cons ~doms ~con ~req = in let response = input_handle_error ~cons ~doms ~fct ~con ~t ~req in + let response = try + if tid <> Transaction.none then + (* Remember the request and response for this operation in case we need to replay the transaction *) + Transaction.add_operation ~perm:(Connection.get_perm con) t req response; + response + with Quota.Limit_reached -> + Packet.Error "EQUOTA" + in + (* Put the response on the wire *) send_response ty con t rid response with exn ->
tools/ocaml/xenstored/transaction.ml +15 -6
@@ -75,7 +75,8 @@ type t = { ty: ty; store: Store.t; quota: Quota.t; - mutable ops: (Xenbus.Xb.Op.operation * Store.Path.t) list; + mutable paths: (Xenbus.Xb.Op.operation * Store.Path.t) list; + mutable operations: (Packet.request * Packet.response) list; mutable read_lowpath: Store.Path.t option; mutable write_lowpath: Store.Path.t option; }
@@ -86,16 +87,24 @@ let make id store = ty = ty; store = if id = none then store else Store.copy store; quota = Quota.copy store.Store.quota; - ops = []; + paths = []; + operations = []; read_lowpath = None; write_lowpath = None; } let get_id t = match t.ty with No -> none | Full (id, _, _) -> id let get_store t = t.store -let get_ops t = t.ops - -let add_wop t ty path = t.ops <- (ty, path) :: t.ops +let get_paths t = t.paths + +let add_wop t ty path = t.paths <- (ty, path) :: t.paths +let add_operation ~perm t request response = + if !Define.maxrequests >= 0 + && not (Perms.Connection.is_dom0 perm) + && List.length t.operations >= !Define.maxrequests + then raise Quota.Limit_reached; + t.operations <- (request, response) :: t.operations +let get_operations t = List.rev t.operations let set_read_lowpath t path = t.read_lowpath <- get_lowest path t.read_lowpath let set_write_lowpath t path = t.write_lowpath <- get_lowest path t.write_lowpath
@@ -141,7 +150,7 @@ let getperms t perm path = r let commit ~con t = - let has_write_ops = List.length t.ops > 0 in + let has_write_ops = List.length t.paths > 0 in let has_coalesced = ref false in let has_commited = match t.ty with
tools/ocaml/xenstored/xenstored.ml +1 -0
@@ -95,6 +95,7 @@ let parse_config filename = ("quota-transaction", Config.Set_int Define.maxtransaction); ("quota-maxentity", Config.Set_int Quota.maxent); ("quota-maxsize", Config.Set_int Quota.maxsize); + ("quota-maxrequests", Config.Set_int Define.maxrequests); ("test-eagain", Config.Set_bool Transaction.test_eagain); ("persistent", Config.Set_bool Disk.enable); ("xenstored-log-file", Config.String Logging.set_xenstored_log_destination);
Signature · 1 line
2.1.4
From c8a7bd3fff923dd7747a45aa5f5b3222921f9728 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 17:53:03 +0000
Subject: [PATCH 14/30] oxenstored: move functions that process simple
operations
Separate the functions which process operations that can be done as part of a transaction. Specifically, these operations are: read, write, rm, getperms, setperms, getdomainpath, directory, mkdir.
Also split function_of_type into two functions: one for processing the simple operations and one for processing the rest.
This will help allow replay of transactions, allowing us to invoke the functions that process the simple operations as part of the processing of transaction_end.
Backporting to 4.5:
- Removed references to Reset_watches, which was introduced in 4.6.
--- tools/ocaml/xenstored/process.ml | 220 +++++++++++++++++++++------------------ 1 file changed, 119 insertions(+), 101 deletions(-)
tools/ocaml/xenstored/process.ml +119 -101
247 lines not on this page · raw message
Signature · 1 line
2.1.4
From ce0ca538ccc5e59b9407f983babfb0dd098e1a0b Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 17:54:17 +0000
Subject: [PATCH 15/30] oxenstored: replay transaction upon conflict
The existing transaction merge algorithm keeps track of the least upper bound (longest common prefix) of all the nodes which have been read and written, and will re-combine two stores which have disjoint upper bounds. This works well for small transactions but causes unnecessary conflicts for ones that span a large subtree, such as the following ones used by the xapi toolstack:
* VM start: creates /vm/... /vss/... /local/domain/... The least upper bound of this transaction is / and so all these transactions conflict with everything.
* Device hotplug: creates /local/domain/0/... /local/domain/n/... The least upper bound of this transaction is /local/domain so all these transactions conflict with each other.
If the existing merge algorithm cannot merge and commit, we attempt a /replay/ of the failed transaction against the new store.
When we replay the requests we check whether the response sent to the client is the same as during the first attempt at the transaction. If the responses are all the same then the transaction replay can be committed. If any differ then the transaction replay must be aborted and the client must retry.
This algorithm uses the intuition that the transactions made by the toolstack are designed to be for separate domains, and should fundamentally not conflict in the sense that they don't read or write any shared keys. By replaying the transaction on the server side we do what the client would have to do anyway, only we can do it quickly without allowing any other requests to interfere.
Performing 300 parallel simulated VM start and shutdowns without this code:
300 parallel starts and shutdowns: 268.92
Performing 300 parallel simulated VM start and shutdowns with this code:
300 parallel starts and shutdowns: 3.80
--- tools/ocaml/xenstored/connection.ml | 5 ++++- tools/ocaml/xenstored/packet.ml | 5 +++++ tools/ocaml/xenstored/process.ml | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-)
tools/ocaml/xenstored/connection.ml +4 -1
@@ -212,7 +212,10 @@ let end_transaction con tid commit = let trans = Hashtbl.find con.transactions tid in Hashtbl.remove con.transactions tid; Logging.end_transaction ~tid ~con:(get_domstr con); - if commit then Transaction.commit ~con:(get_domstr con) trans else true + match commit with + | None -> true + | Some transaction_replay_f -> + Transaction.commit ~con:(get_domstr con) trans || transaction_replay_f con trans let get_transaction con tid = Hashtbl.find con.transactions tid
tools/ocaml/xenstored/packet.ml +5 -0
@@ -9,3 +9,8 @@ type response = | Ack of (unit -> unit) (* function is the action to execute after sending the ack *) | Reply of string | Error of string + +let response_equal a b = + match (a, b) with + | (Ack _, Ack _) -> true (* just consider the response, not the post-response action *)
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From c89859c4735ce717d4115a4f056c9565363b05a1 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 17:54:28 +0000
Subject: [PATCH 16/30] oxenstored: log request and response during transaction
replay
During a transaction replay, the replayed requests and the new responses are logged in the same way as the original requests and the original responses.
--- tools/ocaml/xenstored/process.ml | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 88f59d22230b304ac861cea9759bd8861a6c3867 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 17:54:35 +0000
Subject: [PATCH 17/30] oxenstored: allow compilation prior to OCaml 3.12.0
Commit 363ae55c8 used an OCaml feature called record field punning. This broke the build on compilers prior to OCaml 3.12.0.
This patch makes no semantic change but now uses backwards-compatible syntax.
--- tools/ocaml/xenstored/process.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 4782ccf2f68941fa591cfa72275b678613314fea Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Tue, 14 Mar 2017 12:15:52 +0000
Subject: [PATCH 18/30] oxenstored: comments explaining some variables
It took a while of reading and reasoning to work out what these are for, so here are comments to make life easier for everyone reading this code in future.
--- tools/ocaml/xenstored/store.ml | 1 + tools/ocaml/xenstored/transaction.ml | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 6118099bec07d77bfd73a032d8b411cab29a9f3e Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Tue, 14 Mar 2017 12:15:52 +0000
Subject: [PATCH 19/30] oxenstored: handling of domain conflict-credit
This commit gives each domain a conflict-credit variable, which will later be used for limiting how often a domain can cause other domain's transaction-commits to fail.
This commit also provides functions and data for manipulating domains and their conflict-credit, and checking whether they have credit.
--- tools/ocaml/xenstored/connection.ml | 5 ++ tools/ocaml/xenstored/define.ml | 3 + tools/ocaml/xenstored/domain.ml | 11 +++- tools/ocaml/xenstored/domains.ml | 103 +++++++++++++++++++++++++++++++++- tools/ocaml/xenstored/oxenstored.conf | 32 +++++++++++ tools/ocaml/xenstored/transaction.ml | 2 + tools/ocaml/xenstored/xenstored.ml | 2 + 7 files changed, 154 insertions(+), 4 deletions(-)
tools/ocaml/xenstored/domains.ml +101 -2
103 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From c72a4976b66887b12126810d240fdd2d3f74ec0a Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Tue, 14 Mar 2017 12:15:52 +0000
Subject: [PATCH 20/30] oxenstored: ignore domains with no conflict-credit
When processing connections, skip those from domains with no remaining conflict-credit.
Also, issue a point of conflict-credit at regular intervals, the period being set by the configuration option "conflict-max-history- seconds". When issuing conflict-credit, we give a point either to every domain at once (one each) or only to the single domain at the front of the queue, depending on the configuration option "conflict-rate-limit-is-aggregate".
--- tools/ocaml/xenstored/connections.ml | 14 ++++---- tools/ocaml/xenstored/define.ml | 1 + tools/ocaml/xenstored/domains.ml | 4 +-- tools/ocaml/xenstored/oxenstored.conf | 2 +- tools/ocaml/xenstored/xenstored.ml | 65 ++++++++++++++++++++++++++--------- 5 files changed, 60 insertions(+), 26 deletions(-)
tools/ocaml/xenstored/xenstored.ml +48 -17
65 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 38e49e8b7d270ce641cfaee649f24e506a2b3ff8 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Tue, 14 Mar 2017 12:17:38 +0000
Subject: [PATCH 21/30] oxenstored: add transaction info relevant to
history-tracking
Specifically:
* retain the original store (not just the root) in full transactions
* store commit count at the time of the start of the transaction
--- tools/ocaml/xenstored/process.ml | 2 +- tools/ocaml/xenstored/transaction.ml | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 4d0479387d5abd326810a0e6af17cbed50641ca9 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Tue, 14 Mar 2017 13:20:07 +0000
Subject: [PATCH 22/30] oxenstored: support commit history tracking
Add ability to track xenstore tree operations -- either non-transactional operations or committed transactions.
For now, the call to actually retain commits is commented out because history can grow without bound.
For now, we call record_commit for all non-transactional operations. A subsequent patch will make it retain only the ones with side-effects.
--- tools/ocaml/xenstored/Makefile | 1 + tools/ocaml/xenstored/history.ml | 43 ++++++++++++++++++++++++++++++++++++++ tools/ocaml/xenstored/process.ml | 24 +++++++++++++++++++-- tools/ocaml/xenstored/xenstored.ml | 1 + 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 tools/ocaml/xenstored/history.ml
tools/ocaml/xenstored/history.ml new file +43 -0
43 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From b05fcb4ee2e09991ad43226370cac2a38b41de82 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 14:20:33 +0000
Subject: [PATCH 23/30] oxenstored: only record operations with side-effects in
history
There is no need to record "read" operations as they will never cause another transaction to fail.
Backport 4.6 -> 4.5 by removing reference to XS_RESET_WATCHES.
--- tools/ocaml/xenstored/process.ml | 46 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-)
tools/ocaml/xenstored/process.ml +42 -4
46 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From c9fb09ca7384fa1952de7a470c52d93c5b4d2eea Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Thu, 23 Mar 2017 14:25:16 +0000
Subject: [PATCH 24/30] oxenstored: discard old commit-history on txn end
The history of commits is to be used for working out which historical commit(s) (including atomic writes) caused conflicts with a currently-failing commit of a transaction. Any commit that was made before the current transaction started cannot be relevant. Therefore we never need to keep history from before the start of the longest-running transaction that is open at any given time: whenever a transaction ends (with or without a commit) then if it was the longest-running open transaction we can delete history up until start of the the next-longest-running open transaction.
Some transactions might stay open for a very long time, so if any transaction exceeds conflict_max_history_seconds then we remove it from consideration in this context, and will not guarantee to keep remembering about historical commits made during such a transaction.
We implement this by keeping a list of all open transactions that have not been open too long. When a transaction ends, we remove it from the list, along with any that have been open longer than the maximum; then we delete any history from before the start of the longest-running transaction remaining in the list.
--- tools/ocaml/xenstored/history.ml | 17 +++++++++++++++++ tools/ocaml/xenstored/process.ml | 4 ++-- tools/ocaml/xenstored/transaction.ml | 29 +++++++++++++++++++++++++---- 3 files changed, 44 insertions(+), 6 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From dd5758b85234356ad03615160433c0b0347a4aec Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Mon, 27 Mar 2017 08:58:29 +0000
Subject: [PATCH 25/30] oxenstored: track commit history
Since the list of historic activity cannot grow without bound, it is safe to use this to track commits.
--- tools/ocaml/xenstored/process.ml | 5 ----- 1 file changed, 5 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From a6edf151e5eb4f401745e13a803e713accd22bee Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 14:28:16 +0000
Subject: [PATCH 26/30] oxenstored: blame the connection that caused a
transaction conflict
Blame each connection found to have made a commit that would cause this transaction to fail. Each blamed connection is penalised by having its conflict-credit decremented.
Note the change in semantics for the replay function: we no longer stop after finding the first operation that can't be replayed. This allows us to identify all operations that conflicted with this transaction, not just the one that conflicted first.
v1 Reviewed-by: Christian Lindig <[email protected]>
Changes since v1:
* use correct log levels for informational messages
Changes since v2:
* fix the blame algorithm and improve logging (fix was reviewed by Jonathan Davies)
--- tools/ocaml/xenstored/history.ml | 12 ++++++++++ tools/ocaml/xenstored/process.ml | 50 ++++++++++++++++++++++++++++++++-------- 2 files changed, 52 insertions(+), 10 deletions(-)
tools/ocaml/xenstored/process.ml +40 -10
50 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 0c7841d03e182585fcb9444b4799f432e2a444cb Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Thu, 23 Mar 2017 19:06:54 +0000
Subject: [PATCH 27/30] oxenstored: allow self-conflicts
We already avoid inter-domain conflicts but now allow intra-domain conflicts. Although there are no known practical examples of a domain that might perform operations that conflict with its own transactions, this is conceivable, so here we avoid changing those semantics unnecessarily.
When a transaction commit fails with a conflict and we look through the history of commits to see which connection(s) to blame, ignore historical commits that were made by the same connection as the failing commit.
--- tools/ocaml/xenstored/history.ml | 3 ++- tools/ocaml/xenstored/process.ml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From f44d628a0101d4c5318b3b14d7c19ace10a18a61 Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Fri, 24 Mar 2017 16:16:10 +0000
Subject: [PATCH 28/30] oxenstored: do not commit read-only transactions
The packet telling us to end the transaction has always carried an argument telling us whether to commit.
If the transaction made no modifications to the tree, now we ignore that argument and do not commit: it is just a waste of effort.
This makes read-only transactions immune to conflicts, and means that we do not need to store any of their details in the history that is used for assigning blame for conflicts.
We count a transaction as a read-only transaction only if it contains no operations that modified the tree.
This means that (for example) a transaction that creates a new node then deletes it would NOT count as read-only, even though it makes no change overall. A more sophisticated algorithm could judge the transaction based on comparison of its initial and final states, but this would add complexity and computational cost.
--- tools/ocaml/xenstored/process.ml | 1 + tools/ocaml/xenstored/transaction.ml | 1 + 2 files changed, 2 insertions(+)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From b0c7a48af6d0b0dedf638bef6cf166c245057229 Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Fri, 24 Mar 2017 19:55:03 +0000
Subject: [PATCH 29/30] oxenstored: don't wake to issue no conflict-credit
In the main loop, when choosing the timeout for the select function call, we were setting it so as to wake up to issue conflict-credit to any domains that could accept it. When xenstore is idle, this would mean waking up every 50ms (by default) to do no work. With this commit, we check whether any domain is below its cap, and if not then we set the timeout for longer (the same timeout as before the conflict-protection feature was added).
--- tools/ocaml/xenstored/domains.ml | 51 ++++++++++++++++++++++++++++++-------- tools/ocaml/xenstored/xenstored.ml | 5 +++- 2 files changed, 44 insertions(+), 12 deletions(-)
tools/ocaml/xenstored/domains.ml +40 -11
51 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From cc5c2188f39bd707fd8b29df5d488c47aab189ca Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Mon, 27 Mar 2017 14:36:34 +0100
Subject: [PATCH 30/30] oxenstored transaction conflicts: improve logging
For information related to transaction conflicts, potentially frequent logging at "info" priority has been changed to "debug" priority, and once per two minutes there is an "info" priority summary.
Additional detailed logging has been added at "debug" priority.
--- tools/ocaml/xenstored/domain.ml | 8 ++++++++ tools/ocaml/xenstored/domains.ml | 5 +++++ tools/ocaml/xenstored/process.ml | 6 +++++- tools/ocaml/xenstored/transaction.ml | 5 +++++ tools/ocaml/xenstored/xenstored.ml | 6 ++++++ 5 files changed, 29 insertions(+), 1 deletion(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 26b15d4eb7ac71fcab28a7fca664afa0549c135c Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Tue, 28 Mar 2017 18:57:52 +0100
Subject: [PATCH 31/30] oxenstored: trim history in the frequent_ops function
We were trimming the history of commits only at the end of each transaction (regardless of how it ended).
Therefore if non-transactional writes were being made but no transactions were being ended, the history would grow indefinitely. Now we trim the history at regular intervals.
--- tools/ocaml/xenstored/history.ml | 6 +++--- tools/ocaml/xenstored/transaction.ml | 8 ++++++-- tools/ocaml/xenstored/xenstored.ml | 1 + 3 files changed, 10 insertions(+), 5 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.9.5
From 62fbfaa1c2a8256cd8eebde43f36fe293037a731 Mon Sep 17 00:00:00 2001
From: Ian Jackson <[email protected]>
Date: Sat, 18 Mar 2017 16:44:46 +0000
Subject: [PATCH 01/23] xenstored: apply a write transaction rate limit
This avoids a rogue client being about to stall another client (eg the toolstack) indefinitely.
This is XSA-206.
--- tools/xenstore/Makefile | 3 +- tools/xenstore/xenstored_core.c | 9 ++ tools/xenstore/xenstored_core.h | 6 + tools/xenstore/xenstored_domain.c | 215 +++++++++++++++++++++++++++++++++ tools/xenstore/xenstored_domain.h | 25 ++++ tools/xenstore/xenstored_transaction.c | 5 + 6 files changed, 262 insertions(+), 1 deletion(-)
tools/xenstore/xenstored_domain.c +215 -0
215 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 0cc3c9826bba9af86ae25e082f55e70aec713628 Mon Sep 17 00:00:00 2001
From: Ian Jackson <[email protected]>
Date: Thu, 23 Mar 2017 17:05:11 +0000
Subject: [PATCH 02/23] xenstored: Log when the write transaction rate limit
bites
--- tools/xenstore/xenstored_core.c | 1 + tools/xenstore/xenstored_domain.c | 25 +++++++++++++++++++++++++ tools/xenstore/xenstored_domain.h | 2 ++ 3 files changed, 28 insertions(+)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 0dcad769130f4e7bae2a6d07f9248d54e12b7ae6 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 17:05:22 +0000
Subject: [PATCH 03/23] oxenstored: refactor putting response on wire
Previously, the functions reply_{ack,data,data_or_ack} and input_handle_error put the response on the wire by invoking Connection.send_{ack,reply,error}.
Instead, these functions now return a value indicating what needs to be put on the wire, and that action is done by a send_response function called afterwards.
This refactoring gives us a chance to store the value of the response, useful for replaying transactions.
--- tools/ocaml/xenstored/Makefile | 1 + tools/ocaml/xenstored/packet.ml | 4 ++++ tools/ocaml/xenstored/process.ml | 34 ++++++++++++++++++++++++---------- 3 files changed, 29 insertions(+), 10 deletions(-) create mode 100644 tools/ocaml/xenstored/packet.ml
tools/ocaml/xenstored/packet.ml new file +4 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From a3a63b2cec1771b0fdc7fe68cc03a92e22904211 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 17:12:41 +0000
Subject: [PATCH 04/23] oxenstored: remove some unused parameters
--- tools/ocaml/xenstored/process.ml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 0c67dd9bf6c45e3afeb236cbbd414291cbb2a627 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 17:12:50 +0000
Subject: [PATCH 05/23] oxenstored: refactor request processing
Encapsulate the request in a record that is passed from do_input to process_packet and input_handle_error.
This will be helpful when keeping track of the requests made as part of a transaction.
--- tools/ocaml/xenstored/packet.ml | 7 +++++++ tools/ocaml/xenstored/process.ml | 15 ++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 8ae0c11240419916f500e3664b1f8b0fae23cb2e Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 17:12:56 +0000
Subject: [PATCH 06/23] oxenstored: keep track of each transaction's operations
A list of (request, response) pairs from the operations performed within the transaction will be useful to support transaction replay.
Since this consumes memory, the number of requests per transaction must not be left unbounded. Hence a new quota for this is introduced. This quota, configured via the configuration key 'quota-maxrequests', limits the size of transactions initiated by domUs.
After the maximum number of requests has been exhausted, any further requests will result in EQUOTA errors. The client may then choose to end the transaction; a successful commit will result in the retention of only the prior requests.
--- tools/ocaml/xenstored/define.ml | 1 + tools/ocaml/xenstored/oxenstored.conf | 1 + tools/ocaml/xenstored/process.ml | 13 +++++++++++-- tools/ocaml/xenstored/transaction.ml | 21 +++++++++++++++------ tools/ocaml/xenstored/xenstored.ml | 1 + 5 files changed, 29 insertions(+), 8 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From fbfd84d7db5f26081923309f59a6563194368584 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 17:13:03 +0000
Subject: [PATCH 07/23] oxenstored: move functions that process simple
operations
Separate the functions which process operations that can be done as part of a transaction. Specifically, these operations are: read, write, rm, getperms, setperms, getdomainpath, directory, mkdir.
Also split function_of_type into two functions: one for processing the simple operations and one for processing the rest.
This will help allow replay of transactions, allowing us to invoke the functions that process the simple operations as part of the processing of transaction_end.
Backporting to 4.5:
- Removed references to Reset_watches, which was introduced in 4.6.
--- tools/ocaml/xenstored/process.ml | 220 +++++++++++++++++++++------------------ 1 file changed, 119 insertions(+), 101 deletions(-)
tools/ocaml/xenstored/process.ml +119 -101
220 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From dcf7067785693fa6669c6ad253a9a523e3b72177 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 17:30:42 +0000
Subject: [PATCH 08/23] oxenstored: replay transaction upon conflict
The existing transaction merge algorithm keeps track of the least upper bound (longest common prefix) of all the nodes which have been read and written, and will re-combine two stores which have disjoint upper bounds. This works well for small transactions but causes unnecessary conflicts for ones that span a large subtree, such as the following ones used by the xapi toolstack:
* VM start: creates /vm/... /vss/... /local/domain/... The least upper bound of this transaction is / and so all these transactions conflict with everything.
* Device hotplug: creates /local/domain/0/... /local/domain/n/... The least upper bound of this transaction is /local/domain so all these transactions conflict with each other.
If the existing merge algorithm cannot merge and commit, we attempt a /replay/ of the failed transaction against the new store.
When we replay the requests we check whether the response sent to the client is the same as during the first attempt at the transaction. If the responses are all the same then the transaction replay can be committed. If any differ then the transaction replay must be aborted and the client must retry.
This algorithm uses the intuition that the transactions made by the toolstack are designed to be for separate domains, and should fundamentally not conflict in the sense that they don't read or write any shared keys. By replaying the transaction on the server side we do what the client would have to do anyway, only we can do it quickly without allowing any other requests to interfere.
Performing 300 parallel simulated VM start and shutdowns without this code:
300 parallel starts and shutdowns: 268.92
Performing 300 parallel simulated VM start and shutdowns with this code:
300 parallel starts and shutdowns: 3.80
--- tools/ocaml/xenstored/connection.ml | 5 ++++- tools/ocaml/xenstored/packet.ml | 5 +++++ tools/ocaml/xenstored/process.ml | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 19e48ca3eb2e27d6f678f125d5daee5482d07de2 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 17:30:49 +0000
Subject: [PATCH 09/23] oxenstored: log request and response during transaction
replay
During a transaction replay, the replayed requests and the new responses are logged in the same way as the original requests and the original responses.
--- tools/ocaml/xenstored/process.ml | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 4060b15a6e8ee5f6de99cd9765faae808bf6cd73 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 17:30:58 +0000
Subject: [PATCH 10/23] oxenstored: allow compilation prior to OCaml 3.12.0
Commit 363ae55c8 used an OCaml feature called record field punning. This broke the build on compilers prior to OCaml 3.12.0.
This patch makes no semantic change but now uses backwards-compatible syntax.
--- tools/ocaml/xenstored/process.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From c41fd8071de4c1d77033b5bb9546e637093c973e Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Tue, 14 Mar 2017 12:15:52 +0000
Subject: [PATCH 11/23] oxenstored: comments explaining some variables
It took a while of reading and reasoning to work out what these are for, so here are comments to make life easier for everyone reading this code in future.
--- tools/ocaml/xenstored/store.ml | 1 + tools/ocaml/xenstored/transaction.ml | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From f0820b919a385b0947c85f3a465b79ebdeb8777c Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Tue, 14 Mar 2017 12:15:52 +0000
Subject: [PATCH 12/23] oxenstored: handling of domain conflict-credit
This commit gives each domain a conflict-credit variable, which will later be used for limiting how often a domain can cause other domain's transaction-commits to fail.
This commit also provides functions and data for manipulating domains and their conflict-credit, and checking whether they have credit.
--- tools/ocaml/xenstored/connection.ml | 5 ++ tools/ocaml/xenstored/define.ml | 3 + tools/ocaml/xenstored/domain.ml | 11 +++- tools/ocaml/xenstored/domains.ml | 103 +++++++++++++++++++++++++++++++++- tools/ocaml/xenstored/oxenstored.conf | 32 +++++++++++ tools/ocaml/xenstored/transaction.ml | 2 + tools/ocaml/xenstored/xenstored.ml | 2 + 7 files changed, 154 insertions(+), 4 deletions(-)
tools/ocaml/xenstored/domains.ml +101 -2
103 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 15cd1a83ce70a107462dcd7fa3879193c11540ce Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Tue, 14 Mar 2017 12:15:52 +0000
Subject: [PATCH 13/23] oxenstored: ignore domains with no conflict-credit
When processing connections, skip those from domains with no remaining conflict-credit.
Also, issue a point of conflict-credit at regular intervals, the period being set by the configuration option "conflict-max-history- seconds". When issuing conflict-credit, we give a point either to every domain at once (one each) or only to the single domain at the front of the queue, depending on the configuration option "conflict-rate-limit-is-aggregate".
--- tools/ocaml/xenstored/connections.ml | 14 ++++---- tools/ocaml/xenstored/define.ml | 1 + tools/ocaml/xenstored/domains.ml | 4 +-- tools/ocaml/xenstored/oxenstored.conf | 2 +- tools/ocaml/xenstored/xenstored.ml | 65 ++++++++++++++++++++++++++--------- 5 files changed, 60 insertions(+), 26 deletions(-)
tools/ocaml/xenstored/xenstored.ml +48 -17
65 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From fecc5fd5ce05ba35b4e83a0980e5e469ddb18908 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Tue, 14 Mar 2017 12:17:38 +0000
Subject: [PATCH 14/23] oxenstored: add transaction info relevant to
history-tracking
Specifically:
* retain the original store (not just the root) in full transactions
* store commit count at the time of the start of the transaction
--- tools/ocaml/xenstored/process.ml | 2 +- tools/ocaml/xenstored/transaction.ml | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From dfc91fbce5b0b71e4b178a290287955d197f4326 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Tue, 14 Mar 2017 13:20:07 +0000
Subject: [PATCH 15/23] oxenstored: support commit history tracking
Add ability to track xenstore tree operations -- either non-transactional operations or committed transactions.
For now, the call to actually retain commits is commented out because history can grow without bound.
For now, we call record_commit for all non-transactional operations. A subsequent patch will make it retain only the ones with side-effects.
--- tools/ocaml/xenstored/Makefile | 1 + tools/ocaml/xenstored/history.ml | 43 ++++++++++++++++++++++++++++++++++++++ tools/ocaml/xenstored/process.ml | 24 +++++++++++++++++++-- tools/ocaml/xenstored/xenstored.ml | 1 + 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 tools/ocaml/xenstored/history.ml
tools/ocaml/xenstored/history.ml new file +43 -0
43 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 1b140e3b9ecf442804253d528ebe9fa8345c894a Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 14:20:33 +0000
Subject: [PATCH 16/23] oxenstored: only record operations with side-effects in
history
There is no need to record "read" operations as they will never cause another transaction to fail.
Backport 4.6 -> 4.5 by removing reference to XS_RESET_WATCHES.
--- tools/ocaml/xenstored/process.ml | 46 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-)
tools/ocaml/xenstored/process.ml +42 -4
46 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 05e31984f46e207b5b942c3683f540b8ceea43b8 Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Thu, 23 Mar 2017 14:25:16 +0000
Subject: [PATCH 17/23] oxenstored: discard old commit-history on txn end
The history of commits is to be used for working out which historical commit(s) (including atomic writes) caused conflicts with a currently-failing commit of a transaction. Any commit that was made before the current transaction started cannot be relevant. Therefore we never need to keep history from before the start of the longest-running transaction that is open at any given time: whenever a transaction ends (with or without a commit) then if it was the longest-running open transaction we can delete history up until start of the the next-longest-running open transaction.
Some transactions might stay open for a very long time, so if any transaction exceeds conflict_max_history_seconds then we remove it from consideration in this context, and will not guarantee to keep remembering about historical commits made during such a transaction.
We implement this by keeping a list of all open transactions that have not been open too long. When a transaction ends, we remove it from the list, along with any that have been open longer than the maximum; then we delete any history from before the start of the longest-running transaction remaining in the list.
--- tools/ocaml/xenstored/history.ml | 17 +++++++++++++++++ tools/ocaml/xenstored/process.ml | 4 ++-- tools/ocaml/xenstored/transaction.ml | 29 +++++++++++++++++++++++++---- 3 files changed, 44 insertions(+), 6 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From d017aa4487363e25354a6cbbdc4aa51c320da548 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Mon, 27 Mar 2017 08:58:29 +0000
Subject: [PATCH 18/23] oxenstored: track commit history
Since the list of historic activity cannot grow without bound, it is safe to use this to track commits.
--- tools/ocaml/xenstored/process.ml | 5 ----- 1 file changed, 5 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From d7f40a14e454161a56ec8428d8841eb92cd4b548 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 14:28:16 +0000
Subject: [PATCH 19/23] oxenstored: blame the connection that caused a
transaction conflict
Blame each connection found to have made a commit that would cause this transaction to fail. Each blamed connection is penalised by having its conflict-credit decremented.
Note the change in semantics for the replay function: we no longer stop after finding the first operation that can't be replayed. This allows us to identify all operations that conflicted with this transaction, not just the one that conflicted first.
v1 Reviewed-by: Christian Lindig <[email protected]>
Changes since v1:
* use correct log levels for informational messages
Changes since v2:
* fix the blame algorithm and improve logging (fix was reviewed by Jonathan Davies)
--- tools/ocaml/xenstored/history.ml | 12 ++++++++++ tools/ocaml/xenstored/process.ml | 50 ++++++++++++++++++++++++++++++++-------- 2 files changed, 52 insertions(+), 10 deletions(-)
tools/ocaml/xenstored/process.ml +40 -10
50 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 0a7533a240515c7713b8caf1eceed61d87a55006 Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Thu, 23 Mar 2017 19:06:54 +0000
Subject: [PATCH 20/23] oxenstored: allow self-conflicts
We already avoid inter-domain conflicts but now allow intra-domain conflicts. Although there are no known practical examples of a domain that might perform operations that conflict with its own transactions, this is conceivable, so here we avoid changing those semantics unnecessarily.
When a transaction commit fails with a conflict and we look through the history of commits to see which connection(s) to blame, ignore historical commits that were made by the same connection as the failing commit.
--- tools/ocaml/xenstored/history.ml | 3 ++- tools/ocaml/xenstored/process.ml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 1553162a36a74771de8e0b54209be1cbe5052c85 Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Fri, 24 Mar 2017 16:16:10 +0000
Subject: [PATCH 21/23] oxenstored: do not commit read-only transactions
The packet telling us to end the transaction has always carried an argument telling us whether to commit.
If the transaction made no modifications to the tree, now we ignore that argument and do not commit: it is just a waste of effort.
This makes read-only transactions immune to conflicts, and means that we do not need to store any of their details in the history that is used for assigning blame for conflicts.
We count a transaction as a read-only transaction only if it contains no operations that modified the tree.
This means that (for example) a transaction that creates a new node then deletes it would NOT count as read-only, even though it makes no change overall. A more sophisticated algorithm could judge the transaction based on comparison of its initial and final states, but this would add complexity and computational cost.
--- tools/ocaml/xenstored/process.ml | 1 + tools/ocaml/xenstored/transaction.ml | 1 + 2 files changed, 2 insertions(+)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From d577584114b605c125dc30be496b55bca7dda978 Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Fri, 24 Mar 2017 19:55:03 +0000
Subject: [PATCH 22/23] oxenstored: don't wake to issue no conflict-credit
In the main loop, when choosing the timeout for the select function call, we were setting it so as to wake up to issue conflict-credit to any domains that could accept it. When xenstore is idle, this would mean waking up every 50ms (by default) to do no work. With this commit, we check whether any domain is below its cap, and if not then we set the timeout for longer (the same timeout as before the conflict-protection feature was added).
--- tools/ocaml/xenstored/domains.ml | 51 ++++++++++++++++++++++++++++++-------- tools/ocaml/xenstored/xenstored.ml | 5 +++- 2 files changed, 44 insertions(+), 12 deletions(-)
tools/ocaml/xenstored/domains.ml +40 -11
51 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From d9e51da1a9d10655557d63ecaa749cfcd8e41204 Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Mon, 27 Mar 2017 14:36:34 +0100
Subject: [PATCH 23/23] oxenstored transaction conflicts: improve logging
For information related to transaction conflicts, potentially frequent logging at "info" priority has been changed to "debug" priority, and once per two minutes there is an "info" priority summary.
Additional detailed logging has been added at "debug" priority.
--- tools/ocaml/xenstored/domain.ml | 8 ++++++++ tools/ocaml/xenstored/domains.ml | 5 +++++ tools/ocaml/xenstored/process.ml | 6 +++++- tools/ocaml/xenstored/transaction.ml | 5 +++++ tools/ocaml/xenstored/xenstored.ml | 6 ++++++ 5 files changed, 29 insertions(+), 1 deletion(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 26b15d4eb7ac71fcab28a7fca664afa0549c135c Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Tue, 28 Mar 2017 18:57:52 +0100
Subject: [PATCH 24/23] oxenstored: trim history in the frequent_ops function
We were trimming the history of commits only at the end of each transaction (regardless of how it ended).
Therefore if non-transactional writes were being made but no transactions were being ended, the history would grow indefinitely. Now we trim the history at regular intervals.
--- tools/ocaml/xenstored/history.ml | 6 +++--- tools/ocaml/xenstored/transaction.ml | 8 ++++++-- tools/ocaml/xenstored/xenstored.ml | 1 + 3 files changed, 10 insertions(+), 5 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.9.5
From 5aed8d6e20d1848f6818e649905df84e9cee34ae Mon Sep 17 00:00:00 2001
From: Ian Jackson <[email protected]>
Date: Sat, 18 Mar 2017 16:44:46 +0000
Subject: [PATCH 01/23] xenstored: apply a write transaction rate limit
This avoids a rogue client being about to stall another client (eg the toolstack) indefinitely.
This is XSA-206.
--- tools/xenstore/Makefile | 3 +- tools/xenstore/xenstored_core.c | 9 ++ tools/xenstore/xenstored_core.h | 6 + tools/xenstore/xenstored_domain.c | 215 +++++++++++++++++++++++++++++++++ tools/xenstore/xenstored_domain.h | 25 ++++ tools/xenstore/xenstored_transaction.c | 5 + 6 files changed, 262 insertions(+), 1 deletion(-)
tools/xenstore/xenstored_domain.c +215 -0
215 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 973b17021b43c825c03ca0619dbeb25d5360a38b Mon Sep 17 00:00:00 2001
From: Ian Jackson <[email protected]>
Date: Sat, 18 Mar 2017 16:45:27 +0000
Subject: [PATCH 02/23] xenstored: Log when the write transaction rate limit
bites
--- tools/xenstore/xenstored_core.c | 1 + tools/xenstore/xenstored_domain.c | 25 +++++++++++++++++++++++++ tools/xenstore/xenstored_domain.h | 2 ++ 3 files changed, 28 insertions(+)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 9cb3ad7a8a0749d8e8633b0ff56afc268e42dc13 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 16:27:23 +0000
Subject: [PATCH 03/23] oxenstored: refactor putting response on wire
Previously, the functions reply_{ack,data,data_or_ack} and input_handle_error put the response on the wire by invoking Connection.send_{ack,reply,error}.
Instead, these functions now return a value indicating what needs to be put on the wire, and that action is done by a send_response function called afterwards.
This refactoring gives us a chance to store the value of the response, useful for replaying transactions.
--- tools/ocaml/xenstored/Makefile | 1 + tools/ocaml/xenstored/packet.ml | 4 ++++ tools/ocaml/xenstored/process.ml | 34 ++++++++++++++++++++++++---------- 3 files changed, 29 insertions(+), 10 deletions(-) create mode 100644 tools/ocaml/xenstored/packet.ml
tools/ocaml/xenstored/packet.ml new file +4 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 5d641cb4019a22d0818709d6637825082e0f5c97 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 16:27:39 +0000
Subject: [PATCH 04/23] oxenstored: remove some unused parameters
--- tools/ocaml/xenstored/process.ml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 03190ba306d478b4ea70535f4a19c32ad1cf63c2 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 16:27:50 +0000
Subject: [PATCH 05/23] oxenstored: refactor request processing
Encapsulate the request in a record that is passed from do_input to process_packet and input_handle_error.
This will be helpful when keeping track of the requests made as part of a transaction.
--- tools/ocaml/xenstored/packet.ml | 7 +++++++ tools/ocaml/xenstored/process.ml | 15 ++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 7e956305bb7990d39fd57a05820dcbf0e1ff3c38 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 16:27:58 +0000
Subject: [PATCH 06/23] oxenstored: keep track of each transaction's operations
A list of (request, response) pairs from the operations performed within the transaction will be useful to support transaction replay.
Since this consumes memory, the number of requests per transaction must not be left unbounded. Hence a new quota for this is introduced. This quota, configured via the configuration key 'quota-maxrequests', limits the size of transactions initiated by domUs.
After the maximum number of requests has been exhausted, any further requests will result in EQUOTA errors. The client may then choose to end the transaction; a successful commit will result in the retention of only the prior requests.
--- tools/ocaml/xenstored/define.ml | 1 + tools/ocaml/xenstored/oxenstored.conf | 1 + tools/ocaml/xenstored/process.ml | 13 +++++++++++-- tools/ocaml/xenstored/transaction.ml | 21 +++++++++++++++------ tools/ocaml/xenstored/xenstored.ml | 1 + 5 files changed, 29 insertions(+), 8 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 9d62d32ee9813f5b340eb71b8e6ccd8cce45404b Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 16:28:08 +0000
Subject: [PATCH 07/23] oxenstored: move functions that process simple
operations
Separate the functions which process operations that can be done as part of a transaction. Specifically, these operations are: read, write, rm, getperms, setperms, getdomainpath, directory, mkdir.
Also split function_of_type into two functions: one for processing the simple operations and one for processing the rest.
This will help allow replay of transactions, allowing us to invoke the functions that process the simple operations as part of the processing of transaction_end.
--- tools/ocaml/xenstored/process.ml | 223 +++++++++++++++++++++------------------ 1 file changed, 121 insertions(+), 102 deletions(-)
tools/ocaml/xenstored/process.ml +121 -102
223 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 5c58daab885c0ab19200df95773e309a950154ad Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 16:28:19 +0000
Subject: [PATCH 08/23] oxenstored: replay transaction upon conflict
The existing transaction merge algorithm keeps track of the least upper bound (longest common prefix) of all the nodes which have been read and written, and will re-combine two stores which have disjoint upper bounds. This works well for small transactions but causes unnecessary conflicts for ones that span a large subtree, such as the following ones used by the xapi toolstack:
* VM start: creates /vm/... /vss/... /local/domain/... The least upper bound of this transaction is / and so all these transactions conflict with everything.
* Device hotplug: creates /local/domain/0/... /local/domain/n/... The least upper bound of this transaction is /local/domain so all these transactions conflict with each other.
If the existing merge algorithm cannot merge and commit, we attempt a /replay/ of the failed transaction against the new store.
When we replay the requests we check whether the response sent to the client is the same as during the first attempt at the transaction. If the responses are all the same then the transaction replay can be committed. If any differ then the transaction replay must be aborted and the client must retry.
This algorithm uses the intuition that the transactions made by the toolstack are designed to be for separate domains, and should fundamentally not conflict in the sense that they don't read or write any shared keys. By replaying the transaction on the server side we do what the client would have to do anyway, only we can do it quickly without allowing any other requests to interfere.
Performing 300 parallel simulated VM start and shutdowns without this code:
300 parallel starts and shutdowns: 268.92
Performing 300 parallel simulated VM start and shutdowns with this code:
300 parallel starts and shutdowns: 3.80
--- tools/ocaml/xenstored/connection.ml | 5 ++++- tools/ocaml/xenstored/packet.ml | 5 +++++ tools/ocaml/xenstored/process.ml | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 4af91642a5e39270d4ff0e029fc9dce89180b8fe Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 16:28:34 +0000
Subject: [PATCH 09/23] oxenstored: log request and response during transaction
replay
During a transaction replay, the replayed requests and the new responses are logged in the same way as the original requests and the original responses.
--- tools/ocaml/xenstored/process.ml | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 47ea5e9be83c1e3fae2d2497a83adb66c6b4e3f8 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 16:28:45 +0000
Subject: [PATCH 10/23] oxenstored: allow compilation prior to OCaml 3.12.0
Commit 363ae55c8 used an OCaml feature called record field punning. This broke the build on compilers prior to OCaml 3.12.0.
This patch makes no semantic change but now uses backwards-compatible syntax.
--- tools/ocaml/xenstored/process.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From b0711f09f6d0e3fb2b0e52e89222a16800333b21 Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Tue, 14 Mar 2017 12:15:52 +0000
Subject: [PATCH 11/23] oxenstored: comments explaining some variables
It took a while of reading and reasoning to work out what these are for, so here are comments to make life easier for everyone reading this code in future.
--- tools/ocaml/xenstored/store.ml | 1 + tools/ocaml/xenstored/transaction.ml | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 769f335e6bc11711f7fbe3a26f17f8e3a91bb007 Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Tue, 14 Mar 2017 12:15:52 +0000
Subject: [PATCH 12/23] oxenstored: handling of domain conflict-credit
This commit gives each domain a conflict-credit variable, which will later be used for limiting how often a domain can cause other domain's transaction-commits to fail.
This commit also provides functions and data for manipulating domains and their conflict-credit, and checking whether they have credit.
--- tools/ocaml/xenstored/connection.ml | 5 ++ tools/ocaml/xenstored/define.ml | 3 + tools/ocaml/xenstored/domain.ml | 11 +++- tools/ocaml/xenstored/domains.ml | 103 +++++++++++++++++++++++++++++++++- tools/ocaml/xenstored/oxenstored.conf | 32 +++++++++++ tools/ocaml/xenstored/transaction.ml | 2 + tools/ocaml/xenstored/xenstored.ml | 2 + 7 files changed, 154 insertions(+), 4 deletions(-)
tools/ocaml/xenstored/domains.ml +101 -2
103 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From b2db82fb15c736602fdb3fa06ccd3011880925dc Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Tue, 14 Mar 2017 12:15:52 +0000
Subject: [PATCH 13/23] oxenstored: ignore domains with no conflict-credit
When processing connections, skip those from domains with no remaining conflict-credit.
Also, issue a point of conflict-credit at regular intervals, the period being set by the configuration option "conflict-max-history- seconds". When issuing conflict-credit, we give a point either to every domain at once (one each) or only to the single domain at the front of the queue, depending on the configuration option "conflict-rate-limit-is-aggregate".
--- tools/ocaml/xenstored/connections.ml | 14 ++++---- tools/ocaml/xenstored/define.ml | 1 + tools/ocaml/xenstored/domains.ml | 4 +-- tools/ocaml/xenstored/oxenstored.conf | 2 +- tools/ocaml/xenstored/xenstored.ml | 65 ++++++++++++++++++++++++++--------- 5 files changed, 60 insertions(+), 26 deletions(-)
tools/ocaml/xenstored/xenstored.ml +48 -17
65 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From b1ec169b35db0f70cba494c33a515876223ff7cc Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Tue, 14 Mar 2017 12:17:38 +0000
Subject: [PATCH 14/23] oxenstored: add transaction info relevant to
history-tracking
Specifically:
* retain the original store (not just the root) in full transactions
* store commit count at the time of the start of the transaction
--- tools/ocaml/xenstored/process.ml | 2 +- tools/ocaml/xenstored/transaction.ml | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From ae5f87f3ac593abfb08f12673a06027a34b5450f Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Tue, 14 Mar 2017 13:20:07 +0000
Subject: [PATCH 15/23] oxenstored: support commit history tracking
Add ability to track xenstore tree operations -- either non-transactional operations or committed transactions.
For now, the call to actually retain commits is commented out because history can grow without bound.
For now, we call record_commit for all non-transactional operations. A subsequent patch will make it retain only the ones with side-effects.
--- tools/ocaml/xenstored/Makefile | 1 + tools/ocaml/xenstored/history.ml | 43 ++++++++++++++++++++++++++++++++++++++ tools/ocaml/xenstored/process.ml | 24 +++++++++++++++++++-- tools/ocaml/xenstored/xenstored.ml | 1 + 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 tools/ocaml/xenstored/history.ml
tools/ocaml/xenstored/history.ml new file +43 -0
43 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 594511920df9a1121b178d73f6fb8a48dfd35f9e Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 14:20:33 +0000
Subject: [PATCH 16/23] oxenstored: only record operations with side-effects in
history
There is no need to record "read" operations as they will never cause another transaction to fail.
--- tools/ocaml/xenstored/process.ml | 47 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-)
tools/ocaml/xenstored/process.ml +43 -4
47 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 2583968f96e8d431efc79c4da48379fd93363007 Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Thu, 23 Mar 2017 14:25:16 +0000
Subject: [PATCH 17/23] oxenstored: discard old commit-history on txn end
The history of commits is to be used for working out which historical commit(s) (including atomic writes) caused conflicts with a currently-failing commit of a transaction. Any commit that was made before the current transaction started cannot be relevant. Therefore we never need to keep history from before the start of the longest-running transaction that is open at any given time: whenever a transaction ends (with or without a commit) then if it was the longest-running open transaction we can delete history up until start of the the next-longest-running open transaction.
Some transactions might stay open for a very long time, so if any transaction exceeds conflict_max_history_seconds then we remove it from consideration in this context, and will not guarantee to keep remembering about historical commits made during such a transaction.
We implement this by keeping a list of all open transactions that have not been open too long. When a transaction ends, we remove it from the list, along with any that have been open longer than the maximum; then we delete any history from before the start of the longest-running transaction remaining in the list.
--- tools/ocaml/xenstored/history.ml | 17 +++++++++++++++++ tools/ocaml/xenstored/process.ml | 4 ++-- tools/ocaml/xenstored/transaction.ml | 29 +++++++++++++++++++++++++---- 3 files changed, 44 insertions(+), 6 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 3ab13d5ebd991b4c9f9d1296c8f80a612f027298 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Mon, 27 Mar 2017 08:58:29 +0000
Subject: [PATCH 18/23] oxenstored: track commit history
Since the list of historic activity cannot grow without bound, it is safe to use this to track commits.
--- tools/ocaml/xenstored/process.ml | 5 ----- 1 file changed, 5 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 28a3047d339c0bf524173f38bcf7d25d346e8c62 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 14:28:16 +0000
Subject: [PATCH 19/23] oxenstored: blame the connection that caused a
transaction conflict
Blame each connection found to have made a commit that would cause this transaction to fail. Each blamed connection is penalised by having its conflict-credit decremented.
Note the change in semantics for the replay function: we no longer stop after finding the first operation that can't be replayed. This allows us to identify all operations that conflicted with this transaction, not just the one that conflicted first.
v1 Reviewed-by: Christian Lindig <[email protected]>
Changes since v1:
* use correct log levels for informational messages
Changes since v2:
* fix the blame algorithm and improve logging (fix was reviewed by Jonathan Davies)
--- tools/ocaml/xenstored/history.ml | 12 ++++++++++ tools/ocaml/xenstored/process.ml | 50 ++++++++++++++++++++++++++++++++-------- 2 files changed, 52 insertions(+), 10 deletions(-)
tools/ocaml/xenstored/process.ml +40 -10
50 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 54b70b7e7b8c09a2cf9ac1f01d357cf1a5a9f34b Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Thu, 23 Mar 2017 19:06:54 +0000
Subject: [PATCH 20/23] oxenstored: allow self-conflicts
We already avoid inter-domain conflicts but now allow intra-domain conflicts. Although there are no known practical examples of a domain that might perform operations that conflict with its own transactions, this is conceivable, so here we avoid changing those semantics unnecessarily.
When a transaction commit fails with a conflict and we look through the history of commits to see which connection(s) to blame, ignore historical commits that were made by the same connection as the failing commit.
--- tools/ocaml/xenstored/history.ml | 3 ++- tools/ocaml/xenstored/process.ml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 04c815f29e918ca54093da61d28eec18db582074 Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Fri, 24 Mar 2017 16:16:10 +0000
Subject: [PATCH 21/23] oxenstored: do not commit read-only transactions
The packet telling us to end the transaction has always carried an argument telling us whether to commit.
If the transaction made no modifications to the tree, now we ignore that argument and do not commit: it is just a waste of effort.
This makes read-only transactions immune to conflicts, and means that we do not need to store any of their details in the history that is used for assigning blame for conflicts.
We count a transaction as a read-only transaction only if it contains no operations that modified the tree.
This means that (for example) a transaction that creates a new node then deletes it would NOT count as read-only, even though it makes no change overall. A more sophisticated algorithm could judge the transaction based on comparison of its initial and final states, but this would add complexity and computational cost.
--- tools/ocaml/xenstored/process.ml | 1 + tools/ocaml/xenstored/transaction.ml | 1 + 2 files changed, 2 insertions(+)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From fbc4354a22c070e6d336b9bf4eae5dfb80657a9b Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Fri, 24 Mar 2017 19:55:03 +0000
Subject: [PATCH 22/23] oxenstored: don't wake to issue no conflict-credit
In the main loop, when choosing the timeout for the select function call, we were setting it so as to wake up to issue conflict-credit to any domains that could accept it. When xenstore is idle, this would mean waking up every 50ms (by default) to do no work. With this commit, we check whether any domain is below its cap, and if not then we set the timeout for longer (the same timeout as before the conflict-protection feature was added).
--- tools/ocaml/xenstored/domains.ml | 51 ++++++++++++++++++++++++++++++-------- tools/ocaml/xenstored/xenstored.ml | 5 +++- 2 files changed, 44 insertions(+), 12 deletions(-)
tools/ocaml/xenstored/domains.ml +40 -11
51 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From a64892b9765cd4a79f19320f61ad4b8afb5826b1 Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Mon, 27 Mar 2017 14:36:34 +0100
Subject: [PATCH 23/23] oxenstored transaction conflicts: improve logging
For information related to transaction conflicts, potentially frequent logging at "info" priority has been changed to "debug" priority, and once per two minutes there is an "info" priority summary.
Additional detailed logging has been added at "debug" priority.
--- tools/ocaml/xenstored/domain.ml | 8 ++++++++ tools/ocaml/xenstored/domains.ml | 5 +++++ tools/ocaml/xenstored/process.ml | 6 +++++- tools/ocaml/xenstored/transaction.ml | 5 +++++ tools/ocaml/xenstored/xenstored.ml | 6 ++++++ 5 files changed, 29 insertions(+), 1 deletion(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 26b15d4eb7ac71fcab28a7fca664afa0549c135c Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Tue, 28 Mar 2017 18:57:52 +0100
Subject: [PATCH 24/23] oxenstored: trim history in the frequent_ops function
We were trimming the history of commits only at the end of each transaction (regardless of how it ended).
Therefore if non-transactional writes were being made but no transactions were being ended, the history would grow indefinitely. Now we trim the history at regular intervals.
--- tools/ocaml/xenstored/history.ml | 6 +++--- tools/ocaml/xenstored/transaction.ml | 8 ++++++-- tools/ocaml/xenstored/xenstored.ml | 1 + 3 files changed, 10 insertions(+), 5 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.9.5
From bfe42a836450591bb41f4f6393c42dbb0d72abb9 Mon Sep 17 00:00:00 2001
From: Ian Jackson <[email protected]>
Date: Sat, 18 Mar 2017 16:12:26 +0000
Subject: [PATCH 01/15] xenstored: apply a write transaction rate limit
This avoids a rogue client being about to stall another client (eg the toolstack) indefinitely.
This is XSA-206.
Backported to 4.8 (not entirely trivial).
--- tools/xenstore/Makefile | 3 +- tools/xenstore/xenstored_core.c | 9 ++ tools/xenstore/xenstored_core.h | 6 + tools/xenstore/xenstored_domain.c | 215 +++++++++++++++++++++++++++++++++ tools/xenstore/xenstored_domain.h | 25 ++++ tools/xenstore/xenstored_transaction.c | 5 + 6 files changed, 262 insertions(+), 1 deletion(-)
tools/xenstore/xenstored_domain.c +215 -0
215 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 1d713bf29548ee3e48c3170bafe2863d17694e90 Mon Sep 17 00:00:00 2001
From: Ian Jackson <[email protected]>
Date: Sat, 18 Mar 2017 16:39:31 +0000
Subject: [PATCH 02/15] xenstored: Log when the write transaction rate limit
bites
--- tools/xenstore/xenstored_core.c | 1 + tools/xenstore/xenstored_domain.c | 25 +++++++++++++++++++++++++ tools/xenstore/xenstored_domain.h | 2 ++ 3 files changed, 28 insertions(+)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From d45a4b9cc5687d089e1cfb0a23847db59270c855 Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Tue, 14 Mar 2017 12:15:52 +0000
Subject: [PATCH 03/15] oxenstored: comments explaining some variables
It took a while of reading and reasoning to work out what these are for, so here are comments to make life easier for everyone reading this code in future.
--- tools/ocaml/xenstored/store.ml | 1 + tools/ocaml/xenstored/transaction.ml | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From a7d7b8fff1b61fa108a2d7c671a52863954f1d70 Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Tue, 14 Mar 2017 12:15:52 +0000
Subject: [PATCH 04/15] oxenstored: handling of domain conflict-credit
This commit gives each domain a conflict-credit variable, which will later be used for limiting how often a domain can cause other domain's transaction-commits to fail.
This commit also provides functions and data for manipulating domains and their conflict-credit, and checking whether they have credit.
--- tools/ocaml/xenstored/connection.ml | 5 ++ tools/ocaml/xenstored/define.ml | 3 + tools/ocaml/xenstored/domain.ml | 11 +++- tools/ocaml/xenstored/domains.ml | 103 +++++++++++++++++++++++++++++++++- tools/ocaml/xenstored/oxenstored.conf | 32 +++++++++++ tools/ocaml/xenstored/transaction.ml | 2 + tools/ocaml/xenstored/xenstored.ml | 2 + 7 files changed, 154 insertions(+), 4 deletions(-)
tools/ocaml/xenstored/domains.ml +101 -2
103 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 60d93eb4da98d43fde6f59993c69a18d98e14778 Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Tue, 14 Mar 2017 12:15:52 +0000
Subject: [PATCH 05/15] oxenstored: ignore domains with no conflict-credit
When processing connections, skip those from domains with no remaining conflict-credit.
Also, issue a point of conflict-credit at regular intervals, the period being set by the configuration option "conflict-max-history- seconds". When issuing conflict-credit, we give a point either to every domain at once (one each) or only to the single domain at the front of the queue, depending on the configuration option "conflict-rate-limit-is-aggregate".
--- tools/ocaml/xenstored/connections.ml | 14 ++++---- tools/ocaml/xenstored/define.ml | 1 + tools/ocaml/xenstored/domains.ml | 4 +-- tools/ocaml/xenstored/oxenstored.conf | 2 +- tools/ocaml/xenstored/xenstored.ml | 65 ++++++++++++++++++++++++++--------- 5 files changed, 60 insertions(+), 26 deletions(-)
tools/ocaml/xenstored/xenstored.ml +48 -17
65 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 5b0215d116da814c7ab50054e1f04c47c75db29b Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Tue, 14 Mar 2017 12:17:38 +0000
Subject: [PATCH 06/15] oxenstored: add transaction info relevant to
history-tracking
Specifically:
* retain the original store (not just the root) in full transactions
* store commit count at the time of the start of the transaction
--- tools/ocaml/xenstored/process.ml | 2 +- tools/ocaml/xenstored/transaction.ml | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From c98cd288e2f0fa8614c1334807eda87eaa6e52a0 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Tue, 14 Mar 2017 13:20:07 +0000
Subject: [PATCH 07/15] oxenstored: support commit history tracking
Add ability to track xenstore tree operations -- either non-transactional operations or committed transactions.
For now, the call to actually retain commits is commented out because history can grow without bound.
For now, we call record_commit for all non-transactional operations. A subsequent patch will make it retain only the ones with side-effects.
--- tools/ocaml/xenstored/Makefile | 1 + tools/ocaml/xenstored/history.ml | 43 ++++++++++++++++++++++++++++++++++++++ tools/ocaml/xenstored/process.ml | 24 +++++++++++++++++++-- tools/ocaml/xenstored/xenstored.ml | 1 + 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 tools/ocaml/xenstored/history.ml
tools/ocaml/xenstored/history.ml new file +43 -0
43 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 67e9694576b20f2493410a0c9165c1fccea30b00 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 14:20:33 +0000
Subject: [PATCH 08/15] oxenstored: only record operations with side-effects in
history
There is no need to record "read" operations as they will never cause another transaction to fail.
--- tools/ocaml/xenstored/process.ml | 47 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-)
tools/ocaml/xenstored/process.ml +43 -4
47 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 285d5968606d18338bed22e02a06087d59563f3d Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Thu, 23 Mar 2017 14:25:16 +0000
Subject: [PATCH 09/15] oxenstored: discard old commit-history on txn end
The history of commits is to be used for working out which historical commit(s) (including atomic writes) caused conflicts with a currently-failing commit of a transaction. Any commit that was made before the current transaction started cannot be relevant. Therefore we never need to keep history from before the start of the longest-running transaction that is open at any given time: whenever a transaction ends (with or without a commit) then if it was the longest-running open transaction we can delete history up until start of the the next-longest-running open transaction.
Some transactions might stay open for a very long time, so if any transaction exceeds conflict_max_history_seconds then we remove it from consideration in this context, and will not guarantee to keep remembering about historical commits made during such a transaction.
We implement this by keeping a list of all open transactions that have not been open too long. When a transaction ends, we remove it from the list, along with any that have been open longer than the maximum; then we delete any history from before the start of the longest-running transaction remaining in the list.
--- tools/ocaml/xenstored/history.ml | 17 +++++++++++++++++ tools/ocaml/xenstored/process.ml | 4 ++-- tools/ocaml/xenstored/transaction.ml | 29 +++++++++++++++++++++++++---- 3 files changed, 44 insertions(+), 6 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 6693c5d5edf3a2694b41b759c468e07afff93dd8 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Mon, 27 Mar 2017 08:58:29 +0000
Subject: [PATCH 10/15] oxenstored: track commit history
Since the list of historic activity cannot grow without bound, it is safe to use this to track commits.
--- tools/ocaml/xenstored/process.ml | 5 ----- 1 file changed, 5 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 8feb37bb79707804c7c9a17b06d8b0a80c58186d Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 14:28:16 +0000
Subject: [PATCH 11/15] oxenstored: blame the connection that caused a
transaction conflict
Blame each connection found to have made a commit that would cause this transaction to fail. Each blamed connection is penalised by having its conflict-credit decremented.
Note the change in semantics for the replay function: we no longer stop after finding the first operation that can't be replayed. This allows us to identify all operations that conflicted with this transaction, not just the one that conflicted first.
v1 Reviewed-by: Christian Lindig <[email protected]>
Changes since v1:
* use correct log levels for informational messages
Changes since v2:
* fix the blame algorithm and improve logging (fix was reviewed by Jonathan Davies)
--- tools/ocaml/xenstored/history.ml | 12 ++++++++++ tools/ocaml/xenstored/process.ml | 50 ++++++++++++++++++++++++++++++++-------- 2 files changed, 52 insertions(+), 10 deletions(-)
tools/ocaml/xenstored/process.ml +40 -10
50 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 424d85e97def513ede780f3307ea9311995a5156 Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Thu, 23 Mar 2017 19:06:54 +0000
Subject: [PATCH 12/15] oxenstored: allow self-conflicts
We already avoid inter-domain conflicts but now allow intra-domain conflicts. Although there are no known practical examples of a domain that might perform operations that conflict with its own transactions, this is conceivable, so here we avoid changing those semantics unnecessarily.
When a transaction commit fails with a conflict and we look through the history of commits to see which connection(s) to blame, ignore historical commits that were made by the same connection as the failing commit.
--- tools/ocaml/xenstored/history.ml | 3 ++- tools/ocaml/xenstored/process.ml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From fefca2cba49850ec894a6140c3620e70de68b273 Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Fri, 24 Mar 2017 16:16:10 +0000
Subject: [PATCH 13/15] oxenstored: do not commit read-only transactions
The packet telling us to end the transaction has always carried an argument telling us whether to commit.
If the transaction made no modifications to the tree, now we ignore that argument and do not commit: it is just a waste of effort.
This makes read-only transactions immune to conflicts, and means that we do not need to store any of their details in the history that is used for assigning blame for conflicts.
We count a transaction as a read-only transaction only if it contains no operations that modified the tree.
This means that (for example) a transaction that creates a new node then deletes it would NOT count as read-only, even though it makes no change overall. A more sophisticated algorithm could judge the transaction based on comparison of its initial and final states, but this would add complexity and computational cost.
--- tools/ocaml/xenstored/process.ml | 1 + tools/ocaml/xenstored/transaction.ml | 1 + 2 files changed, 2 insertions(+)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 64e9ed3eb51d6fb1f2ef04f57aaaa9e7d7c34937 Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Fri, 24 Mar 2017 19:55:03 +0000
Subject: [PATCH 14/15] oxenstored: don't wake to issue no conflict-credit
In the main loop, when choosing the timeout for the select function call, we were setting it so as to wake up to issue conflict-credit to any domains that could accept it. When xenstore is idle, this would mean waking up every 50ms (by default) to do no work. With this commit, we check whether any domain is below its cap, and if not then we set the timeout for longer (the same timeout as before the conflict-protection feature was added).
--- tools/ocaml/xenstored/domains.ml | 51 ++++++++++++++++++++++++++++++-------- tools/ocaml/xenstored/xenstored.ml | 5 +++- 2 files changed, 44 insertions(+), 12 deletions(-)
tools/ocaml/xenstored/domains.ml +40 -11
51 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 9f8280911b1db9419bc9755394ee3c248392cd2c Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Mon, 27 Mar 2017 14:36:34 +0100
Subject: [PATCH 15/15] oxenstored transaction conflicts: improve logging
For information related to transaction conflicts, potentially frequent logging at "info" priority has been changed to "debug" priority, and once per two minutes there is an "info" priority summary.
Additional detailed logging has been added at "debug" priority.
--- tools/ocaml/xenstored/domain.ml | 8 ++++++++ tools/ocaml/xenstored/domains.ml | 5 +++++ tools/ocaml/xenstored/process.ml | 6 +++++- tools/ocaml/xenstored/transaction.ml | 5 +++++ tools/ocaml/xenstored/xenstored.ml | 6 ++++++ 5 files changed, 29 insertions(+), 1 deletion(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 26b15d4eb7ac71fcab28a7fca664afa0549c135c Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Tue, 28 Mar 2017 18:57:52 +0100
Subject: [PATCH 16/15] oxenstored: trim history in the frequent_ops function
We were trimming the history of commits only at the end of each transaction (regardless of how it ended).
Therefore if non-transactional writes were being made but no transactions were being ended, the history would grow indefinitely. Now we trim the history at regular intervals.
--- tools/ocaml/xenstored/history.ml | 6 +++--- tools/ocaml/xenstored/transaction.ml | 8 ++++++-- tools/ocaml/xenstored/xenstored.ml | 1 + 3 files changed, 10 insertions(+), 5 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.9.5
From 8b2d563e6693527e0747fbb22c5f01eeb89a6c53 Mon Sep 17 00:00:00 2001
From: Ian Jackson <[email protected]>
Date: Tue, 7 Mar 2017 16:09:12 +0000
Subject: [PATCH 01/15] xenstored: apply a write transaction rate limit
This avoids a rogue client being about to stall another client (eg the toolstack) indefinitely.
This is XSA-206.
Backported to 4.8 (not entirely trivial).
--- tools/xenstore/Makefile | 3 +- tools/xenstore/xenstored_core.c | 9 ++ tools/xenstore/xenstored_core.h | 6 + tools/xenstore/xenstored_domain.c | 215 +++++++++++++++++++++++++++++++++ tools/xenstore/xenstored_domain.h | 25 ++++ tools/xenstore/xenstored_transaction.c | 5 + 6 files changed, 262 insertions(+), 1 deletion(-)
tools/xenstore/xenstored_domain.c +215 -0
215 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 6a5b012157c3dbe4bb82f2aa3d950e20cb5bf9d6 Mon Sep 17 00:00:00 2001
From: Ian Jackson <[email protected]>
Date: Tue, 7 Mar 2017 16:09:13 +0000
Subject: [PATCH 02/15] xenstored: Log when the write transaction rate limit
bites
--- tools/xenstore/xenstored_core.c | 1 + tools/xenstore/xenstored_domain.c | 25 +++++++++++++++++++++++++ tools/xenstore/xenstored_domain.h | 2 ++ 3 files changed, 28 insertions(+)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From d94645f1eb00e2703aef57cac19df9e86c54d275 Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Tue, 14 Mar 2017 12:15:52 +0000
Subject: [PATCH 03/15] oxenstored: comments explaining some variables
It took a while of reading and reasoning to work out what these are for, so here are comments to make life easier for everyone reading this code in future.
--- tools/ocaml/xenstored/store.ml | 1 + tools/ocaml/xenstored/transaction.ml | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 1f12baed15dc7502365afb54161827405ff24732 Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Tue, 14 Mar 2017 12:15:52 +0000
Subject: [PATCH 04/15] oxenstored: handling of domain conflict-credit
This commit gives each domain a conflict-credit variable, which will later be used for limiting how often a domain can cause other domain's transaction-commits to fail.
This commit also provides functions and data for manipulating domains and their conflict-credit, and checking whether they have credit.
--- tools/ocaml/xenstored/connection.ml | 5 ++ tools/ocaml/xenstored/define.ml | 3 + tools/ocaml/xenstored/domain.ml | 11 +++- tools/ocaml/xenstored/domains.ml | 103 ++++++++++++++++++++++++++++++- tools/ocaml/xenstored/oxenstored.conf.in | 32 ++++++++++ tools/ocaml/xenstored/transaction.ml | 2 + tools/ocaml/xenstored/xenstored.ml | 2 + 7 files changed, 154 insertions(+), 4 deletions(-)
tools/ocaml/xenstored/domains.ml +101 -2
103 lines not on this page · raw message
tools/ocaml/xenstored/oxenstored.conf.in +32 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From e0f02f8fb5a5130a37bd7efdc80d7f0dd46db41e Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Tue, 14 Mar 2017 12:15:52 +0000
Subject: [PATCH 05/15] oxenstored: ignore domains with no conflict-credit
When processing connections, skip those from domains with no remaining conflict-credit.
Also, issue a point of conflict-credit at regular intervals, the period being set by the configuration option "conflict-max-history- seconds". When issuing conflict-credit, we give a point either to every domain at once (one each) or only to the single domain at the front of the queue, depending on the configuration option "conflict-rate-limit-is-aggregate".
--- tools/ocaml/xenstored/connections.ml | 14 ++++--- tools/ocaml/xenstored/define.ml | 1 + tools/ocaml/xenstored/domains.ml | 4 +- tools/ocaml/xenstored/oxenstored.conf.in | 2 +- tools/ocaml/xenstored/xenstored.ml | 65 +++++++++++++++++++++++--------- 5 files changed, 60 insertions(+), 26 deletions(-)
tools/ocaml/xenstored/oxenstored.conf.in +1 -1
Lines of this file are not shown. View the raw message.
tools/ocaml/xenstored/xenstored.ml +48 -17
65 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From eedcaba31d907b889f571113e7d9739e5ce1e9e5 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Tue, 14 Mar 2017 12:17:38 +0000
Subject: [PATCH 06/15] oxenstored: add transaction info relevant to
history-tracking
Specifically:
* retain the original store (not just the root) in full transactions
* store commit count at the time of the start of the transaction
--- tools/ocaml/xenstored/process.ml | 2 +- tools/ocaml/xenstored/transaction.ml | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 5df600ee06458eebf037f6bff663b0a9273e3a3f Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Tue, 14 Mar 2017 13:20:07 +0000
Subject: [PATCH 07/15] oxenstored: support commit history tracking
Add ability to track xenstore tree operations -- either non-transactional operations or committed transactions.
For now, the call to actually retain commits is commented out because history can grow without bound.
For now, we call record_commit for all non-transactional operations. A subsequent patch will make it retain only the ones with side-effects.
--- tools/ocaml/xenstored/Makefile | 1 + tools/ocaml/xenstored/history.ml | 43 ++++++++++++++++++++++++++++++++++++++ tools/ocaml/xenstored/process.ml | 24 +++++++++++++++++++-- tools/ocaml/xenstored/xenstored.ml | 1 + 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 tools/ocaml/xenstored/history.ml
tools/ocaml/xenstored/history.ml new file +43 -0
43 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From f8083d52b6314f92718316f160eea47fef47988e Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 14:20:33 +0000
Subject: [PATCH 08/15] oxenstored: only record operations with side-effects in
history
There is no need to record "read" operations as they will never cause another transaction to fail.
--- tools/ocaml/xenstored/process.ml | 47 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-)
tools/ocaml/xenstored/process.ml +43 -4
47 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 66bdbbc41a45d2bf59ddb4ff26c52c1cc546f720 Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Thu, 23 Mar 2017 14:25:16 +0000
Subject: [PATCH 09/15] oxenstored: discard old commit-history on txn end
The history of commits is to be used for working out which historical commit(s) (including atomic writes) caused conflicts with a currently-failing commit of a transaction. Any commit that was made before the current transaction started cannot be relevant. Therefore we never need to keep history from before the start of the longest-running transaction that is open at any given time: whenever a transaction ends (with or without a commit) then if it was the longest-running open transaction we can delete history up until start of the the next-longest-running open transaction.
Some transactions might stay open for a very long time, so if any transaction exceeds conflict_max_history_seconds then we remove it from consideration in this context, and will not guarantee to keep remembering about historical commits made during such a transaction.
We implement this by keeping a list of all open transactions that have not been open too long. When a transaction ends, we remove it from the list, along with any that have been open longer than the maximum; then we delete any history from before the start of the longest-running transaction remaining in the list.
--- tools/ocaml/xenstored/history.ml | 17 +++++++++++++++++ tools/ocaml/xenstored/process.ml | 4 ++-- tools/ocaml/xenstored/transaction.ml | 29 +++++++++++++++++++++++++---- 3 files changed, 44 insertions(+), 6 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 2e94c635a652a575cb1f25f7dc5bc0ebcdbedcc4 Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Mon, 27 Mar 2017 08:58:29 +0000
Subject: [PATCH 10/15] oxenstored: track commit history
Since the list of historic activity cannot grow without bound, it is safe to use this to track commits.
--- tools/ocaml/xenstored/process.ml | 5 ----- 1 file changed, 5 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 0972f3e46001e9b3192786033663ef4ee423f8be Mon Sep 17 00:00:00 2001
From: Jonathan Davies <[email protected]>
Date: Thu, 23 Mar 2017 14:28:16 +0000
Subject: [PATCH 11/15] oxenstored: blame the connection that caused a
transaction conflict
Blame each connection found to have made a commit that would cause this transaction to fail. Each blamed connection is penalised by having its conflict-credit decremented.
Note the change in semantics for the replay function: we no longer stop after finding the first operation that can't be replayed. This allows us to identify all operations that conflicted with this transaction, not just the one that conflicted first.
v1 Reviewed-by: Christian Lindig <[email protected]>
Changes since v1:
* use correct log levels for informational messages
Changes since v2:
* fix the blame algorithm and improve logging (fix was reviewed by Jonathan Davies)
--- tools/ocaml/xenstored/history.ml | 12 ++++++++++ tools/ocaml/xenstored/process.ml | 50 ++++++++++++++++++++++++++++++++-------- 2 files changed, 52 insertions(+), 10 deletions(-)
tools/ocaml/xenstored/process.ml +40 -10
50 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From d3a8b4ffde38f01aa7f497d07404478b6f90041c Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Thu, 23 Mar 2017 19:06:54 +0000
Subject: [PATCH 12/15] oxenstored: allow self-conflicts
We already avoid inter-domain conflicts but now allow intra-domain conflicts. Although there are no known practical examples of a domain that might perform operations that conflict with its own transactions, this is conceivable, so here we avoid changing those semantics unnecessarily.
When a transaction commit fails with a conflict and we look through the history of commits to see which connection(s) to blame, ignore historical commits that were made by the same connection as the failing commit.
--- tools/ocaml/xenstored/history.ml | 3 ++- tools/ocaml/xenstored/process.ml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From f45ce51771c7e96c8ac8179c44476f8fc6168636 Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Fri, 24 Mar 2017 16:16:10 +0000
Subject: [PATCH 13/15] oxenstored: do not commit read-only transactions
The packet telling us to end the transaction has always carried an argument telling us whether to commit.
If the transaction made no modifications to the tree, now we ignore that argument and do not commit: it is just a waste of effort.
This makes read-only transactions immune to conflicts, and means that we do not need to store any of their details in the history that is used for assigning blame for conflicts.
We count a transaction as a read-only transaction only if it contains no operations that modified the tree.
This means that (for example) a transaction that creates a new node then deletes it would NOT count as read-only, even though it makes no change overall. A more sophisticated algorithm could judge the transaction based on comparison of its initial and final states, but this would add complexity and computational cost.
--- tools/ocaml/xenstored/process.ml | 1 + tools/ocaml/xenstored/transaction.ml | 1 + 2 files changed, 2 insertions(+)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 374c6a67e3d139a04ecde127a63ce70d24ed7b45 Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Fri, 24 Mar 2017 19:55:03 +0000
Subject: [PATCH 14/15] oxenstored: don't wake to issue no conflict-credit
In the main loop, when choosing the timeout for the select function call, we were setting it so as to wake up to issue conflict-credit to any domains that could accept it. When xenstore is idle, this would mean waking up every 50ms (by default) to do no work. With this commit, we check whether any domain is below its cap, and if not then we set the timeout for longer (the same timeout as before the conflict-protection feature was added).
--- tools/ocaml/xenstored/domains.ml | 51 ++++++++++++++++++++++++++++++-------- tools/ocaml/xenstored/xenstored.ml | 5 +++- 2 files changed, 44 insertions(+), 12 deletions(-)
tools/ocaml/xenstored/domains.ml +40 -11
51 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From d7d0c021115d40177035a0626ed47681b034b584 Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Mon, 27 Mar 2017 14:36:34 +0100
Subject: [PATCH 15/15] oxenstored transaction conflicts: improve logging
For information related to transaction conflicts, potentially frequent logging at "info" priority has been changed to "debug" priority, and once per two minutes there is an "info" priority summary.
Additional detailed logging has been added at "debug" priority.
--- tools/ocaml/xenstored/domain.ml | 8 ++++++++ tools/ocaml/xenstored/domains.ml | 5 +++++ tools/ocaml/xenstored/process.ml | 6 +++++- tools/ocaml/xenstored/transaction.ml | 5 +++++ tools/ocaml/xenstored/xenstored.ml | 6 ++++++ 5 files changed, 29 insertions(+), 1 deletion(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.4
From 26b15d4eb7ac71fcab28a7fca664afa0549c135c Mon Sep 17 00:00:00 2001
From: Thomas Sanders <[email protected]>
Date: Tue, 28 Mar 2017 18:57:52 +0100
Subject: [PATCH 16/15] oxenstored: trim history in the frequent_ops function
We were trimming the history of commits only at the end of each transaction (regardless of how it ended).
Therefore if non-transactional writes were being made but no transactions were being ended, the history would grow indefinitely. Now we trim the history at regular intervals.
--- tools/ocaml/xenstored/history.ml | 6 +++--- tools/ocaml/xenstored/transaction.ml | 8 ++++++-- tools/ocaml/xenstored/xenstored.ml | 1 + 3 files changed, 10 insertions(+), 5 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.9.5
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Part of the diff is not shown here. View the raw message.
Quoted 7 lines · Xen.org security team
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1Xen Security Advisory XSA-206
version 9xenstore denial of service via repeated update
I am seeing a build failure from these patches when using gcc 7. The problem is with
xsa206-4.80002-xenstored-Log-when-the-write-transaction-rate-limit-.patch because in tools/xenstore/xenstored_domain.c the patch adds the boolean wrl_delay_logged to the structure "domain" but later it tries to increment it, resulting in the error xenstored_domain.c: In function 'wrl_apply_debit_actual':
xenstored_domain.c:949:32: error: increment of a boolean expression [-Werror=bool-operation]
if (!domain->wrl_delay_logged++) {
Michael Young
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
(dropping some of the lists)
Michael Young writes ("Re: [Xen-devel] Xen Security Advisory 206 - xenstore denial of service via repeated update"):
Quoted 14 lines · Xen.org security team
Quoted 3 lines
Xen Security Advisory XSA-206
version 9
xenstore denial of service via repeated updateI am seeing a build failure from these patches when using gcc 7. The problem is with xsa206-4.80002-xenstored-Log-when-the-write-transaction-rate-limit-.patch because in
tools/xenstore/xenstored_domain.cthe patch adds the booleanwrl_delay_loggedto the structure "domain" but later it tries to increment it, resulting in the errorxenstored_domain.c: In function 'wrl_apply_debit_actual':
xenstored_domain.c:949:32: error: increment of a boolean expression [-Werror=bool-operation]
Quoted 1 line
if (!domain->wrl_delay_logged++) {I think this warning is wrong.
1. Increment of a boolean expression is perfectly well-defined:
With _Bool b;', b++' is equivalent to `b += 1' (C99 6.5.3.1(2))
That in turn is equivalent to `b = b + 1' (except that the lvalue b is evaluated only once) (C99 6.5.16.2(3))
The expression b + 1 is of type int (because 1 is of type int and b gets promoted to int by the usual arithmetic conversions (6.3.1.8, 6.3.1.1) since _Bool is the lowest ranked type. So the expression has value 1 or 2.
The constraints for the assignment (6.5.16.1) are satisfied because both operands are arithmetic. The right operand is converted to the type of the left (6.5.16.1(2)). Ie we convert (int)1 or (int)2 to _Bool.
This is defined to be a zero-test (6.3.1.2) so the assigned value is 1.
2. Increment of a boolean expression feels more idiomatic to me, certainly in this case, than plain assignment of 1. (It is also more flexible in case the code should be changed to count rather than simply flag.)
It's a shame that we can't disable the warning about incrementing or decrementing booleans, from other possible useful warnings such as attempts to bitwise-invert them.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Ian Jackson writes ("Re: [Xen-devel] Xen Security Advisory 206 - xenstore denial of service via repeated update"):
Quoted 4 lines
Quoted 2 lines
[-Werror=bool-operation]
if (!domain->wrl_delay_logged++) {I think this warning is wrong.
...
Quoted 3 lines
It's a shame that we can't disable the warning about incrementing or decrementing booleans, from other possible useful warnings such as attempts to bitwise-invert them.
Michael, can you confirm whether the patch below fixes it for you ?
If so we will commit it to staging, and also add this to the XSA-206 series (which we are currently waiting to apply to the stable trees...)
Thanks,
Ian.
tools/xenstore/Makefile +1 -0
@@ -5,6 +5,7 @@ MAJOR = 3.0 MINOR = 3 CFLAGS += -Werror +CFLAGS += -Wno-bool-operation CFLAGS += -I. # Include configure output (config.h) CFLAGS += -include $(XEN_ROOT)/tools/config.h
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 10 lines · Ian Jackson
Ian Jackson writes ("Re: [Xen-devel] Xen Security Advisory 206 - xenstore denial of service via repeated update"):
Quoted 4 lines
Quoted 2 lines
[-Werror=bool-operation]
if (!domain->wrl_delay_logged++) {I think this warning is wrong.
...
Quoted 3 lines
It's a shame that we can't disable the warning about incrementing or decrementing booleans, from other possible useful warnings such as attempts to bitwise-invert them.
Quoted 7 lines
Michael, can you confirm whether the patch below fixes it for you ?
If so we will commit it to staging, and also add this to the XSA-206 series (which we are currently waiting to apply to the stable trees...)
Thanks,
Ian.
Yes, xen builds with this patch.
Michael Young
Quoted 7 lines
tools/xenstore/Makefile +0
-0
tools/xenstore/Makefile MAJOR = 3.0 · line 11
Quoted 7 lines
tools/xenstore/Makefile +1
-0@@ -5,6 +5,7 @@ MAJOR = 3.0 MINOR = 3 CFLAGS += -Werror +CFLAGS += -Wno-bool-operation CFLAGS += -I. # Include configure output (config.h) CFLAGS += -include $(XEN_ROOT)/tools/config.h
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
M A Young writes ("Re: [Xen-devel] Xen Security Advisory 206 - xenstore denial of service via repeated update"):
Quoted 5 lines · Ian Jackson
Quoted 4 lines
Michael, can you confirm whether the patch below fixes it for you ?
If so we will commit it to staging, and also add this to the XSA-206 series (which we are currently waiting to apply to the stable trees...)
..
Quoted 1 line
Yes, xen builds with this patch.
Thanks.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 1/1 tools/xenstore: Add -Wno-bool-operation
This suppresses a warning from GCC7
xenstored_domain.c:949:32: error: increment of a boolean expression
We have not yet 100% concluded that this should not be fixed by changing the _Bool b; b++;' to b = 1'. But this fixes the warning and thus the build for now, and we want to apply the XSA-206 patches to stable trees.
In the stable trees, this should be applied _before_ the XSA-206 series.
--- tools/xenstore/Makefile | 1 + 1 file changed, 1 insertion(+)
tools/xenstore/Makefile +1 -0
@@ -5,6 +5,7 @@ MAJOR = 3.0 MINOR = 3 CFLAGS += -Werror +CFLAGS += -Wno-bool-operation CFLAGS += -I. # Include configure output (config.h) CFLAGS += -include $(XEN_ROOT)/tools/config.h
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH] tools/xenstore: Add -Wno-bool-operation
Quoted 8 lines · Ian Jackson
This suppresses a warning from GCC7
xenstored_domain.c:949:32: error: increment of a boolean expressionWe have not yet 100% concluded that this should not be fixed by changing the
_Bool b; b++;' tob = 1'. But this fixes the warning and thus the build for now, and we want to apply the XSA-206 patches to stable trees.
Quoted 7 lines
In the stable trees, this should be applied _before_ the XSA-206 series.
Reported-by Michael Young <[email protected]>CC Wei Liu <[email protected]>CC Jan Beulich <[email protected]>Signed-off-by Ian Jackson <[email protected]>
I'm fairly sure this will break the Clang build.
Furthermore, the proper fix here is to make less "clever" code. IMO, this compiler warning is entirely legitimate, because relying on the saturation behaviour of incrementing a boolean is worthy only for obfuscated code.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH] tools/xenstore: Add -Wno-bool-operation
Andrew Cooper writes ("Re: [Xen-devel] [PATCH] tools/xenstore: Add -Wno-bool-operation"):
Quoted 1 line
I'm fairly sure this will break the Clang build.
This seems unlikely. I assume that clang has the same behaviour as gcc, for -Wno-unknown-warning.
Quoted 4 lines
Furthermore, the proper fix here is to make less "clever" code. IMO, this compiler warning is entirely legitimate, because relying on the saturation behaviour of incrementing a boolean is worthy only for obfuscated code.
I don't care to argue about this. Feel free to submit an alternative patch.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH] tools/xenstore: Add -Wno-bool-operation
Quoted 3 lines · Ian Jackson
Andrew Cooper writes ("Re: [Xen-devel] [PATCH]
tools/xenstore: Add -Wno-bool-operation"):Quoted 1 line
I'm fairly sure this will break the Clang build.
This seems unlikely.
Have you tried?
Quoted 1 line
I assume that clang has the same behaviour as gcc, for -Wno-unknown-warning.
Have you tried?
And independently of that,
andrewcoop@andrewcoop:/local/xen.git/xen$ git grep unknown-warning -- :/ andrewcoop@andrewcoop:/local/xen.git/xen$
Quoted 7 lines
Quoted 5 lines
Furthermore, the proper fix here is to make less "clever" code. IMO, this compiler warning is entirely legitimate, because relying on the saturation behaviour of incrementing a boolean is worthy only for obfuscated code.
I don't care to argue about this. Feel free to submit an alternative patch.
You have already identified the correct fix, which both makes the code clearer to read, and compiles properly. What is wrong with that?
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH] tools/xenstore: Add -Wno-bool-operation
Quoted 5 lines · Andrew Cooper
Quoted 3 lines · Ian Jackson
Andrew Cooper writes ("Re: [Xen-devel] [PATCH]
tools/xenstore: Add -Wno-bool-operation"):Quoted 1 line
I'm fairly sure this will break the Clang build.
This seems unlikely.
Have you tried?
In an attempt to not be completely unhelpful in this situation,
xenstore_client.o xenstore_client.c
error: unknown warning option '-Wno-bool-operation'; did you mean '-Wno-bool-conversion'? [-Werror,-Wunknown-warning-option] /local/xen.git/tools/xenstore/../../tools/Rules.mk:212: recipe for target 'xenstore_client.o' failed
Quoted 8 lines
Quoted 2 lines
I assume that clang has the same behaviour as gcc, for -Wno-unknown-warning.
Have you tried?
And independently of that,
andrewcoop@andrewcoop:/local/xen.git/xen$ git grep unknown-warning -- :/ andrewcoop@andrewcoop:/local/xen.git/xen$
xenstore_client.o xenstore_client.c
error: unknown warning option '-Wno-unknown-warning'; did you mean '-Wno-unknown-argument'? [-Werror,-Wunknown-warning-option] /local/xen.git/tools/xenstore/../../tools/Rules.mk:212: recipe for target 'xenstore_client.o' failed
This definitely breaks the clang build, and a GCC workaround don't help.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH] tools/xenstore: Add -Wno-bool-operation
In reply to Ian JacksonQuoted 7 lines
Quoted 1 line
Quoted 1 line · On 05.04.17 at 15:27, <[email protected]> wrote:
Andrew Cooper writes ("Re: [Xen-devel] [PATCH]
tools/xenstore: Add -Wno-bool-operation"):Quoted 1 line
I'm fairly sure this will break the Clang build.
This seems unlikely. I assume that clang has the same behaviour as gcc, for -Wno-unknown-warning.
I'm afraid this also breaks for older gcc (just tried 4.3.4), which we still consider supported. You need to probe the compiler via cc-option-add, just like done in ./Config.mk.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel