All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] docs/mm: extend ksm doc
@ 2023-03-14 20:45 Stefan Roesch
  2023-03-15  3:59 ` Bagas Sanjaya
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Roesch @ 2023-03-14 20:45 UTC (permalink / raw)
  To: kernel-team; +Cc: shr, linux-mm, riel, mhocko, david, linux-doc, akpm, hannes

This adds a description of the new prctl interface for KSM and also adds
a general section on security concerns.

Signed-off-by: Stefan Roesch <shr@devkernel.io>
---
 Documentation/admin-guide/mm/ksm.rst | 41 +++++++++++++++++++++++++++-
 1 file changed, 40 insertions(+), 1 deletion(-)

diff --git a/Documentation/admin-guide/mm/ksm.rst b/Documentation/admin-guide/mm/ksm.rst
index d2929964cd0f..ba75d628f6d7 100644
--- a/Documentation/admin-guide/mm/ksm.rst
+++ b/Documentation/admin-guide/mm/ksm.rst
@@ -20,13 +20,15 @@ content which can be replaced by a single write-protected page (which
 is automatically copied if a process later wants to update its
 content). The amount of pages that KSM daemon scans in a single pass
 and the time between the passes are configured using :ref:`sysfs
-intraface <ksm_sysfs>`
+interface <ksm_sysfs>`
 
 KSM only merges anonymous (private) pages, never pagecache (file) pages.
 KSM's merged pages were originally locked into kernel memory, but can now
 be swapped out just like other user pages (but sharing is broken when they
 are swapped back in: ksmd must rediscover their identity and merge again).
 
+.. _ksm_madvise:
+
 Controlling KSM with madvise
 ============================
 
@@ -68,6 +70,43 @@ Applications should be considerate in their use of MADV_MERGEABLE,
 restricting its use to areas likely to benefit.  KSM's scans may use a lot
 of processing power: some installations will disable KSM for that reason.
 
+Controlling KSM with prctl
+============================
+
+KSM can be enabled for a process or a cgroup, by using the prctl(2) system
+call::
+
+	int prctl(PR_SET_MEMORY_MERGE, 1)
+
+The app may call
+
+::
+
+	int prctl(PR_SET_MEMORY_MERGE, 0)
+
+to cancel that advice and restore unshared pages: whereupon KSM
+unmerges whatever is merged for that process.  Note: this unmerging call
+may suddenly require more memory than is available - possibly failing
+with EAGAIN, but more probably arousing the Out-Of-Memory killer.
+
+The restrictions mentioned in :ref:`Controlling KSM with madvise <ksm_madvise>`'
+also apply here. Also consider the security implications of using KSM.
+
+KSM security concerns
+=======================
+
+KSM has the possibility of memory side channel attacks. When individual
+VMA's have KSM enabled, the security aspect needs to be considered.
+
+An individual workload doesn't know what else is running on
+the machine, so it needs to be highly conservative about what it can
+give up for system-wide merging.
+
+However, if the system is dedicated to running multiple jobs within the
+same security domain, there is a usecase where multiple instances of the
+same job are running inside a safe shared security domain and using the
+same sensitive data.
+
 .. _ksm_sysfs:
 
 KSM daemon sysfs interface

base-commit: 5faf25f023d8816a49e168930218ffdb75d5d853
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v1] docs/mm: extend ksm doc
  2023-03-14 20:45 [PATCH v1] docs/mm: extend ksm doc Stefan Roesch
@ 2023-03-15  3:59 ` Bagas Sanjaya
  2023-03-15  4:28   ` Randy Dunlap
  2023-03-15 15:59   ` Stefan Roesch
  0 siblings, 2 replies; 4+ messages in thread
From: Bagas Sanjaya @ 2023-03-15  3:59 UTC (permalink / raw)
  To: Stefan Roesch, kernel-team
  Cc: linux-mm, riel, mhocko, david, linux-doc, akpm, hannes

[-- Attachment #1: Type: text/plain, Size: 895 bytes --]

On Tue, Mar 14, 2023 at 01:45:57PM -0700, Stefan Roesch wrote:
> +to cancel that advice and restore unshared pages: whereupon KSM
> +unmerges whatever is merged for that process.  Note: this unmerging call
> +may suddenly require more memory than is available - possibly failing
> +with EAGAIN, but more probably arousing the Out-Of-Memory killer.

"... to disable KSM and let it unmerges ... . Note that this unmerging
call may exhaust memory and triggers OOM killer."

> +However, if the system is dedicated to running multiple jobs within the
> +same security domain, there is a usecase where multiple instances of the
> +same job are running inside a safe shared security domain and using the
> +same sensitive data.

"... it is possible for multiple instances ... and share the same
sensitive data."

Thanks. 

-- 
An old man doll... just what I always wanted! - Clara

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v1] docs/mm: extend ksm doc
  2023-03-15  3:59 ` Bagas Sanjaya
@ 2023-03-15  4:28   ` Randy Dunlap
  2023-03-15 15:59   ` Stefan Roesch
  1 sibling, 0 replies; 4+ messages in thread
From: Randy Dunlap @ 2023-03-15  4:28 UTC (permalink / raw)
  To: Bagas Sanjaya, Stefan Roesch, kernel-team
  Cc: linux-mm, riel, mhocko, david, linux-doc, akpm, hannes

Hi--

On 3/14/23 20:59, Bagas Sanjaya wrote:
> On Tue, Mar 14, 2023 at 01:45:57PM -0700, Stefan Roesch wrote:
>> +to cancel that advice and restore unshared pages: whereupon KSM
>> +unmerges whatever is merged for that process.  Note: this unmerging call
>> +may suddenly require more memory than is available - possibly failing
>> +with EAGAIN, but more probably arousing the Out-Of-Memory killer.
> 
> "... to disable KSM and let it unmerges ... . Note that this unmerging
> call may exhaust memory and triggers OOM killer."

I can't tell exactly what is being proposed here, but "let it unmerges"
is not good & proper...

Perhaps fewer ellipses and more complete sentences are in order.

>> +However, if the system is dedicated to running multiple jobs within the
>> +same security domain, there is a usecase where multiple instances of the
>> +same job are running inside a safe shared security domain and using the
>> +same sensitive data.
> 
> "... it is possible for multiple instances ... and share the same
> sensitive data."
> 
> Thanks. 
> 

-- 
~Randy

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v1] docs/mm: extend ksm doc
  2023-03-15  3:59 ` Bagas Sanjaya
  2023-03-15  4:28   ` Randy Dunlap
@ 2023-03-15 15:59   ` Stefan Roesch
  1 sibling, 0 replies; 4+ messages in thread
From: Stefan Roesch @ 2023-03-15 15:59 UTC (permalink / raw)
  To: Bagas Sanjaya
  Cc: kernel-team, linux-mm, riel, mhocko, david, linux-doc, akpm, hannes


Bagas Sanjaya <bagasdotme@gmail.com> writes:

> [[PGP Signed Part:Undecided]]
> On Tue, Mar 14, 2023 at 01:45:57PM -0700, Stefan Roesch wrote:
>> +to cancel that advice and restore unshared pages: whereupon KSM
>> +unmerges whatever is merged for that process.  Note: this unmerging call
>> +may suddenly require more memory than is available - possibly failing
>> +with EAGAIN, but more probably arousing the Out-Of-Memory killer.
>

This follows the wording in the previous paragraph, do you also want to
change the previous paragraph?

> "... to disable KSM and let it unmerges ... . Note that this unmerging
> call may exhaust memory and triggers OOM killer."
>
>> +However, if the system is dedicated to running multiple jobs within the
>> +same security domain, there is a usecase where multiple instances of the
>> +same job are running inside a safe shared security domain and using the
>> +same sensitive data.
>
> "... it is possible for multiple instances ... and share the same
> sensitive data."
>

Something like this?

>> +However, if the system is dedicated to running multiple jobs within the
>> +same security domain, there is a usecase where multiple instances of the
>> +same job are running inside a safe shared security domain and share the
>> +same sensitive data.
>

The is possible I think is less clear.

 Thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-03-15 16:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-14 20:45 [PATCH v1] docs/mm: extend ksm doc Stefan Roesch
2023-03-15  3:59 ` Bagas Sanjaya
2023-03-15  4:28   ` Randy Dunlap
2023-03-15 15:59   ` Stefan Roesch

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.