From nobody Sun Feb 8 16:31:10 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1582554302; cv=none; d=zohomail.com; s=zohoarc; b=moaMXVk6eP5Pltych7eooKnmULXvo6yDCqfuxOrN8L489gFYm57zeQQylt+esu3BtAq0JhXsMc+0SOgz02HCDnVJMvG9B+fT1zJj4lfcNBN4DVp27P622uYWXj7O+dE3+5/OdMvxtBGnEPHGu/qnNdTT1O6yOcpVIYGKgxDSdMI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582554302; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=r8QAJ/K5WSzX8EQkTjHiFM6T6WSl/z9vpf7UX72Fy4Y=; b=Z9GWPFsRdM8/gfewDLDJGfE67Qa1qI5k0s4l60jN+gC25pEbRFglSI3BIiPl8AmFOYSWRRv/rJjzDRBHWVBHXe6HHx63Eb8Br10M8f8jW5L8N/l8i7edSNfMprWBlSGWKRJNcOhH8Y2/G6+/UjA9W7yRUXnQll8Mt59JPHdVo6k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1582554302457747.1150217375449; Mon, 24 Feb 2020 06:25:02 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-362-VBBIOieTPiGQII5V7Iir7g-1; Mon, 24 Feb 2020 09:24:58 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 664C0107ACC4; Mon, 24 Feb 2020 14:24:53 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2FDD660BF7; Mon, 24 Feb 2020 14:24:53 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 98D7C18089CE; Mon, 24 Feb 2020 14:24:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 01OEOpMY023356 for ; Mon, 24 Feb 2020 09:24:51 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0D49C10EE781; Mon, 24 Feb 2020 14:24:51 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 08A5910EE77C for ; Mon, 24 Feb 2020 14:24:48 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6257885A308 for ; Mon, 24 Feb 2020 14:24:48 +0000 (UTC) Received: from mail-qt1-f196.google.com (mail-qt1-f196.google.com [209.85.160.196]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-84-j6bJKxNgNKOh6kq96JGTnw-1; Mon, 24 Feb 2020 09:24:45 -0500 Received: by mail-qt1-f196.google.com with SMTP id r5so6627647qtt.9 for ; Mon, 24 Feb 2020 06:24:45 -0800 (PST) Received: from localhost.localdomain (201-69-8-70.dial-up.telesp.net.br. [201.69.8.70]) by smtp.gmail.com with ESMTPSA id o16sm6092364qtr.28.2020.02.24.06.24.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2020 06:24:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582554301; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=r8QAJ/K5WSzX8EQkTjHiFM6T6WSl/z9vpf7UX72Fy4Y=; b=NDSa4iLqO5IXchACUcmy6XiQJqWtLAmSQ1zRL+bLr8CO3W6r0Pym20OSFakzDnOk+qhULY FyzAue0OqZFd4bqL71db6vv9HQAUgKuGmtnnIbm24KXt0DBJl92D1vPw42jKDG+Nq5zSnd nrK2HoPtUJHYqJURtQJYrrn3lj7M0QY= X-MC-Unique: VBBIOieTPiGQII5V7Iir7g-1 X-MC-Unique: j6bJKxNgNKOh6kq96JGTnw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8ms+LnZVHFXemnCQePHWGsYOsN66AV6zwoPKVGBUS1M=; b=lsMsnPHhivrrlFJOmdmgrNvPfUkNVT4qm9euvjwpNF7A6lIA3VZdq5claO/SOs4Kp2 332ezBNU8pSwwActYVZlxxc6bMc/s9T78iZ81VF5t4pgGFBIV5N4qQHqa4m5y7IY7r2i ouTG6mYyNKRvHalkDLYFYkgmtCd9TmReIXn5Rn/Cmc8HFutI54Yc6p5jaSuIpPjbRsgh pDBwcZD0R7Kw0qfKG1tzKa8ybHWU/sOrThRs1xg5LqNFuojFrY1tpinA6C6r5ptkLHrd ZeuJyklgh/lpLRrNBEzwSZd51vEQsQltmUvrOaZDb0I79PHbnhYsUtq+yJ0Z8k3fqwNP 4m4g== X-Gm-Message-State: APjAAAXLRxsb+rOF83Ij87wEyX+RhBtBF0i9mGk+EnMSR1F64Pu9bahD YQRmB96aZg77zavLgJV7nMjUO6bS X-Google-Smtp-Source: APXvYqwUq/3L+ASA8AFKSW3hyJPP7ac2KNnvRcoBtCRn5cF6nm0Fb7b9GxdFooWUA3YBA2jz9aCYBw== X-Received: by 2002:aed:2ae7:: with SMTP id t94mr47808898qtd.130.1582554284016; Mon, 24 Feb 2020 06:24:44 -0800 (PST) From: Julio Faracco To: libvir-list@redhat.com Subject: [PATCH v4 1/5] lxc: Add Real Time Clock device into allowed devices Date: Mon, 24 Feb 2020 11:24:24 -0300 Message-Id: <20200224142428.538-2-jcfaracco@gmail.com> In-Reply-To: <20200224142428.538-1-jcfaracco@gmail.com> References: <20200224142428.538-1-jcfaracco@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 01OEOpMY023356 X-loop: libvir-list@redhat.com Cc: danielhb413@gmail.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This commit share host Real Time Clock device (rtc) into LXC containers to support hardware clock. This should be available setting up a `rtc` timer under clock section. Since this option is not emulated, it should be available only for `localtime` clock. This option should be readonly due to security reasons. Before: root# hwclock --verbose hwclock from util-linux 2.32.1 System Time: 1581877557.598365 Trying to open: /dev/rtc0 Trying to open: /dev/rtc Trying to open: /dev/misc/rtc No usable clock interface found. hwclock: Cannot access the Hardware Clock via any known method. Now: root# hwclock 2020-02-16 18:23:55.374134+00:00 root# hwclock -w hwclock: ioctl(RTC_SET_TIME) to /dev/rtc to set the time failed: Permission denied Signed-off-by: Julio Faracco --- docs/formatdomain.html.in | 2 +- src/lxc/lxc_cgroup.c | 36 +++++++++++++++++++++ src/lxc/lxc_controller.c | 68 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 1 deletion(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 4fef2a0a97..5598bf41b4 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -2465,7 +2465,7 @@ being modified, and can be one of "platform" (currently unsupported), "hpet" (libxl, xen, qemu), "kvmclock" (qemu), - "pit" (qemu), "rtc" (qemu), "tsc" (libxl, qemu - + "pit" (qemu), "rtc" (qemu, lxc), "tsc" (libxl, qemu - since 3.2.0), "hypervclock" (qemu - since 1.2.2) or "armvtimer" (qemu - since 6.1.0). diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 4ebe5ef467..6a103055a4 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -337,6 +337,42 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr = def, VIR_CGROUP_DEVICE_RWM) < 0) return -1; =20 + VIR_DEBUG("Allowing timers char devices"); + + /* Sync'ed with Host clock */ + if (def->clock.offset =3D=3D VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME) { + for (i =3D 0; i < def->clock.ntimers; i++) { + virDomainTimerDefPtr timer =3D def->clock.timers[i]; + + switch ((virDomainTimerNameType)timer->name) { + case VIR_DOMAIN_TIMER_NAME_PLATFORM: + case VIR_DOMAIN_TIMER_NAME_TSC: + case VIR_DOMAIN_TIMER_NAME_KVMCLOCK: + case VIR_DOMAIN_TIMER_NAME_HYPERVCLOCK: + case VIR_DOMAIN_TIMER_NAME_PIT: + case VIR_DOMAIN_TIMER_NAME_HPET: + case VIR_DOMAIN_TIMER_NAME_ARMVTIMER: + case VIR_DOMAIN_TIMER_NAME_LAST: + break; + case VIR_DOMAIN_TIMER_NAME_RTC: + if (!timer->present) + break; + + if (virFileExists("/dev/rtc")) { + if (virCgroupAllowDevicePath(cgroup, "/dev/rtc", + VIR_CGROUP_DEVICE_READ, + false) < 0) + return -1; + } else { + VIR_DEBUG("Ignoring non-existent device /dev/rtc"); + } + break; + } + } + } else { + VIR_DEBUG("Ignoring non-localtime clock"); + } + VIR_DEBUG("Device whitelist complete"); =20 return 0; diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index c3dec0859c..eba6bfe0bf 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -1550,6 +1550,71 @@ static int virLXCControllerPopulateDevices(virLXCCon= trollerPtr ctrl) } =20 =20 +static int +virLXCControllerSetupTimers(virLXCControllerPtr ctrl) +{ + g_autofree char *path =3D NULL; + size_t i; + struct stat sb; + virDomainDefPtr def =3D ctrl->def; + + /* Not sync'ed with Host clock */ + if (def->clock.offset !=3D VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME) + return 0; + + for (i =3D 0; i < def->clock.ntimers; i++) { + dev_t dev; + virDomainTimerDefPtr timer =3D def->clock.timers[i]; + + switch ((virDomainTimerNameType)timer->name) { + case VIR_DOMAIN_TIMER_NAME_PLATFORM: + case VIR_DOMAIN_TIMER_NAME_TSC: + case VIR_DOMAIN_TIMER_NAME_KVMCLOCK: + case VIR_DOMAIN_TIMER_NAME_HYPERVCLOCK: + case VIR_DOMAIN_TIMER_NAME_PIT: + case VIR_DOMAIN_TIMER_NAME_HPET: + case VIR_DOMAIN_TIMER_NAME_ARMVTIMER: + case VIR_DOMAIN_TIMER_NAME_LAST: + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unsupported timer type (name) '%s'"), + virDomainTimerNameTypeToString(timer->name)); + return -1; + case VIR_DOMAIN_TIMER_NAME_RTC: + if (!timer->present) + break; + + if (stat("/dev/rtc", &sb) < 0) { + if (errno =3D=3D EACCES) + return -1; + + virReportSystemError(errno, + _("Path '%s' is not accessible"), + path); + return -1; + } + + path =3D g_strdup_printf("/%s/%s.dev/%s", LXC_STATE_DIR, + ctrl->def->name, "/rtc"); + + dev =3D makedev(major(sb.st_rdev), minor(sb.st_rdev)); + if (mknod(path, S_IFCHR, dev) < 0 || + chmod(path, sb.st_mode)) { + virReportSystemError(errno, + _("Failed to make device %s"), + path); + return -1; + } + + if (lxcContainerChown(ctrl->def, path) < 0) + return -1; + break; + } + } + + return 0; +} + + static int virLXCControllerSetupHostdevSubsysUSB(virDomainDefPtr vmDef, virDomainHostdevDefPtr def, @@ -2352,6 +2417,9 @@ virLXCControllerRun(virLXCControllerPtr ctrl) if (virLXCControllerPopulateDevices(ctrl) < 0) goto cleanup; =20 + if (virLXCControllerSetupTimers(ctrl) < 0) + goto cleanup; + if (virLXCControllerSetupAllDisks(ctrl) < 0) goto cleanup; =20 --=20 2.20.1