From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (unknown [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 025D680777 for ; Fri, 2 Oct 2026 21:28:10 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 692LR0uV026217; Sat, 3 Oct 2026 00:27:01 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 692LR0uV026217 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="iR4nJq1Y" Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 692LQjY7026178 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Sat, 3 Oct 2026 00:26:45 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 692LQjY7026178 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-48b01a74792so202165f8f.0 for ; Fri, 02 Oct 2026 14:26:45 -0700 (PDT) X-Forwarded-Encrypted: i=2; AKwUvBzSd5FAlsoHyAZTH0CQAP56wrfunZ/QgbD6AO+jRZWpoO5Huhs4qy5uwzzzrvsO7WNKMVschw==@openvz.org X-Gm-Message-State: AFq9FYJtZ1YTbAr4oriZGfuxo84+RaPqxjRhY5LWS4P75Dsy861DEQTZ bzNuvzK47ra9qWnCoHFouOXD5RNcqYJY+/G/UJi0pkKy3iKMscOGiflSN9QR2sNxvwV1TgxVNKM LkI6aZYr4unOFlGwZRP9ikH/qIsp9HvOy7D6R7Y2GjiKQmvfUlobpmQ== X-Gm-Gg: AYBFou2pRyCmDyBJ2BZ9rYDxV0RLWpBbSAJBVTuHh+cNSUvFd4n5THwNY2s+tudbOYz dxmKDH3+04eKVqyaJEyJBJT3x3T/tGppU3VAb187Th08wUHu50PI37FlfbPm7qFYEveB+3V9569 nAzifd0DTCmnMWYfeV4MQ7JfkhtDAxI1cqRd+3X+t+L/sLJyVmE//E+kuSbu+gG2aTeEOAOdPVR ZrKDel/cahn+se8na1ChQGeqcqycZ5rMFCFsESrE8xaYz2z6kHM71ZaptFPOG1KmUqGzCyCYXPP ZDE8+Yk3WhurJ50q35v6ma5cw/76293E4TGdsYILEXQMgAuVjlC1oy9KtsXmyki4DDuoCcmiLxX a7HFww1XKHxbW1eY4eJKzQ4a4zZkL X-Received: by 2002:a05:6000:2085:b0:48b:3b4:1c8e with SMTP id ffacd0b85a97d-48b1272c992mr7212622f8f.20.1790976405036; Fri, 02 Oct 2026 14:26:45 -0700 (PDT) X-Received: by 2002:a05:6000:2085:b0:48b:3b4:1c8e with SMTP id ffacd0b85a97d-48b1272c992mr7212600f8f.20.1790976404502; Fri, 02 Oct 2026 14:26:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1790976404; cv=none; d=google.com; s=arc-20260327; b=KNba9xnJeG7SdTdr598nlF/3lc1gbTRuOZJ14BD1kJtIqkcrr4VsfWROsTH7PZCFIS 6tObO/ookd6zb9e/7xYXoIgtBxywHSv1YL9oPKvzfUMCkTHOOazWZWJcksrSxZFBKdpV soWxbwf6cZF2Nl7ksaBWkBXOUKSHJdviwe1YMbV8tG565ygSI21wqmISicgrHIUvO1i4 iSbhCcAUDyYkpw4Jbr+eN7c7QtSxj34MsCQ0Dc8ge01cWNA6+rH2RNWLDLTJIQPYLJFa uDSIJbE+3vKu0uWG3x4SD1WYI+TgE5Bm8N2I/iFmmqgyRpG53yWbWXQc4t8xiU5+m41V YRgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=21ocynesDFgFZ8YnlZBMiDrVzSMJCIguEhOMdZmsXu8=; fh=vUECVpjOjIdz431s8bRiKYBdScEDOVhPZlDu2AQ+txg=; b=RWKQ3QGu57CXlxcI0xh97YiuCZu2GLFPA7Vp82gMAKulI76qJXC9LQ1/Hir365hZBq HNBgCjiq5I8MshEaj5Qw11LK48VQFOwkJ/gsho54Eh0cyxc0wuw1yrE3qe7fAdbyNASA 3cHJMC0SBaxWflFWixIMGazVLuHlCy1VURLMNOpUmw59TICKuCZZS1yuzmtt3hR5p9wy HAxeI7gAPZzeiWH7LG7x1Wja9Ayl4KrwvT/tP/c+YZaWsgKA4MeNGgNKDrMMmZibXG02 Ks02y85ubepO9il0Bzn1PzZNcWKIESeQoJApb/ExJ9y2RdKkD2BvXcY1emv1baFnyt3c dZiQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=iR4nJq1Y; spf=pass (google.com: domain of vladimir.riabchun@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=vladimir.riabchun@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id ffacd0b85a97d-48b5b448e90si6490003f8f.468.2026.10.02.14.26.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2026 14:26:44 -0700 (PDT) Received-SPF: pass (google.com: domain of vladimir.riabchun@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=iR4nJq1Y; spf=pass (google.com: domain of vladimir.riabchun@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=vladimir.riabchun@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=Message-Id:Content-Type:MIME-Version:Subject:Date :From; bh=21ocynesDFgFZ8YnlZBMiDrVzSMJCIguEhOMdZmsXu8=; b=iR4nJq1YU18AgOEUyjf qitcSbOh5GZ2Kjw+VfyWJZlLKIEwlM6bSRRQQ4GbQK9ERKWUQs9s9CfG/ZYLZaQerPla/ypW9ICAF j8MZwqNIlFPRSpb8Hfd3u4ukU5uTe5Rn3Uo78lwLFeIa6MhEo1M67WIE0tH5BIzMEUssqUA/w0JJH K99bLUEmdJM/Q+3VAfvO4nNLnMqvTQRxtNvXxTXa7iUgO6UvhgYmjGB9hJQR/VnoQ1TxM5XQUBoar lojt8JqAT4sMnbrH8IRsE99vRmiR5QIATyf9t8nRETdlfu4+9YHXgKKn6SbZRyLzENbX9RhmQPFnC hjlPMj8E628wl4w==; Received: from ch-demo-asa.virtuozzo.com ([130.117.225.8] helo=192.168.1.87) by relay.virtuozzo.com with esmtps (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1xCkj2-00GcBK-34; Fri, 02 Oct 2026 23:26:39 +0200 From: Vladimir Riabchun Date: Fri, 02 Oct 2026 23:26:13 +0200 MIME-Version: 1.0 Message-Id: <20261002-ve-printk-irq-v1-4-cb55896d455c@virtuozzo.com> References: <20261002-ve-printk-irq-v1-0-cb55896d455c@virtuozzo.com> In-Reply-To: <20261002-ve-printk-irq-v1-0-cb55896d455c@virtuozzo.com> To: Konstantin Khorenko , vasileios.almpanis@virtuozzo.com X-Mailer: b4 0.14.3 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 4/6] ve/printk: Fix time virtualization X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org The usage of get_exec_env() in ve_timens_add_boottime_ns can lead to time travels - a printk from IRQ might use container time for printing to host dmesg and vice versa. Fix this by adding timens_offsets info to printk_info entry. This way correct time is provided by the original printer of message, rather than printing job, that may be delayed and called from a different context. It seems complicated to keep time namespace in log_state, because VE creation and namespace creation happen at different times and it seems that one VE can have different time namespaces if it was stopped and then started again. So instead of tracking time namespaces, let's put actual time offsets into log state. https://virtuozzo.atlassian.net/browse/VSTOR-146839 Feature: ve printk Signed-off-by: Vladimir Riabchun --- kernel/printk/internal.h | 6 +++++ kernel/printk/printk.c | 51 ++++++++++++++++++++++++--------------- kernel/printk/printk_ringbuffer.h | 2 ++ 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h index d00ac40d8401..d0096aba5af7 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -4,6 +4,7 @@ */ #include #include +#include #include #if defined(CONFIG_PRINTK) && defined(CONFIG_SYSCTL) @@ -354,11 +355,16 @@ struct log_state { */ struct latched_seq clear_seq; struct printk_ringbuffer *prb; + /* Updated on every log_state request */ + struct timens_offsets time_offset; }; +#define GET_VE_LOG(ve) ((struct log_state *) ve->log_state) + extern struct log_state init_log_state; struct log_state *ve_log_state(void); +struct log_state *__ve_log_state(struct ve_struct *ve); bool printk_get_next_message(struct log_state *log, struct printk_message *pmsg, u64 seq, diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index df7cf83fb4af..575bd3590198 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -556,13 +556,28 @@ DEFINE_STRUCT_MEMBER_ALIAS(clear_seq, init_log_state, clear_seq); DEFINE_STRUCT_MEMBER_ALIAS(prb, init_log_state, prb); #undef DEFINE_STRUCT_MEMBER_ALIAS +static void update_log_time(struct ve_struct *ve) +{ + struct time_namespace *timens = ve_get_time_ns(ve); + + if (timens) + GET_VE_LOG(ve)->time_offset = timens->offsets; + else + GET_VE_LOG(ve)->time_offset = init_time_ns.offsets; + + if (timens) + put_time_ns(timens); +} + struct log_state *ve_log_state(void) { struct log_state *log = &init_log_state; #ifdef CONFIG_VE /* get_exec_env() is reliable only in task context */ - if (!WARN_ON_ONCE(!in_task()) && get_exec_env()->log_state) + if (!WARN_ON_ONCE(!in_task()) && get_exec_env()->log_state) { + update_log_time(get_exec_env()); log = get_exec_env()->log_state; + } #endif return log; } @@ -571,8 +586,10 @@ struct log_state *__ve_log_state(struct ve_struct *ve) { struct log_state *log = &init_log_state; #ifdef CONFIG_VE - if (ve->log_state) + if (ve->log_state) { + update_log_time(ve); log = ve->log_state; + } #endif return log; } @@ -698,21 +715,10 @@ static void append_char(char **pp, char *e, char c) *(*pp)++ = c; } -static inline u64 ve_timens_add_boottime_ns(u64 nsec) +static inline u64 ve_timens_add_boottime_ns(u64 nsec, const struct timens_offsets *off) { - struct time_namespace *ve_time_ns; - struct timens_offsets *ns_offsets; - - ve_time_ns = ve_get_time_ns(get_exec_env()); - if (unlikely(!ve_time_ns)) { - /* container not yet started */ - return nsec; - } - - ns_offsets = &ve_time_ns->offsets; - nsec += ns_offsets->boottime.tv_sec * NSEC_PER_SEC; - nsec += ns_offsets->boottime.tv_nsec; - put_time_ns(ve_time_ns); + nsec += off->boottime.tv_sec * NSEC_PER_SEC; + nsec += off->boottime.tv_nsec; return nsec; } @@ -732,7 +738,7 @@ static ssize_t info_print_ext_header(char *buf, size_t size, #endif /* shift the timestamp on the Container uptime value */ - ts_usec = ve_timens_add_boottime_ns(ts_usec); + ts_usec = ve_timens_add_boottime_ns(ts_usec, &info->time_offset); do_div(ts_usec, 1000); return scnprintf(buf, size, "%u,%llu,%llu,%c%s;", @@ -1108,6 +1114,7 @@ void log_buf_vmcoreinfo_setup(void) VMCOREINFO_OFFSET(printk_info, text_len); VMCOREINFO_OFFSET(printk_info, caller_id); VMCOREINFO_OFFSET(printk_info, dev_info); + VMCOREINFO_OFFSET(printk_info, time_offset); VMCOREINFO_STRUCT_SIZE(dev_printk_info); VMCOREINFO_OFFSET(dev_printk_info, subsystem); @@ -1219,6 +1226,7 @@ static unsigned int __init add_to_rb(struct printk_ringbuffer *rb, dest_r.info->ts_nsec = r->info->ts_nsec; dest_r.info->caller_id = r->info->caller_id; memcpy(&dest_r.info->dev_info, &r->info->dev_info, sizeof(dest_r.info->dev_info)); + dest_r.info->time_offset = r->info->time_offset; prb_final_commit(&e); @@ -1427,12 +1435,13 @@ static size_t print_syslog(unsigned int level, char *buf) return sprintf(buf, "<%u>", level); } -static size_t print_time(u64 ts, char *buf) +static size_t print_time(const struct printk_info *info, char *buf) { unsigned long rem_nsec; + u64 ts; /* shift the timestamp on the Container uptime value */ - ts = ve_timens_add_boottime_ns(ts); + ts = ve_timens_add_boottime_ns(info->ts_nsec, &info->time_offset); rem_nsec = do_div(ts, 1000000000); @@ -1462,7 +1471,7 @@ static size_t info_print_prefix(const struct printk_info *info, bool syslog, len = print_syslog((info->facility << 3) | info->level, buf); if (time) - len += print_time(info->ts_nsec, buf + len); + len += print_time(info, buf + len); len += print_caller(info->caller_id, buf + len); @@ -2402,6 +2411,8 @@ static int vprintk_store_log(struct log_state *log, int facility, int level, if (dev_info) memcpy(&r.info->dev_info, dev_info, sizeof(r.info->dev_info)); + r.info->time_offset = log->time_offset; + /* A message without a trailing newline can be continued. */ if (!(flags & LOG_NEWLINE)) prb_commit(&e); diff --git a/kernel/printk/printk_ringbuffer.h b/kernel/printk/printk_ringbuffer.h index 4ef81349d9fb..19052ba005fc 100644 --- a/kernel/printk/printk_ringbuffer.h +++ b/kernel/printk/printk_ringbuffer.h @@ -7,6 +7,7 @@ #include #include #include +#include #include /* @@ -25,6 +26,7 @@ struct printk_info { u32 caller_id; /* thread id or processor id */ struct dev_printk_info dev_info; + struct timens_offsets time_offset; /* Author timens offsets */ }; /* -- 2.52.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel