All of lore.kernel.org
 help / color / mirror / Atom feed
* [PULL 0/5] migration queue
@ 2020-07-03 15:27 Dr. David Alan Gilbert (git)
  2020-07-03 15:27 ` [PULL 1/5] virtiofsd: Terminate capability list Dr. David Alan Gilbert (git)
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Dr. David Alan Gilbert (git) @ 2020-07-03 15:27 UTC (permalink / raw)
  To: qemu-devel, quintela, zhukeqian1, stefanha

From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

The following changes since commit 6651620b92bc08cde07cb500e9a43dba7bd9b2b7:

  Merge remote-tracking branch 'remotes/kraxel/tags/seabios-20200702-pull-request' into staging (2020-07-03 09:55:35 +0100)

are available in the Git repository at:

  git://github.com/dagrh/qemu.git tags/pull-migration-20200703a

for you to fetch changes up to fb6135807fcab4670d69663ac88e88e124348ffd:

  migration: Count new_dirty instead of real_dirty (2020-07-03 16:23:05 +0100)

----------------------------------------------------------------
virtiofsd+migration pull 2020-07-03

A couple of small migration fixes, and some capability
rework for virtiofsd.

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

----------------------------------------------------------------
Dr. David Alan Gilbert (4):
      virtiofsd: Terminate capability list
      virtiofsd: Check capability calls
      virtiofsd: Allow addition or removal of capabilities
      migration: postcopy take proper error return

Keqian Zhu (1):
      migration: Count new_dirty instead of real_dirty

 docs/tools/virtiofsd.rst         |  5 +++
 include/exec/ram_addr.h          |  5 +--
 migration/postcopy-ram.c         |  2 +-
 migration/ram.c                  |  8 +++--
 tools/virtiofsd/helper.c         |  2 ++
 tools/virtiofsd/passthrough_ll.c | 71 +++++++++++++++++++++++++++++++++++++---
 6 files changed, 80 insertions(+), 13 deletions(-)



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

* [PULL 1/5] virtiofsd: Terminate capability list
  2020-07-03 15:27 [PULL 0/5] migration queue Dr. David Alan Gilbert (git)
@ 2020-07-03 15:27 ` Dr. David Alan Gilbert (git)
  2020-07-03 15:27 ` [PULL 2/5] virtiofsd: Check capability calls Dr. David Alan Gilbert (git)
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Dr. David Alan Gilbert (git) @ 2020-07-03 15:27 UTC (permalink / raw)
  To: qemu-devel, quintela, zhukeqian1, stefanha

From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

capng_updatev is a varargs function that needs a -1 to terminate it,
but it was missing.

In practice what seems to have been happening is that it's added the
capabilities we asked for, then runs into junk on the stack, so if
we're unlucky it might be adding some more, but in reality it's
failing - but after adding the capabilities we asked for.

Fixes: a59feb483b8 ("virtiofsd: only retain file system capabilities")
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Message-Id: <20200629115420.98443-2-dgilbert@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 tools/virtiofsd/passthrough_ll.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
index 2ce7c96085..e373e3b36e 100644
--- a/tools/virtiofsd/passthrough_ll.c
+++ b/tools/virtiofsd/passthrough_ll.c
@@ -2598,7 +2598,9 @@ static void setup_capabilities(void)
             CAP_SETGID,
             CAP_SETUID,
             CAP_MKNOD,
-            CAP_SETFCAP);
+            CAP_SETFCAP,
+            -1);
+
     capng_apply(CAPNG_SELECT_BOTH);
 
     cap.saved = capng_save_state();
-- 
2.26.2



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

* [PULL 2/5] virtiofsd: Check capability calls
  2020-07-03 15:27 [PULL 0/5] migration queue Dr. David Alan Gilbert (git)
  2020-07-03 15:27 ` [PULL 1/5] virtiofsd: Terminate capability list Dr. David Alan Gilbert (git)
@ 2020-07-03 15:27 ` Dr. David Alan Gilbert (git)
  2020-07-03 15:27 ` [PULL 3/5] virtiofsd: Allow addition or removal of capabilities Dr. David Alan Gilbert (git)
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Dr. David Alan Gilbert (git) @ 2020-07-03 15:27 UTC (permalink / raw)
  To: qemu-devel, quintela, zhukeqian1, stefanha

From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

Check the capability calls worked.

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Message-Id: <20200629115420.98443-3-dgilbert@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 tools/virtiofsd/passthrough_ll.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
index e373e3b36e..99d562046a 100644
--- a/tools/virtiofsd/passthrough_ll.c
+++ b/tools/virtiofsd/passthrough_ll.c
@@ -2589,7 +2589,7 @@ static void setup_capabilities(void)
      */
     capng_setpid(syscall(SYS_gettid));
     capng_clear(CAPNG_SELECT_BOTH);
-    capng_updatev(CAPNG_ADD, CAPNG_PERMITTED | CAPNG_EFFECTIVE,
+    if (capng_updatev(CAPNG_ADD, CAPNG_PERMITTED | CAPNG_EFFECTIVE,
             CAP_CHOWN,
             CAP_DAC_OVERRIDE,
             CAP_DAC_READ_SEARCH,
@@ -2599,11 +2599,21 @@ static void setup_capabilities(void)
             CAP_SETUID,
             CAP_MKNOD,
             CAP_SETFCAP,
-            -1);
+            -1)) {
+        fuse_log(FUSE_LOG_ERR, "%s: capng_updatev failed\n", __func__);
+        exit(1);
+    }
 
-    capng_apply(CAPNG_SELECT_BOTH);
+    if (capng_apply(CAPNG_SELECT_BOTH)) {
+        fuse_log(FUSE_LOG_ERR, "%s: capng_apply failed\n", __func__);
+        exit(1);
+    }
 
     cap.saved = capng_save_state();
+    if (!cap.saved) {
+        fuse_log(FUSE_LOG_ERR, "%s: capng_save_state failed\n", __func__);
+        exit(1);
+    }
     pthread_mutex_unlock(&cap.mutex);
 }
 
-- 
2.26.2



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

* [PULL 3/5] virtiofsd: Allow addition or removal of capabilities
  2020-07-03 15:27 [PULL 0/5] migration queue Dr. David Alan Gilbert (git)
  2020-07-03 15:27 ` [PULL 1/5] virtiofsd: Terminate capability list Dr. David Alan Gilbert (git)
  2020-07-03 15:27 ` [PULL 2/5] virtiofsd: Check capability calls Dr. David Alan Gilbert (git)
@ 2020-07-03 15:27 ` Dr. David Alan Gilbert (git)
  2020-07-03 15:27 ` [PULL 4/5] migration: postcopy take proper error return Dr. David Alan Gilbert (git)
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Dr. David Alan Gilbert (git) @ 2020-07-03 15:27 UTC (permalink / raw)
  To: qemu-devel, quintela, zhukeqian1, stefanha

From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

Allow capabilities to be added or removed from the allowed set for the
daemon; e.g.

default:
CapPrm: 00000000880000df
CapEff: 00000000880000df

-o modcaps=+sys_admin

CapPrm: 00000000882000df
CapEff: 00000000882000df

-o modcaps=+sys_admin:-chown

CapPrm: 00000000882000de
CapEff: 00000000882000de

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Message-Id: <20200629115420.98443-4-dgilbert@redhat.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 docs/tools/virtiofsd.rst         |  5 +++
 tools/virtiofsd/helper.c         |  2 ++
 tools/virtiofsd/passthrough_ll.c | 53 ++++++++++++++++++++++++++++++--
 3 files changed, 58 insertions(+), 2 deletions(-)

diff --git a/docs/tools/virtiofsd.rst b/docs/tools/virtiofsd.rst
index 378594c422..824e713491 100644
--- a/docs/tools/virtiofsd.rst
+++ b/docs/tools/virtiofsd.rst
@@ -54,6 +54,11 @@ Options
   * flock|no_flock -
     Enable/disable flock.  The default is ``no_flock``.
 
+  * modcaps=CAPLIST
+    Modify the list of capabilities allowed; CAPLIST is a colon separated
+    list of capabilities, each preceded by either + or -, e.g.
+    ''+sys_admin:-chown''.
+
   * log_level=LEVEL -
     Print only log messages matching LEVEL or more severe.  LEVEL is one of
     ``err``, ``warn``, ``info``, or ``debug``.  The default is ``info``.
diff --git a/tools/virtiofsd/helper.c b/tools/virtiofsd/helper.c
index 00a1ef666a..3105b6c23a 100644
--- a/tools/virtiofsd/helper.c
+++ b/tools/virtiofsd/helper.c
@@ -174,6 +174,8 @@ void fuse_cmdline_help(void)
            "                               default: no_writeback\n"
            "    -o xattr|no_xattr          enable/disable xattr\n"
            "                               default: no_xattr\n"
+           "    -o modcaps=CAPLIST         Modify the list of capabilities\n"
+           "                               e.g. -o modcaps=+sys_admin:-chown\n"
            "    --rlimit-nofile=<num>      set maximum number of file descriptors\n"
            "                               (0 leaves rlimit unchanged)\n"
            "                               default: min(1000000, fs.file-max - 16384)\n"
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
index 99d562046a..94e0de2d2b 100644
--- a/tools/virtiofsd/passthrough_ll.c
+++ b/tools/virtiofsd/passthrough_ll.c
@@ -145,6 +145,7 @@ struct lo_data {
     int posix_lock;
     int xattr;
     char *source;
+    char *modcaps;
     double timeout;
     int cache;
     int timeout_set;
@@ -170,6 +171,7 @@ static const struct fuse_opt lo_opts[] = {
     { "no_posix_lock", offsetof(struct lo_data, posix_lock), 0 },
     { "xattr", offsetof(struct lo_data, xattr), 1 },
     { "no_xattr", offsetof(struct lo_data, xattr), 0 },
+    { "modcaps=%s", offsetof(struct lo_data, modcaps), 0 },
     { "timeout=%lf", offsetof(struct lo_data, timeout), 0 },
     { "timeout=", offsetof(struct lo_data, timeout_set), 1 },
     { "cache=none", offsetof(struct lo_data, cache), CACHE_NONE },
@@ -2570,9 +2572,11 @@ static void setup_mounts(const char *source)
 
 /*
  * Only keep whitelisted capabilities that are needed for file system operation
+ * The (possibly NULL) modcaps_in string passed in is free'd before exit.
  */
-static void setup_capabilities(void)
+static void setup_capabilities(char *modcaps_in)
 {
+    char *modcaps = modcaps_in;
     pthread_mutex_lock(&cap.mutex);
     capng_restore_state(&cap.saved);
 
@@ -2604,6 +2608,51 @@ static void setup_capabilities(void)
         exit(1);
     }
 
+    /*
+     * The modcaps option is a colon separated list of caps,
+     * each preceded by either + or -.
+     */
+    while (modcaps) {
+        capng_act_t action;
+        int cap;
+
+        char *next = strchr(modcaps, ':');
+        if (next) {
+            *next = '\0';
+            next++;
+        }
+
+        switch (modcaps[0]) {
+        case '+':
+            action = CAPNG_ADD;
+            break;
+
+        case '-':
+            action = CAPNG_DROP;
+            break;
+
+        default:
+            fuse_log(FUSE_LOG_ERR,
+                     "%s: Expecting '+'/'-' in modcaps but found '%c'\n",
+                     __func__, modcaps[0]);
+            exit(1);
+        }
+        cap = capng_name_to_capability(modcaps + 1);
+        if (cap < 0) {
+            fuse_log(FUSE_LOG_ERR, "%s: Unknown capability '%s'\n", __func__,
+                     modcaps);
+            exit(1);
+        }
+        if (capng_update(action, CAPNG_PERMITTED | CAPNG_EFFECTIVE, cap)) {
+            fuse_log(FUSE_LOG_ERR, "%s: capng_update failed for '%s'\n",
+                     __func__, modcaps);
+            exit(1);
+        }
+
+        modcaps = next;
+    }
+    g_free(modcaps_in);
+
     if (capng_apply(CAPNG_SELECT_BOTH)) {
         fuse_log(FUSE_LOG_ERR, "%s: capng_apply failed\n", __func__);
         exit(1);
@@ -2627,7 +2676,7 @@ static void setup_sandbox(struct lo_data *lo, struct fuse_session *se,
     setup_namespaces(lo, se);
     setup_mounts(lo->source);
     setup_seccomp(enable_syslog);
-    setup_capabilities();
+    setup_capabilities(g_strdup(lo->modcaps));
 }
 
 /* Set the maximum number of open file descriptors */
-- 
2.26.2



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

* [PULL 4/5] migration: postcopy take proper error return
  2020-07-03 15:27 [PULL 0/5] migration queue Dr. David Alan Gilbert (git)
                   ` (2 preceding siblings ...)
  2020-07-03 15:27 ` [PULL 3/5] virtiofsd: Allow addition or removal of capabilities Dr. David Alan Gilbert (git)
@ 2020-07-03 15:27 ` Dr. David Alan Gilbert (git)
  2020-07-03 15:27 ` [PULL 5/5] migration: Count new_dirty instead of real_dirty Dr. David Alan Gilbert (git)
  2020-07-04 15:08 ` [PULL 0/5] migration queue Peter Maydell
  5 siblings, 0 replies; 7+ messages in thread
From: Dr. David Alan Gilbert (git) @ 2020-07-03 15:27 UTC (permalink / raw)
  To: qemu-devel, quintela, zhukeqian1, stefanha

From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

This function returns a boolean success and we're returning -1;
lets just use the 'out' error path.

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Fixes: 58b7c17e226 ("Disable mlock around incoming postcopy")
Buglink: https://bugs.launchpad.net/qemu/+bug/1885720
Message-Id: <20200701093557.130096-1-dgilbert@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 migration/postcopy-ram.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
index a36402722b..bef2a3afed 100644
--- a/migration/postcopy-ram.c
+++ b/migration/postcopy-ram.c
@@ -389,7 +389,7 @@ bool postcopy_ram_supported_by_host(MigrationIncomingState *mis)
      */
     if (munlockall()) {
         error_report("%s: munlockall: %s", __func__,  strerror(errno));
-        return -1;
+        goto out;
     }
 
     /*
-- 
2.26.2



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

* [PULL 5/5] migration: Count new_dirty instead of real_dirty
  2020-07-03 15:27 [PULL 0/5] migration queue Dr. David Alan Gilbert (git)
                   ` (3 preceding siblings ...)
  2020-07-03 15:27 ` [PULL 4/5] migration: postcopy take proper error return Dr. David Alan Gilbert (git)
@ 2020-07-03 15:27 ` Dr. David Alan Gilbert (git)
  2020-07-04 15:08 ` [PULL 0/5] migration queue Peter Maydell
  5 siblings, 0 replies; 7+ messages in thread
From: Dr. David Alan Gilbert (git) @ 2020-07-03 15:27 UTC (permalink / raw)
  To: qemu-devel, quintela, zhukeqian1, stefanha

From: Keqian Zhu <zhukeqian1@huawei.com>

real_dirty_pages becomes equal to total ram size after dirty log sync
in ram_init_bitmaps, the reason is that the bitmap of ramblock is
initialized to be all set, so old path counts them as "real dirty" at
beginning.

This causes wrong dirty rate and false positive throttling.

Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com>
Message-Id: <20200622032037.31112-1-zhukeqian1@huawei.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 include/exec/ram_addr.h | 5 +----
 migration/ram.c         | 8 +++++---
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
index 7b5c24e928..3ef729a23c 100644
--- a/include/exec/ram_addr.h
+++ b/include/exec/ram_addr.h
@@ -442,8 +442,7 @@ static inline void cpu_physical_memory_clear_dirty_range(ram_addr_t start,
 static inline
 uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb,
                                                ram_addr_t start,
-                                               ram_addr_t length,
-                                               uint64_t *real_dirty_pages)
+                                               ram_addr_t length)
 {
     ram_addr_t addr;
     unsigned long word = BIT_WORD((start + rb->offset) >> TARGET_PAGE_BITS);
@@ -469,7 +468,6 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb,
             if (src[idx][offset]) {
                 unsigned long bits = atomic_xchg(&src[idx][offset], 0);
                 unsigned long new_dirty;
-                *real_dirty_pages += ctpopl(bits);
                 new_dirty = ~dest[k];
                 dest[k] |= bits;
                 new_dirty &= bits;
@@ -502,7 +500,6 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb,
                         start + addr + offset,
                         TARGET_PAGE_SIZE,
                         DIRTY_MEMORY_MIGRATION)) {
-                *real_dirty_pages += 1;
                 long k = (start + addr) >> TARGET_PAGE_BITS;
                 if (!test_and_set_bit(k, dest)) {
                     num_dirty++;
diff --git a/migration/ram.c b/migration/ram.c
index 069b6e30bc..5554a7d2d8 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -859,9 +859,11 @@ static inline bool migration_bitmap_clear_dirty(RAMState *rs,
 /* Called with RCU critical section */
 static void ramblock_sync_dirty_bitmap(RAMState *rs, RAMBlock *rb)
 {
-    rs->migration_dirty_pages +=
-        cpu_physical_memory_sync_dirty_bitmap(rb, 0, rb->used_length,
-                                              &rs->num_dirty_pages_period);
+    uint64_t new_dirty_pages =
+        cpu_physical_memory_sync_dirty_bitmap(rb, 0, rb->used_length);
+
+    rs->migration_dirty_pages += new_dirty_pages;
+    rs->num_dirty_pages_period += new_dirty_pages;
 }
 
 /**
-- 
2.26.2



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

* Re: [PULL 0/5] migration queue
  2020-07-03 15:27 [PULL 0/5] migration queue Dr. David Alan Gilbert (git)
                   ` (4 preceding siblings ...)
  2020-07-03 15:27 ` [PULL 5/5] migration: Count new_dirty instead of real_dirty Dr. David Alan Gilbert (git)
@ 2020-07-04 15:08 ` Peter Maydell
  5 siblings, 0 replies; 7+ messages in thread
From: Peter Maydell @ 2020-07-04 15:08 UTC (permalink / raw)
  To: Dr. David Alan Gilbert (git)
  Cc: Keqian Zhu, QEMU Developers, Stefan Hajnoczi, Juan Quintela

On Fri, 3 Jul 2020 at 16:30, Dr. David Alan Gilbert (git)
<dgilbert@redhat.com> wrote:
>
> From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
>
> The following changes since commit 6651620b92bc08cde07cb500e9a43dba7bd9b2b7:
>
>   Merge remote-tracking branch 'remotes/kraxel/tags/seabios-20200702-pull-request' into staging (2020-07-03 09:55:35 +0100)
>
> are available in the Git repository at:
>
>   git://github.com/dagrh/qemu.git tags/pull-migration-20200703a
>
> for you to fetch changes up to fb6135807fcab4670d69663ac88e88e124348ffd:
>
>   migration: Count new_dirty instead of real_dirty (2020-07-03 16:23:05 +0100)
>
> ----------------------------------------------------------------
> virtiofsd+migration pull 2020-07-03
>
> A couple of small migration fixes, and some capability
> rework for virtiofsd.
>
> Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
>
> ----------------------------------------------------------------


Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/5.1
for any user-visible changes.

-- PMM


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

end of thread, other threads:[~2020-07-04 15:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-03 15:27 [PULL 0/5] migration queue Dr. David Alan Gilbert (git)
2020-07-03 15:27 ` [PULL 1/5] virtiofsd: Terminate capability list Dr. David Alan Gilbert (git)
2020-07-03 15:27 ` [PULL 2/5] virtiofsd: Check capability calls Dr. David Alan Gilbert (git)
2020-07-03 15:27 ` [PULL 3/5] virtiofsd: Allow addition or removal of capabilities Dr. David Alan Gilbert (git)
2020-07-03 15:27 ` [PULL 4/5] migration: postcopy take proper error return Dr. David Alan Gilbert (git)
2020-07-03 15:27 ` [PULL 5/5] migration: Count new_dirty instead of real_dirty Dr. David Alan Gilbert (git)
2020-07-04 15:08 ` [PULL 0/5] migration queue Peter Maydell

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.