From nobody Sun May 5 16:06:25 2024 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=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1590747130; cv=none; d=zohomail.com; s=zohoarc; b=auWfebbLfiUaa2l3yJmLt0WOJJyjEktNZr4HxaYl0dabQRzSx+99Ysk2s2kGlD2kTQLLpaoM1IKWu4CFo8QQkeRl8IPocegQbrdA2I1cvjyiKnboRAHbF+lWpzstw/FoMepqioSurmZXUn5F1+v+lZe2xFVKNr4f7/Hfk0x0TQU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590747130; 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=w0PEaaQmw/799eQVEzp4ht9hof44/ySiFjaLmBstouA=; b=ZN0EiP1d8jYlqc+4o3tLLiwMJNX6x9bRcxpzNJYfBpXSJNcGik5cY7v4jo7BhZDEfucW1MS2EUwmsyZ1iXpmzZlhXlN3IcNjpbf9tLffJ6hD/j17B8rWHXsUzcht0Yy7xSeliMWfgVnj6+Jrju9B2aPpVlrqkhKjdCdwxpwe/tY= 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 1590747130690858.5538058143901; Fri, 29 May 2020 03:12:10 -0700 (PDT) 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-146-Rd8J_11VN26OhqR2G0G4sQ-1; Fri, 29 May 2020 06:12:07 -0400 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 B70A618A0724; Fri, 29 May 2020 10:12:01 +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 376A460E1C; Fri, 29 May 2020 10:12:01 +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 A6845180954D; Fri, 29 May 2020 10:12:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04TAAPV4030448 for ; Fri, 29 May 2020 06:10:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id 25E6C2026E1C; Fri, 29 May 2020 10:10:25 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1DCA42029F62 for ; Fri, 29 May 2020 10:10:22 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (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 2C795811E7A for ; Fri, 29 May 2020 10:10:22 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-99-8T-nLxT6N3aNLm65oclX9A-1; Fri, 29 May 2020 06:10:17 -0400 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 04TA2QTA178982; Fri, 29 May 2020 06:10:16 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 31as1hbkpd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 29 May 2020 06:10:16 -0400 Received: from m0098414.ppops.net (m0098414.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 04TA2sVx181008; Fri, 29 May 2020 06:10:15 -0400 Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0b-001b2d01.pphosted.com with ESMTP id 31as1hbknh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 29 May 2020 06:10:15 -0400 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 04TA76n2020372; Fri, 29 May 2020 10:10:14 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma03fra.de.ibm.com with ESMTP id 316uf84qxp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 29 May 2020 10:10:13 +0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 04TAAAio46268546 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 29 May 2020 10:10:10 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A169042041; Fri, 29 May 2020 10:10:10 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 21F8F42056; Fri, 29 May 2020 10:10:10 +0000 (GMT) Received: from normandy.boeblingen.de.ibm.com (unknown [9.145.145.249]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 29 May 2020 10:10:10 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590747129; 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=w0PEaaQmw/799eQVEzp4ht9hof44/ySiFjaLmBstouA=; b=dMOW8hEYk9XpwK/mVab1IAN7oxeby6t0eBKFVbdZOO8spmTXxTd6F0tKd8m3Gs6KpzZO0b t9KL3eKypLi9g1zXY1BynJtThmdGF764AxodaF3I5yB64CZrZjhoiuaP3AboycYrk/PbTj +Jn6bQmx/8tIPG8lR0+72byQW3w7VA8= X-MC-Unique: Rd8J_11VN26OhqR2G0G4sQ-1 X-MC-Unique: 8T-nLxT6N3aNLm65oclX9A-1 From: Paulo de Rezende Pinatti To: libvir-list@redhat.com, fiuczy@linux.ibm.com, mihajlov@linux.ibm.com, berrange@redhat.com, brijesh.singh@amd.com, borntraeger@de.ibm.com, eskultet@redhat.com Subject: [PATCH v2 1/7] util: introduce a parser for kernel cmdline arguments Date: Fri, 29 May 2020 12:10:03 +0200 Message-Id: <20200529101009.130358-2-ppinatti@linux.ibm.com> In-Reply-To: <20200529101009.130358-1-ppinatti@linux.ibm.com> References: <20200529101009.130358-1-ppinatti@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216, 18.0.687 definitions=2020-05-29_02:2020-05-28, 2020-05-29 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 suspectscore=2 spamscore=0 adultscore=0 clxscore=1015 priorityscore=1501 impostorscore=0 malwarescore=0 cotscore=-2147483648 mlxlogscore=999 mlxscore=0 phishscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005290075 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 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" Introduce two utility functions to parse a kernel command line string according to the kernel code parsing rules in order to enable the caller to perform operations such as verifying whether certain argument=3Dvalue combinations are present or retrieving an argument's value. Signed-off-by: Paulo de Rezende Pinatti Signed-off-by: Boris Fiuczynski Reviewed-by: Bjoern Walk --- src/libvirt_private.syms | 2 + src/util/virutil.c | 169 +++++++++++++++++++++++++++++++++++++++ src/util/virutil.h | 17 ++++ tests/utiltest.c | 141 ++++++++++++++++++++++++++++++++ 4 files changed, 329 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a6af44fe1c..a206a943c5 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3433,6 +3433,8 @@ virHostGetDRMRenderNode; virHostHasIOMMU; virIndexToDiskName; virIsDevMapperDevice; +virKernelCmdlineMatchParam; +virKernelCmdlineNextParam; virMemoryLimitIsSet; virMemoryLimitTruncate; virMemoryMaxValue; diff --git a/src/util/virutil.c b/src/util/virutil.c index fb46501142..749c9d7116 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -1725,6 +1725,175 @@ virHostGetDRMRenderNode(void) return ret; } =20 + +static const char *virKernelCmdlineSkipDbQuote(const char *cmdline, + bool *is_quoted) +{ + if (cmdline[0] =3D=3D '"') { + *is_quoted =3D !(*is_quoted); + cmdline++; + } + return cmdline; +} + + +static size_t virKernelCmdlineSearchForward(const char *cmdline, + bool *is_quoted, + bool include_equal) +{ + size_t index; + + for (index =3D 0; cmdline[index]; index++) { + if ((!(*is_quoted) && g_ascii_isspace(cmdline[index])) || + (include_equal && cmdline[index] =3D=3D '=3D')) + break; + virKernelCmdlineSkipDbQuote(cmdline + index, is_quoted); + } + return index; +} + + +static size_t virKernelCmdlineNextSpace(const char *cmdline, + bool *is_quoted) +{ + return virKernelCmdlineSearchForward(cmdline, is_quoted, false); +} + + +static size_t virKernelCmdlineNextSpaceOrEqual(const char *cmdline, + bool *is_quoted) +{ + return virKernelCmdlineSearchForward(cmdline, is_quoted, true); +} + + +static char* virKernelArgNormalize(const char *arg) +{ + return virStringReplace(arg, "_", "-"); +} + + +static char* virKernelCmdlineArgNormalize(const char *cmdline, size_t offs= et) +{ + g_autofree char *param =3D g_strndup((cmdline), offset); + + return virKernelArgNormalize(param); +} + + +/* + * Parse the kernel cmdline and store the next parameter in @param + * and the value of @param in @val which can be NULL if @param has + * no value. In addition returns the address right after @param=3D@value + * for possible further processing. + * + * @cmdline: kernel command line string to be checked for next parameter + * @param: pointer to hold retrieved parameter, will be NULL if none found + * @val: pointer to hold retrieved value of @param + * + * Returns a pointer to address right after @param=3D@val in the + * kernel command line, will point to the string's end (NULL) + * in case no next parameter is found + */ +const char *virKernelCmdlineNextParam(const char *cmdline, + char **param, + char **val) +{ + size_t offset; + bool is_quoted =3D false; + *param =3D NULL; + *val =3D NULL; + + virSkipSpaces(&cmdline); + cmdline =3D virKernelCmdlineSkipDbQuote(cmdline, &is_quoted); + offset =3D virKernelCmdlineNextSpaceOrEqual(cmdline, &is_quoted); + if (offset =3D=3D 0) + return cmdline; + + *param =3D virKernelCmdlineArgNormalize(cmdline, offset); + cmdline =3D cmdline + offset; + /* param has no value */ + if (*cmdline !=3D '=3D') + return cmdline; + + cmdline =3D virKernelCmdlineSkipDbQuote(++cmdline, &is_quoted); + offset =3D virKernelCmdlineNextSpace(cmdline, &is_quoted); + if (cmdline[offset-1] =3D=3D '"') + *val =3D g_strndup(cmdline, offset-1); + else + *val =3D g_strndup(cmdline, offset); + + return cmdline + offset; +} + + +#define VIR_CMDLINE_STR_CMP(kernel_val, caller_val, flags) \ + (((flags & VIR_KERNEL_CMDLINE_FLAGS_CMP_EQ) && \ + STREQ(kernel_val, caller_val)) || ((flags & VIR_KERNEL_CMDLINE_FLAGS= _CMP_PREFIX) && \ + STRPREFIX(kernel_val, caller_val)= )) + + +/* + * Try to match the provided kernel cmdline string with the provided @arg + * and the list @values of possible values according to the matching strat= egy + * defined in @flags. Possible options include: + * - VIR_KERNEL_CMDLINE_FLAGS_CMP_PREFIX: do a substring comparison of val= ues + * (uses size of value provided as input) + * - VIR_KERNEL_CMDLINE_FLAGS_CMP_EQ: do a strict string comparison of val= ues + * - VIR_KERNEL_CMDLINE_FLAGS_SEARCH_STICKY: first positive match satifies= search + * (in case of multiple argument occurrences) + * - VIR_KERNEL_CMDLINE_FLAGS_SEARCH_LAST: use the result of last argument= occurence + * (in case of multiple argument occurrences) + * + * @cmdline: kernel command line string to be checked for @arg + * @arg: kernel command line argument + * @values: array of possible values to match @arg + * @len_values: size of array, it can be 0 meaning a match will be positiv= e if the + * argument has no value. + * @flags: flag mask defining the strategy for matching and comparing + * + * Returns true if a match is found, false otherwise + */ +bool virKernelCmdlineMatchParam(const char *cmdline, + const char *arg, + const char **values, + size_t len_values, + virKernelCmdlineFlags flags) +{ + bool match =3D false; + size_t i; + const char *next =3D cmdline; + g_autofree char *norm_arg =3D virKernelArgNormalize(arg); + g_autofree char *kparam =3D NULL; + g_autofree char *kval =3D NULL; + + while (next[0] !=3D '\0') { + VIR_FREE(kparam); + VIR_FREE(kval); + next =3D virKernelCmdlineNextParam(next, &kparam, &kval); + if (!kparam) + break; + if (STRNEQ(kparam, norm_arg)) + continue; + if (!kval) { + match =3D (len_values =3D=3D 0) ? true : false; + } else { + match =3D false; + for (i =3D 0; i < len_values; i++) { + if (VIR_CMDLINE_STR_CMP(kval, values[i], flags)) { + match =3D true; + break; + } + } + } + if (match && (flags & VIR_KERNEL_CMDLINE_FLAGS_SEARCH_STICKY)) + break; + } + + return match; +} + + /* * Get a password from the console input stream. * The caller must free the returned password. diff --git a/src/util/virutil.h b/src/util/virutil.h index 49b4bf440f..7499b78153 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -147,6 +147,23 @@ bool virHostHasIOMMU(void); =20 char *virHostGetDRMRenderNode(void) G_GNUC_NO_INLINE; =20 +typedef enum { + VIR_KERNEL_CMDLINE_FLAGS_CMP_PREFIX =3D 1, + VIR_KERNEL_CMDLINE_FLAGS_CMP_EQ =3D 2, + VIR_KERNEL_CMDLINE_FLAGS_SEARCH_STICKY =3D 4, + VIR_KERNEL_CMDLINE_FLAGS_SEARCH_LAST =3D 8, +} virKernelCmdlineFlags; + +const char *virKernelCmdlineNextParam(const char *cmdline, + char **param, + char **val); + +bool virKernelCmdlineMatchParam(const char *cmdline, + const char *arg, + const char **values, + size_t len_values, + virKernelCmdlineFlags flags); + /** * VIR_ASSIGN_IS_OVERFLOW: * @rvalue: value that is checked (evaluated twice) diff --git a/tests/utiltest.c b/tests/utiltest.c index 5ae04585cb..01fb8c89f5 100644 --- a/tests/utiltest.c +++ b/tests/utiltest.c @@ -254,6 +254,145 @@ testOverflowCheckMacro(const void *data G_GNUC_UNUSED) } =20 =20 +struct testKernelCmdlineNextParamData +{ + const char *cmdline; + const char *param; + const char *val; + const char *next; +}; + +static struct testKernelCmdlineNextParamData kEntries[] =3D { + { "arg1 arg2 arg3=3Dval1", "arg1", = NULL, " arg2 arg3=3Dval1" }, + { "arg1=3Dval1 arg2 arg3=3Dval3 arg4", "arg1", = "val1", " arg2 arg3=3Dval3 arg4" }, + { "arg3=3Dval3 ", "arg3", = "val3", " " }, + { "arg3=3Dval3", "arg3", = "val3", "" }, + { "arg-3=3Dval3 arg4", "arg-3", = "val3", " arg4" }, + { "arg_3=3Dval3 arg4", "arg-3", = "val3", " arg4" }, + { " arg_3=3Dval3 arg4", "arg-3", = "val3", " arg4" }, + { " arg-3=3Dval3 arg4", "arg-3", = "val3", " arg4" }, + { "arg2=3D\"value with spaces\" arg3=3Dval3", "arg2", = "value with spaces", " arg3=3Dval3" }, + { " arg2=3D\"value with spaces\" arg3=3Dval3", "arg2", = "value with spaces", " arg3=3Dval3" }, + { " \"arg2=3Dvalue with spaces\" arg3=3Dval3", "arg2", = "value with spaces", " arg3=3Dval3" }, + { "arg2=3D\"val\"ue arg3", "arg2", = "val\"ue", " arg3" }, + { " arg3\" escaped=3Dval2\"", "arg3\" escaped"= , "val2", "" }, + { " arg2longer=3Dsomeval arg2=3Dval2 arg3 ", "arg2longer", = "someval", " arg2=3Dval2 arg3 " }, + { "=3Dval1 arg2=3Dval2", NULL, = NULL, "=3Dval1 arg2=3Dval2" }, + { " ", NULL, = NULL, "" }, + { "", NULL, = NULL, "" }, +}; + +static int +testKernelCmdlineNextParam(const void *data G_GNUC_UNUSED) +{ + char *param =3D NULL; + char *val =3D NULL; + const char *next; + size_t i; + + for (i =3D 0; i < G_N_ELEMENTS(kEntries); ++i) { + VIR_FREE(param); + VIR_FREE(val); + + next =3D virKernelCmdlineNextParam(kEntries[i].cmdline, ¶m, &v= al); + + if (STRNEQ_NULLABLE(param, kEntries[i].param) || + STRNEQ_NULLABLE(val, kEntries[i].val) || + STRNEQ(next, kEntries[i].next)) { + VIR_TEST_DEBUG("\nKernel cmdline [%s]", kEntries[i].cmdline); + VIR_TEST_DEBUG("Expect param [%s]", kEntries[i].param); + VIR_TEST_DEBUG("Actual param [%s]", param); + VIR_TEST_DEBUG("Expect value [%s]", kEntries[i].val); + VIR_TEST_DEBUG("Actual value [%s]", val); + VIR_TEST_DEBUG("Expect next [%s]", kEntries[i].next); + VIR_TEST_DEBUG("Actual next [%s]", next); + + VIR_FREE(param); + VIR_FREE(val); + + return -1; + } + } + + VIR_FREE(param); + VIR_FREE(val); + + return 0; +} + + +struct testKernelCmdlineMatchData +{ + const char *cmdline; + const char *arg; + const char *values[2]; + virKernelCmdlineFlags flags; + bool result; +}; + +static struct testKernelCmdlineMatchData kMatchEntries[] =3D { + {"arg1 myarg=3Dno arg2=3Dval2 myarg=3Dyes arg4=3Dval4 myarg=3Dno arg5"= , "myarg", {"1", "y"}, VIR_KERNEL_CMDLINE_FLAGS_SEARCH_STICKY | VIR_KER= NEL_CMDLINE_FLAGS_CMP_EQ, false }, + {"arg1 myarg=3Dno arg2=3Dval2 myarg=3Dyes arg4=3Dval4 myarg=3Dno arg5"= , "myarg", {"on", "yes"}, VIR_KERNEL_CMDLINE_FLAGS_SEARCH_STICKY | VIR_KER= NEL_CMDLINE_FLAGS_CMP_EQ, true }, + {"arg1 myarg=3Dno arg2=3Dval2 myarg=3Dyes arg4=3Dval4 myarg=3Dno arg5"= , "myarg", {"1", "y"}, VIR_KERNEL_CMDLINE_FLAGS_SEARCH_STICKY | VIR_KER= NEL_CMDLINE_FLAGS_CMP_PREFIX, true }, + {"arg1 myarg=3Dno arg2=3Dval2 myarg=3Dyes arg4=3Dval4 myarg=3Dno arg5"= , "myarg", {"a", "b"}, VIR_KERNEL_CMDLINE_FLAGS_SEARCH_STICKY | VIR_KER= NEL_CMDLINE_FLAGS_CMP_PREFIX, false }, + {"arg1 myarg=3Dno arg2=3Dval2 myarg=3Dyes arg4=3Dval4 myarg=3Dno arg5"= , "myarg", {"on", "yes"}, VIR_KERNEL_CMDLINE_FLAGS_SEARCH_LAST | VIR_KERNE= L_CMDLINE_FLAGS_CMP_EQ, false}, + {"arg1 myarg=3Dno arg2=3Dval2 myarg=3Dyes arg4=3Dval4 myarg=3Dno arg5"= , "myarg", {"1", "y"}, VIR_KERNEL_CMDLINE_FLAGS_SEARCH_LAST | VIR_KERNE= L_CMDLINE_FLAGS_CMP_PREFIX, false}, + {"arg1 myarg=3Dno arg2=3Dval2 arg4=3Dval4 myarg=3Dyes arg5", = "myarg", {"on", "yes"}, VIR_KERNEL_CMDLINE_FLAGS_SEARCH_LAST | VIR_KERNEL_= CMDLINE_FLAGS_CMP_EQ, true }, + {"arg1 myarg=3Dno arg2=3Dval2 arg4=3Dval4 myarg=3Dyes arg5", = "myarg", {"1", "y"}, VIR_KERNEL_CMDLINE_FLAGS_SEARCH_LAST | VIR_KERNEL_= CMDLINE_FLAGS_CMP_PREFIX, true }, + {"arg1 myarg=3Dno arg2=3Dval2 arg4=3Dval4 myarg arg5", "m= yarg", {NULL, NULL}, VIR_KERNEL_CMDLINE_FLAGS_SEARCH_LAST, = true }, + {"arg1 myarg arg2=3Dval2 arg4=3Dval4 myarg=3Dyes arg5", "m= yarg", {NULL, NULL}, VIR_KERNEL_CMDLINE_FLAGS_SEARCH_STICKY, = true }, + {"arg1 myarg arg2=3Dval2 arg4=3Dval4 myarg=3Dyes arg5", "m= yarg", {NULL, NULL}, VIR_KERNEL_CMDLINE_FLAGS_SEARCH_LAST, = false }, + {"arg1 my-arg=3Dno arg2=3Dval2 arg4=3Dval4 my_arg=3Dyes arg5", = "my-arg", {"on", "yes"}, VIR_KERNEL_CMDLINE_FLAGS_SEARCH_LAST | VIR_KERNEL_= CMDLINE_FLAGS_CMP_EQ, true }, + {"arg1 my-arg=3Dno arg2=3Dval2 arg4=3Dval4 my_arg=3Dyes arg5 ", = "my-arg", {"on", "yes"}, VIR_KERNEL_CMDLINE_FLAGS_SEARCH_LAST | VIR_KERNEL_= CMDLINE_FLAGS_CMP_EQ, true }, + {"arg1 my-arg arg2=3Dval2 arg4=3Dval4 my_arg=3Dyes arg5", "m= y_arg", {NULL, NULL}, VIR_KERNEL_CMDLINE_FLAGS_SEARCH_STICKY, = true }, + {"arg1 my-arg arg2=3Dval2 arg4=3Dval4 my-arg=3Dyes arg5", "m= y_arg", {NULL, NULL}, VIR_KERNEL_CMDLINE_FLAGS_SEARCH_STICKY, = true }, + {"=3Dval1 my-arg arg2=3Dval2 arg4=3Dval4 my-arg=3Dyes arg5", = "myarg", {NULL, NULL}, VIR_KERNEL_CMDLINE_FLAGS_SEARCH_STICKY, = false }, + {"arg1 arg2=3D", "arg2"= , {"", ""}, VIR_KERNEL_CMDLINE_FLAGS_SEARCH_LAST | VIR_KERNEL_CMDLIN= E_FLAGS_CMP_EQ, true }, + {" ", "myarg",= {NULL, NULL}, VIR_KERNEL_CMDLINE_FLAGS_SEARCH_LAST, = false }, + {"", "", = {NULL, NULL}, VIR_KERNEL_CMDLINE_FLAGS_SEARCH_LAST, = false }, +}; + + +static int +testKernelCmdlineMatchParam(const void *data G_GNUC_UNUSED) +{ + bool result; + size_t i, lenValues; + + for (i =3D 0; i < G_N_ELEMENTS(kMatchEntries); ++i) { + if (kMatchEntries[i].values[0] =3D=3D NULL) + lenValues =3D 0; + else + lenValues =3D G_N_ELEMENTS(kMatchEntries[i].values); + + result =3D virKernelCmdlineMatchParam(kMatchEntries[i].cmdline, + kMatchEntries[i].arg, + kMatchEntries[i].values, + lenValues, + kMatchEntries[i].flags); + + if (result !=3D kMatchEntries[i].result) { + VIR_TEST_DEBUG("\nKernel cmdline [%s]", kMatchEntries[i].cmdli= ne); + VIR_TEST_DEBUG("Kernel argument [%s]", kMatchEntries[i].arg); + VIR_TEST_DEBUG("Kernel values [%s] [%s]", kMatchEntries[i].val= ues[0], + kMatchEntries[i].values[1]); + if (kMatchEntries[i].flags & VIR_KERNEL_CMDLINE_FLAGS_CMP_PREF= IX) + VIR_TEST_DEBUG("Flag [VIR_KERNEL_CMDLINE_FLAGS_CMP_PREFIX]= "); + if (kMatchEntries[i].flags & VIR_KERNEL_CMDLINE_FLAGS_CMP_EQ) + VIR_TEST_DEBUG("Flag [VIR_KERNEL_CMDLINE_FLAGS_CMP_EQ]"); + if (kMatchEntries[i].flags & VIR_KERNEL_CMDLINE_FLAGS_SEARCH_S= TICKY) + VIR_TEST_DEBUG("Flag [VIR_KERNEL_CMDLINE_FLAGS_SEARCH_STIC= KY]"); + if (kMatchEntries[i].flags & VIR_KERNEL_CMDLINE_FLAGS_SEARCH_L= AST) + VIR_TEST_DEBUG("Flag [VIR_KERNEL_CMDLINE_FLAGS_SEARCH_LAST= ]"); + VIR_TEST_DEBUG("Expect result [%d]", kMatchEntries[i].result); + VIR_TEST_DEBUG("Actual result [%d]", result); + + return -1; + } + } + + return 0; +} =20 =20 static int @@ -277,6 +416,8 @@ mymain(void) DO_TEST(ParseVersionString); DO_TEST(RoundValueToPowerOfTwo); DO_TEST(OverflowCheckMacro); + DO_TEST(KernelCmdlineNextParam); + DO_TEST(KernelCmdlineMatchParam); =20 return result =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } --=20 2.25.4 From nobody Sun May 5 16:06:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1590747111; cv=none; d=zohomail.com; s=zohoarc; b=Zs8yRJP5W4gXDr0ypmK/cUdqaCpT9MnqUybGFFK9xF6feTN+2tsk1kklq3/z9mHC09ijFhIHHjn5T8hFsBbGBD38YYMPwXNqU2RfV3n64VdM7Ry6qUr2yAyfS1TVWjfm4SVwzUuwqAvmZKpo7rUFO/zW2I+wbokhymM01QP7JJ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590747111; 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=eEYH9vXg11eZEVH9dbZ2ZkuUcNPtBNRhvWFuQBIlIPg=; b=m5YGU1MpX2/Mb58cgziyVZOjL4quC3pggLrtR5IYbGodXrqpVLpWlVf5hYi8hfcQ13MXHrZvQdD8wt3fFQBWdIsCQ2aBnsd5p3pm7AvGixqIt1JmAfvQlq3ILzY0ZLn17H2VqxyykfkCx649z2SH9AQG5gG5D/fMtogbAB2snJo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 15907471119451014.841209749453; Fri, 29 May 2020 03:11:51 -0700 (PDT) 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-27-M27zAPSwNdGLPz0J5iibUw-1; Fri, 29 May 2020 06:11:48 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BF87F460; Fri, 29 May 2020 10:11:41 +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 5E9FC5C1B0; Fri, 29 May 2020 10:11:40 +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 16EB01809543; Fri, 29 May 2020 10:11:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04TAAOsP030441 for ; Fri, 29 May 2020 06:10:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 97BE72156A4D; Fri, 29 May 2020 10:10:24 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8729C2156A49 for ; Fri, 29 May 2020 10:10:24 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 B81768007A4 for ; Fri, 29 May 2020 10:10:22 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-466-nNhtcC_ZNqiRTX6NZ88gHA-1; Fri, 29 May 2020 06:10:18 -0400 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 04TA2Zao006963; Fri, 29 May 2020 06:10:17 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 31aucagusp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 29 May 2020 06:10:16 -0400 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 04TA3ARc009774; Fri, 29 May 2020 06:10:16 -0400 Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 31aucagurr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 29 May 2020 06:10:16 -0400 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 04TA6m5V020136; Fri, 29 May 2020 10:10:14 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma03fra.de.ibm.com with ESMTP id 316uf84qxq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 29 May 2020 10:10:14 +0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 04TAABjA9109792 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 29 May 2020 10:10:11 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 42BB84204B; Fri, 29 May 2020 10:10:11 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C2A9742057; Fri, 29 May 2020 10:10:10 +0000 (GMT) Received: from normandy.boeblingen.de.ibm.com (unknown [9.145.145.249]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 29 May 2020 10:10:10 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590747110; 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=eEYH9vXg11eZEVH9dbZ2ZkuUcNPtBNRhvWFuQBIlIPg=; b=YpqRqzJko17SIVPFdiF9Y50gFxfGPgi6oukHBh3I8z5/kz4dLmdXrgMGkPxJlBAvRvtICp IO0lVqb/A5bsG9A9ydZIerR0t+rSmNHcMV9QS9VDmApdjTaNhtwKWkI7HFldANHksETNUc I7cp82iY8s12ksr9FBaB8ldsFg8syAM= X-MC-Unique: M27zAPSwNdGLPz0J5iibUw-1 X-MC-Unique: nNhtcC_ZNqiRTX6NZ88gHA-1 From: Paulo de Rezende Pinatti To: libvir-list@redhat.com, fiuczy@linux.ibm.com, mihajlov@linux.ibm.com, berrange@redhat.com, brijesh.singh@amd.com, borntraeger@de.ibm.com, eskultet@redhat.com Subject: [PATCH v2 2/7] qemu: check if s390 secure guest support is enabled Date: Fri, 29 May 2020 12:10:04 +0200 Message-Id: <20200529101009.130358-3-ppinatti@linux.ibm.com> In-Reply-To: <20200529101009.130358-1-ppinatti@linux.ibm.com> References: <20200529101009.130358-1-ppinatti@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216, 18.0.687 definitions=2020-05-29_02:2020-05-28, 2020-05-29 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 phishscore=0 malwarescore=0 spamscore=0 impostorscore=0 mlxscore=0 mlxlogscore=999 priorityscore=1501 lowpriorityscore=0 suspectscore=2 clxscore=1015 cotscore=-2147483648 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005290075 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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.16 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 patch introduces a common function to verify if the availability of the so-called Secure Guest feature on the host has changed in order to invalidate the qemu capabilities cache. It can be used as an entry point for verification on different architectures. For s390 the verification consists of: - checking if /sys/firmware/uv is available: meaning the HW facility is available and the host OS supports it; - checking if the kernel cmdline contains 'prot_virt=3D1': meaning the host OS wants to use the feature. Whenever the availability of the feature does not match the secure guest flag in the cache then libvirt will re-build it in order to pick up the new set of capabilities available. Signed-off-by: Paulo de Rezende Pinatti Signed-off-by: Boris Fiuczynski Tested-by: Viktor Mihajlovski Reviewed-by: Bjoern Walk --- src/qemu/qemu_capabilities.c | 56 ++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index f12769635a..cbc577353b 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -23,6 +23,7 @@ =20 #include "qemu_capabilities.h" #include "viralloc.h" +#include "virarch.h" #include "vircrypto.h" #include "virlog.h" #include "virerror.h" @@ -657,6 +658,7 @@ struct _virQEMUCaps { virObject parent; =20 bool kvmSupportsNesting; + bool kvmSupportsSecureGuest; =20 char *binary; time_t ctime; @@ -1901,6 +1903,7 @@ virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemu= Caps) =20 ret->invalidation =3D qemuCaps->invalidation; ret->kvmSupportsNesting =3D qemuCaps->kvmSupportsNesting; + ret->kvmSupportsSecureGuest =3D qemuCaps->kvmSupportsSecureGuest; =20 ret->ctime =3D qemuCaps->ctime; =20 @@ -4396,6 +4399,9 @@ virQEMUCapsLoadCache(virArch hostArch, if (virXPathBoolean("boolean(./kvmSupportsNesting)", ctxt) > 0) qemuCaps->kvmSupportsNesting =3D true; =20 + if (virXPathBoolean("boolean(./kvmSupportsSecureGuest)", ctxt) > 0) + qemuCaps->kvmSupportsSecureGuest =3D true; + ret =3D 0; cleanup: VIR_FREE(str); @@ -4633,6 +4639,9 @@ virQEMUCapsFormatCache(virQEMUCapsPtr qemuCaps) if (qemuCaps->kvmSupportsNesting) virBufferAddLit(&buf, "\n"); =20 + if (qemuCaps->kvmSupportsSecureGuest) + virBufferAddLit(&buf, "\n"); + virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\n"); =20 @@ -4670,6 +4679,44 @@ virQEMUCapsSaveFile(void *data, } =20 =20 +/* + * Check whether IBM Secure Execution (S390) is enabled + */ +static bool +virQEMUCapsKVMSupportsSecureGuestS390(void) +{ + + g_autofree char *cmdline =3D NULL; + static const char *kValues[] =3D {"y", "Y", "on", "ON", "oN", "On", "1= "}; + + if (!virFileIsDir("/sys/firmware/uv")) + return false; + if (virFileReadValueString(&cmdline, "/proc/cmdline") < 0) + return false; + if (virKernelCmdlineMatchParam(cmdline, "prot_virt", kValues, + G_N_ELEMENTS(kValues), + VIR_KERNEL_CMDLINE_FLAGS_SEARCH_STICKY | + VIR_KERNEL_CMDLINE_FLAGS_CMP_PREFIX)) + return true; + return false; +} + + +/* + * Check whether the secure guest functionality is enabled. + * See the specific architecture function for details on the verifications= made. + */ +static bool +virQEMUCapsKVMSupportsSecureGuest(void) +{ + virArch arch =3D virArchFromHost(); + + if (ARCH_IS_S390(arch)) + return virQEMUCapsKVMSupportsSecureGuestS390(); + return false; +} + + /* Check the kernel module parameters 'nested' file to determine if enabled * * Intel: 'kvm_intel' uses 'Y' @@ -4857,6 +4904,13 @@ virQEMUCapsIsValid(void *data, qemuCaps->binary, qemuCaps->kvmSupportsNesting); return false; } + + if (virQEMUCapsKVMSupportsSecureGuest() !=3D qemuCaps->kvmSupports= SecureGuest) { + VIR_DEBUG("Outdated capabilities for '%s': kvm kernel secure g= uest " + "value changed from %d", + qemuCaps->binary, qemuCaps->kvmSupportsSecureGuest); + return false; + } } =20 return true; @@ -5349,6 +5403,8 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch, qemuCaps->kernelVersion =3D g_strdup(kernelVersion); =20 qemuCaps->kvmSupportsNesting =3D virQEMUCapsKVMSupportsNesting(); + + qemuCaps->kvmSupportsSecureGuest =3D virQEMUCapsKVMSupportsSecureG= uest(); } =20 return qemuCaps; --=20 2.25.4 From nobody Sun May 5 16:06:25 2024 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=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1590747211; cv=none; d=zohomail.com; s=zohoarc; b=Qq8Tpc8PxWTTbJSSbqW0otJwPFANbTf5KKrZJZbohz7ygegcqxNvu9TbOwjvB+TxmoYo+4+O92iOW4YL8l0qVJJpppB8cYOtF1Mmjy1fC2ObJCDxrmnCPD4LMO+LwrsOeyLWS/sCzvBUNOT5WrN1RKJP5SOkyPx6xOfvpBf6j54= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590747211; 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=URvbKVLbPUdkmKJ1YDYEaYny1xmy+zrtPJ/u1XaHifA=; b=ieYqETJ2vvX8aIIW9ai4XRhb2cj4LVbKYJnbisjZB7EFQpaxiV3atyp4Yv5nBHk4JhwXpwGlgUk/GfnqNeMxyOlas+dgnYOyR3bbvWMyN5i4ACXsa875yoDQxI3AgeQZf30HAShjus3MAHy2l1LtuBMoPwavuwgGS9OHmD1Fjiw= 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 1590747211292218.17845422850883; Fri, 29 May 2020 03:13:31 -0700 (PDT) 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-66-gijeNkbCPHGYz0KsTLUbvg-1; Fri, 29 May 2020 06:13:24 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8F5C5100CCC1; Fri, 29 May 2020 10:13:19 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7348C768DC; Fri, 29 May 2020 10:13:19 +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 4633B6EF47; Fri, 29 May 2020 10:13:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04TAAPtG030446 for ; Fri, 29 May 2020 06:10:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1892C2028CD3; Fri, 29 May 2020 10:10:25 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 142F420267F2 for ; Fri, 29 May 2020 10:10:23 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.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 D445D1019CA8 for ; Fri, 29 May 2020 10:10:22 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-512-wDzy5JifOsmb4LQhOcos9g-1; Fri, 29 May 2020 06:10:19 -0400 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 04TA2bFr086173; Fri, 29 May 2020 06:10:18 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 31as1cvdqm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 29 May 2020 06:10:18 -0400 Received: from m0098410.ppops.net (m0098410.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 04TA3lCp091080; Fri, 29 May 2020 06:10:17 -0400 Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 31as1cvdpq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 29 May 2020 06:10:17 -0400 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 04TA6AGH010133; Fri, 29 May 2020 10:10:15 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma04ams.nl.ibm.com with ESMTP id 316uf93qgd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 29 May 2020 10:10:15 +0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 04TAACqr51970198 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 29 May 2020 10:10:12 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DCF0F4205C; Fri, 29 May 2020 10:10:11 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6791942045; Fri, 29 May 2020 10:10:11 +0000 (GMT) Received: from normandy.boeblingen.de.ibm.com (unknown [9.145.145.249]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 29 May 2020 10:10:11 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590747207; 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=URvbKVLbPUdkmKJ1YDYEaYny1xmy+zrtPJ/u1XaHifA=; b=aqbfqaRn8g5jZtUL24d+S2qyJB7sLPm70Vb17ei06PAiR0kl8/ancn6q2oe8BpB9zH3yxR FuqS1N8b74O1thh/QUAWnD7VEcYC4u4iPh7J7/JclNnjXT1qIkJgYaeQvEL848WSuKzvPJ 267j8nlsdlWX0DM3NbbPbdbPJq/5/D4= X-MC-Unique: gijeNkbCPHGYz0KsTLUbvg-1 X-MC-Unique: wDzy5JifOsmb4LQhOcos9g-1 From: Paulo de Rezende Pinatti To: libvir-list@redhat.com, fiuczy@linux.ibm.com, mihajlov@linux.ibm.com, berrange@redhat.com, brijesh.singh@amd.com, borntraeger@de.ibm.com, eskultet@redhat.com Subject: [PATCH v2 3/7] qemu: check if AMD secure guest support is enabled Date: Fri, 29 May 2020 12:10:05 +0200 Message-Id: <20200529101009.130358-4-ppinatti@linux.ibm.com> In-Reply-To: <20200529101009.130358-1-ppinatti@linux.ibm.com> References: <20200529101009.130358-1-ppinatti@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216, 18.0.687 definitions=2020-05-29_02:2020-05-28, 2020-05-29 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 spamscore=0 phishscore=0 impostorscore=0 mlxscore=0 adultscore=0 cotscore=-2147483648 lowpriorityscore=0 suspectscore=0 clxscore=1015 priorityscore=1501 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005290075 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 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.15 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" Implement secure guest check for AMD SEV (Secure Encrypted Virtualization) in order to invalidate the qemu capabilities cache in case the availability of the feature changed. For AMD SEV the verification consists of: - checking if /sys/module/kvm_amd/parameters/sev contains the value '1': meaning SEV is enabled in the host kernel; - checking if /dev/sev exists Signed-off-by: Paulo de Rezende Pinatti Signed-off-by: Boris Fiuczynski Reviewed-by: Bjoern Walk Reviewed-by: Erik Skultety --- src/qemu/qemu_capabilities.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index cbc577353b..0d19d4adff 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4702,6 +4702,24 @@ virQEMUCapsKVMSupportsSecureGuestS390(void) } =20 =20 +/* + * Check whether AMD Secure Encrypted Virtualization (x86) is enabled + */ +static bool +virQEMUCapsKVMSupportsSecureGuestAMD(void) +{ + g_autofree char *modValue =3D NULL; + + if (virFileReadValueString(&modValue, "/sys/module/kvm_amd/parameters/= sev") < 0) + return false; + if (modValue[0] !=3D '1') + return false; + if (virFileExists(QEMU_DEV_SEV)) + return true; + return false; +} + + /* * Check whether the secure guest functionality is enabled. * See the specific architecture function for details on the verifications= made. @@ -4713,6 +4731,8 @@ virQEMUCapsKVMSupportsSecureGuest(void) =20 if (ARCH_IS_S390(arch)) return virQEMUCapsKVMSupportsSecureGuestS390(); + if (ARCH_IS_X86(arch)) + return virQEMUCapsKVMSupportsSecureGuestAMD(); return false; } =20 --=20 2.25.4 From nobody Sun May 5 16:06:25 2024 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=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1590747183; cv=none; d=zohomail.com; s=zohoarc; b=e6QhC1TwTLwe5a9tMZ/v+CO+ss+52xWgD9NdDrJtrPJ3DI3Ae6bx6PJNt0T4p/zsnDbVZAT7yEmImuor8DeBz+9m8RmmhxaElqwRQSiy8eLAWek+4k9RnT6I36kal0zGK/QnIHGnZQMMAWHKdChITu1M4jeR4yaG/Kjlbvw84y8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590747183; 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=PDdchllVa1wVF/V+3cUmvdZfETaw31QeSFaJAoaNQJU=; b=g8ugX319MDnEoZFDPPADbZ+V+rKYzHOn4nGeFPbotYXCHXUY1T19ZKdV2JmWnP0bmwwGweLFY9aEYLQpzqCD1v0rq2yzJXHuPg8O2TOKy8YoIshMgGSXLsOaWOsiHHrgxJcI4xmVJBlxDQw1zQHpWtmOaGnmjab9KyN3NqC9ggE= 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 1590747183954409.86571776625044; Fri, 29 May 2020 03:13:03 -0700 (PDT) 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-411-249FYnkaPbW0XuWcNY4vEw-1; Fri, 29 May 2020 06:12:15 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 42FF5420DA; Fri, 29 May 2020 10:12:10 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 226C02B6EA; Fri, 29 May 2020 10:12:10 +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 E83056B5F2; Fri, 29 May 2020 10:12:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04TAAP45030461 for ; Fri, 29 May 2020 06:10:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id BE1CFF1C93; Fri, 29 May 2020 10:10:25 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BA671F1C9A for ; Fri, 29 May 2020 10:10:23 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (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 E8A281859164 for ; Fri, 29 May 2020 10:10:22 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-277-OR5caYYaNqynB8vxUjiXYg-1; Fri, 29 May 2020 06:10:18 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 04T9YHcc036797; Fri, 29 May 2020 06:10:17 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 31as1b3xt6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 29 May 2020 06:10:17 -0400 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 04T9Z0xu039808; Fri, 29 May 2020 06:10:17 -0400 Received: from ppma02fra.de.ibm.com (47.49.7a9f.ip4.static.sl-reverse.com [159.122.73.71]) by mx0a-001b2d01.pphosted.com with ESMTP id 31as1b3xsg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 29 May 2020 06:10:17 -0400 Received: from pps.filterd (ppma02fra.de.ibm.com [127.0.0.1]) by ppma02fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 04TA6HrQ011227; Fri, 29 May 2020 10:10:15 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma02fra.de.ibm.com with ESMTP id 316uf8vsbj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 29 May 2020 10:10:15 +0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 04TAACX962390354 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 29 May 2020 10:10:12 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 861FD4204B; Fri, 29 May 2020 10:10:12 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0972742049; Fri, 29 May 2020 10:10:12 +0000 (GMT) Received: from normandy.boeblingen.de.ibm.com (unknown [9.145.145.249]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 29 May 2020 10:10:11 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590747182; 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=PDdchllVa1wVF/V+3cUmvdZfETaw31QeSFaJAoaNQJU=; b=fjyAMosz6Ve67fwO+q7FN6IncB5LQ9aoXwJ3Mn+XlpnhkGwTQ7/4CiJ9VgNdNVFeVRHF6k 3MwRAske70jhA6ZY3NxGrW7ow+1pXWBYbsG2iu6jFpkIJ3vbkz0w+PrfzV+0ZW5ppaaGks VbtGUJaHTSHrllKLShyI6W/px2lwDrU= X-MC-Unique: 249FYnkaPbW0XuWcNY4vEw-1 X-MC-Unique: OR5caYYaNqynB8vxUjiXYg-1 From: Paulo de Rezende Pinatti To: libvir-list@redhat.com, fiuczy@linux.ibm.com, mihajlov@linux.ibm.com, berrange@redhat.com, brijesh.singh@amd.com, borntraeger@de.ibm.com, eskultet@redhat.com Subject: [PATCH v2 4/7] tools: secure guest check on s390 in virt-host-validate Date: Fri, 29 May 2020 12:10:06 +0200 Message-Id: <20200529101009.130358-5-ppinatti@linux.ibm.com> In-Reply-To: <20200529101009.130358-1-ppinatti@linux.ibm.com> References: <20200529101009.130358-1-ppinatti@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216, 18.0.687 definitions=2020-05-29_02:2020-05-28, 2020-05-29 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 cotscore=-2147483648 adultscore=0 malwarescore=0 clxscore=1015 suspectscore=0 bulkscore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 spamscore=0 impostorscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005290073 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 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.84 on 10.5.11.23 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" From: Boris Fiuczynski Add checking in virt-host-validate for secure guest support on s390 for IBM Secure Execution. Signed-off-by: Boris Fiuczynski Tested-by: Viktor Mihajlovski Reviewed-by: Paulo de Rezende Pinatti Reviewed-by: Bjoern Walk Reviewed-by: Erik Skultety --- tools/virt-host-validate-common.c | 58 +++++++++++++++++++++++++++++-- tools/virt-host-validate-common.h | 4 +++ tools/virt-host-validate-qemu.c | 4 +++ 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/tools/virt-host-validate-common.c b/tools/virt-host-validate-c= ommon.c index fbefbada96..8ead68798f 100644 --- a/tools/virt-host-validate-common.c +++ b/tools/virt-host-validate-common.c @@ -40,7 +40,8 @@ VIR_ENUM_IMPL(virHostValidateCPUFlag, VIR_HOST_VALIDATE_CPU_FLAG_LAST, "vmx", "svm", - "sie"); + "sie", + "158"); =20 static bool quiet; =20 @@ -210,7 +211,8 @@ virBitmapPtr virHostValidateGetCPUFlags(void) * on the architecture, so check possible prefixes */ if (!STRPREFIX(line, "flags") && !STRPREFIX(line, "Features") && - !STRPREFIX(line, "features")) + !STRPREFIX(line, "features") && + !STRPREFIX(line, "facilities")) continue; =20 /* fgets() includes the trailing newline in the output buffer, @@ -439,3 +441,55 @@ bool virHostKernelModuleIsLoaded(const char *module) =20 return ret; } + + +int virHostValidateSecureGuests(const char *hvname, + virHostValidateLevel level) +{ + virBitmapPtr flags; + bool hasFac158 =3D false; + virArch arch =3D virArchFromHost(); + g_autofree char *cmdline =3D NULL; + static const char *kIBMValues[] =3D {"y", "Y", "on", "ON", "oN", "On",= "1"}; + + flags =3D virHostValidateGetCPUFlags(); + + if (flags && virBitmapIsBitSet(flags, VIR_HOST_VALIDATE_CPU_FLAG_FACIL= ITY_158)) + hasFac158 =3D true; + + virBitmapFree(flags); + + virHostMsgCheck(hvname, "%s", _("for secure guest support")); + if (ARCH_IS_S390(arch)) { + if (hasFac158) { + if (!virFileIsDir("/sys/firmware/uv")) { + virHostMsgFail(level, "IBM Secure Execution not supported = by " + "the currently used kernel"); + return 0; + } + if (virFileReadValueString(&cmdline, "/proc/cmdline") < 0) + return -1; + if (virKernelCmdlineMatchParam(cmdline, "prot_virt", kIBMValue= s, + G_N_ELEMENTS(kIBMValues), + VIR_KERNEL_CMDLINE_FLAGS_SEARCH= _STICKY | + VIR_KERNEL_CMDLINE_FLAGS_CMP_PR= EFIX)) { + virHostMsgPass(); + return 1; + } else { + virHostMsgFail(level, + "IBM Secure Execution appears to be disable= d " + "in kernel. Add prot_virt=3D1 to kernel cmd= line " + "arguments"); + } + } else { + virHostMsgFail(level, "Hardware or firmware does not provide " + "support for IBM Secure Execution"); + } + } else { + virHostMsgFail(level, + "Unknown if this platform has Secure Guest support"= ); + return -1; + } + + return 0; +} diff --git a/tools/virt-host-validate-common.h b/tools/virt-host-validate-c= ommon.h index 8ae60a21de..44b5544a12 100644 --- a/tools/virt-host-validate-common.h +++ b/tools/virt-host-validate-common.h @@ -37,6 +37,7 @@ typedef enum { VIR_HOST_VALIDATE_CPU_FLAG_VMX =3D 0, VIR_HOST_VALIDATE_CPU_FLAG_SVM, VIR_HOST_VALIDATE_CPU_FLAG_SIE, + VIR_HOST_VALIDATE_CPU_FLAG_FACILITY_158, =20 VIR_HOST_VALIDATE_CPU_FLAG_LAST, } virHostValidateCPUFlag; @@ -83,4 +84,7 @@ int virHostValidateCGroupControllers(const char *hvname, int virHostValidateIOMMU(const char *hvname, virHostValidateLevel level); =20 +int virHostValidateSecureGuests(const char *hvname, + virHostValidateLevel level); + bool virHostKernelModuleIsLoaded(const char *module); diff --git a/tools/virt-host-validate-qemu.c b/tools/virt-host-validate-qem= u.c index bd717a604e..ea7f172790 100644 --- a/tools/virt-host-validate-qemu.c +++ b/tools/virt-host-validate-qemu.c @@ -127,5 +127,9 @@ int virHostValidateQEMU(void) VIR_HOST_VALIDATE_WARN) < 0) ret =3D -1; =20 + if (virHostValidateSecureGuests("QEMU", + VIR_HOST_VALIDATE_WARN) < 0) + ret =3D -1; + return ret; } --=20 2.25.4 From nobody Sun May 5 16:06:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1590747137; cv=none; d=zohomail.com; s=zohoarc; b=Wss3AU4wuP8SCu5Vt4aFYBxorj130ubSMacD1hD0UfsY2bUhsI5ZSqJP/RRk34eKRapm/rDOanWLqBN9XZ7p3fl8jY8HcIeaqluluBspSl0VZKQd91x0Op4AJ42CvWrja9Y2hAtXm6boRrYDwMUFZUwNDmPYufOSDD1dbHvNE5s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590747137; 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=JlSjapO4SadCOAWYavSe7wLj0851Cy6VcO3wYJy1mKE=; b=bFdYwF6Y+bXfAPHPRZBW/h0ar660b3mNZSjeIOksv9txI2aUYpqYy0UK674XYQelwdZwfiiqiCcj9XuEbOD4J7xPn3Qpvq3rxVL8mvkfrcq4BJuOkhNIWOAUSXe6t2bzP5SYtPbmg7lTapOtZwuOjXsfLGAqnCYNN56diwhOTWc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1590747137158197.9331881201964; Fri, 29 May 2020 03:12:17 -0700 (PDT) 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-305-D51nN1PROIe52HGTZI8kBg-1; Fri, 29 May 2020 06:12:13 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 15022107ACCD; Fri, 29 May 2020 10:12:08 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C18F97A8D4; Fri, 29 May 2020 10:12:07 +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 9302E6B5E7; Fri, 29 May 2020 10:12:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04TAAPSY030460 for ; Fri, 29 May 2020 06:10:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id BE7D2F1C97; Fri, 29 May 2020 10:10:25 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BA829F1C9D for ; Fri, 29 May 2020 10:10:22 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (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 4BF0E1859163 for ; Fri, 29 May 2020 10:10:22 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-101-1jAUe0ELOz2_qekp1cgt7Q-1; Fri, 29 May 2020 06:10:19 -0400 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 04TA24gD066202; Fri, 29 May 2020 06:10:18 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 31as1b40ve-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 29 May 2020 06:10:18 -0400 Received: from m0098419.ppops.net (m0098419.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 04TA32AP069415; Fri, 29 May 2020 06:10:18 -0400 Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0b-001b2d01.pphosted.com with ESMTP id 31as1b40uf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 29 May 2020 06:10:18 -0400 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 04TA6nxU020139; Fri, 29 May 2020 10:10:16 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma03fra.de.ibm.com with ESMTP id 316uf84qxs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 29 May 2020 10:10:16 +0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 04TAADl654198326 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 29 May 2020 10:10:13 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2A1544204B; Fri, 29 May 2020 10:10:13 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9E5DF4203F; Fri, 29 May 2020 10:10:12 +0000 (GMT) Received: from normandy.boeblingen.de.ibm.com (unknown [9.145.145.249]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 29 May 2020 10:10:12 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590747135; 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=JlSjapO4SadCOAWYavSe7wLj0851Cy6VcO3wYJy1mKE=; b=DYXiSloOkDl5wL44JF9l7bUrhzGcqWq9PRWCRTMuOh37SBEsJg68mA1AmW+N1J9kcbH6gM 3T3XwHnoJqEifAJ0wBzXhs+L8wYRTwQkdy6PCGTChZRV7zfxG+eD96FhOToFuarx6erED6 D+85KtXbJkLKAPQxEKi/pBNexi/QlRc= X-MC-Unique: D51nN1PROIe52HGTZI8kBg-1 X-MC-Unique: 1jAUe0ELOz2_qekp1cgt7Q-1 From: Paulo de Rezende Pinatti To: libvir-list@redhat.com, fiuczy@linux.ibm.com, mihajlov@linux.ibm.com, berrange@redhat.com, brijesh.singh@amd.com, borntraeger@de.ibm.com, eskultet@redhat.com Subject: [PATCH v2 5/7] tools: secure guest check for AMD in virt-host-validate Date: Fri, 29 May 2020 12:10:07 +0200 Message-Id: <20200529101009.130358-6-ppinatti@linux.ibm.com> In-Reply-To: <20200529101009.130358-1-ppinatti@linux.ibm.com> References: <20200529101009.130358-1-ppinatti@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216, 18.0.687 definitions=2020-05-29_02:2020-05-28, 2020-05-29 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 phishscore=0 malwarescore=0 clxscore=1015 bulkscore=0 spamscore=0 impostorscore=0 cotscore=-2147483648 mlxlogscore=999 suspectscore=0 mlxscore=0 adultscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005290075 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 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.11 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" From: Boris Fiuczynski Add checking in virt-host-validate for secure guest support on x86 for AMD Secure Encrypted Virtualization. Signed-off-by: Boris Fiuczynski Reviewed-by: Paulo de Rezende Pinatti Reviewed-by: Bjoern Walk Reviewed-by: Erik Skultety --- tools/virt-host-validate-common.c | 29 +++++++++++++++++++++++++++-- tools/virt-host-validate-common.h | 1 + 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/tools/virt-host-validate-common.c b/tools/virt-host-validate-c= ommon.c index 8ead68798f..de007f2c43 100644 --- a/tools/virt-host-validate-common.c +++ b/tools/virt-host-validate-common.c @@ -41,7 +41,8 @@ VIR_ENUM_IMPL(virHostValidateCPUFlag, "vmx", "svm", "sie", - "158"); + "158", + "sev"); =20 static bool quiet; =20 @@ -447,15 +448,18 @@ int virHostValidateSecureGuests(const char *hvname, virHostValidateLevel level) { virBitmapPtr flags; - bool hasFac158 =3D false; + bool hasFac158 =3D false, hasAMDSev =3D false; virArch arch =3D virArchFromHost(); g_autofree char *cmdline =3D NULL; static const char *kIBMValues[] =3D {"y", "Y", "on", "ON", "oN", "On",= "1"}; + g_autofree char *mod_value =3D NULL; =20 flags =3D virHostValidateGetCPUFlags(); =20 if (flags && virBitmapIsBitSet(flags, VIR_HOST_VALIDATE_CPU_FLAG_FACIL= ITY_158)) hasFac158 =3D true; + else if (flags && virBitmapIsBitSet(flags, VIR_HOST_VALIDATE_CPU_FLAG_= SEV)) + hasAMDSev =3D true; =20 virBitmapFree(flags); =20 @@ -485,6 +489,27 @@ int virHostValidateSecureGuests(const char *hvname, virHostMsgFail(level, "Hardware or firmware does not provide " "support for IBM Secure Execution"); } + } else if (hasAMDSev) { + if (virFileReadValueString(&mod_value, "/sys/module/kvm_amd/parame= ters/sev") < 0) { + virHostMsgFail(level, "AMD Secure Encrypted Virtualization not= " + "supported by the currently used kernel"= ); + return 0; + } + if (mod_value[0] !=3D '1') { + virHostMsgFail(level, + "AMD Secure Encrypted Virtualization appears to= be " + "disabled in kernel. Add mem_encrypt=3Don " + "kvm_amd.sev=3D1 to kernel cmdline arguments"); + return 0; + } + if (virFileExists("/dev/sev")) { + virHostMsgPass(); + return 1; + } else { + virHostMsgFail(level, + "AMD Secure Encrypted Virtualization appears to= be " + "disabled in firemare."); + } } else { virHostMsgFail(level, "Unknown if this platform has Secure Guest support"= ); diff --git a/tools/virt-host-validate-common.h b/tools/virt-host-validate-c= ommon.h index 44b5544a12..3df5ea0c7e 100644 --- a/tools/virt-host-validate-common.h +++ b/tools/virt-host-validate-common.h @@ -38,6 +38,7 @@ typedef enum { VIR_HOST_VALIDATE_CPU_FLAG_SVM, VIR_HOST_VALIDATE_CPU_FLAG_SIE, VIR_HOST_VALIDATE_CPU_FLAG_FACILITY_158, + VIR_HOST_VALIDATE_CPU_FLAG_SEV, =20 VIR_HOST_VALIDATE_CPU_FLAG_LAST, } virHostValidateCPUFlag; --=20 2.25.4 From nobody Sun May 5 16:06:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1590747212; cv=none; d=zohomail.com; s=zohoarc; b=OaQZj8yieHDsp6UAR7yj5e1sUhEuPI1POh+VgqdlDshYt3Dmtvoi/tE7yHxKu0UYpRP8qItquMTVRNO1L/TChxZQQWf4xGBWjAJ3Ya2VUlFL07Wm+X970WKkAv66cgzLNFeVxhinNM0A70ViVwcxQ8vwnq0WQxi9kYYs3kYm3VI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590747212; 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=OzqRZbWV2Tu6TNpNJkhXLqNBkcileckvnL7O+Q4pqso=; b=DIUvh1X3gs/UC5zfIfHXTzRi1ikfeF+0Eh3Xf3aznFpIQUycm5R9BqGOqhDtfPgRNdnDe+IsOHw4Oyg61y93RlyiOzp//Ww0+/HxInPUOtOynBXT/07iQRZZ6SJ3OyaO0NhC7IuboJRLYRV9XI/Ia8Mlg9rRGRlZlH3iB1UNZWM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1590747212495310.70339097468195; Fri, 29 May 2020 03:13:32 -0700 (PDT) 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-473-8vh0Ay05OQKqemPoIZ-icw-1; Fri, 29 May 2020 06:13:28 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AF1E418A8227; Fri, 29 May 2020 10:13:23 +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 8C08C2BFF9; Fri, 29 May 2020 10:13:23 +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 7D2C9180954D; Fri, 29 May 2020 10:13:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04TAARLv030473 for ; Fri, 29 May 2020 06:10:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 121AAF1C93; Fri, 29 May 2020 10:10:27 +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 0E243F1C90 for ; Fri, 29 May 2020 10:10:27 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 EA048828824 for ; Fri, 29 May 2020 10:10:26 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-336-Uj57d3r3OdyiTm84IEdr4Q-1; Fri, 29 May 2020 06:10:22 -0400 Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 04TA2thO045724; Fri, 29 May 2020 06:10:19 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 31as16b722-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 29 May 2020 06:10:19 -0400 Received: from m0187473.ppops.net (m0187473.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 04TA34Y1046258; Fri, 29 May 2020 06:10:19 -0400 Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 31as16b716-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 29 May 2020 06:10:18 -0400 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 04TA6BRY010144; Fri, 29 May 2020 10:10:16 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma04ams.nl.ibm.com with ESMTP id 316uf93qgf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 29 May 2020 10:10:16 +0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 04TAADAV40173738 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 29 May 2020 10:10:13 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BD61842056; Fri, 29 May 2020 10:10:13 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 40BC84204F; Fri, 29 May 2020 10:10:13 +0000 (GMT) Received: from normandy.boeblingen.de.ibm.com (unknown [9.145.145.249]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 29 May 2020 10:10:13 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590747211; 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=OzqRZbWV2Tu6TNpNJkhXLqNBkcileckvnL7O+Q4pqso=; b=YgKiPTLD+YypadkfL1UMpGLN/RmtfewFQiDDfHocLJqUKAxDRtXDIbtgLFINcykd0zj6eT LvBxNcj2k6wl5hgWMknzV+WDubors4FcBV2zEr3jCzlD1WkmXsuZ2JaLwuTsTLUraG9Fsm uY/Et/eBYbCOuWYDvo8+RUy+9AfzJ+c= X-MC-Unique: 8vh0Ay05OQKqemPoIZ-icw-1 X-MC-Unique: Uj57d3r3OdyiTm84IEdr4Q-1 From: Paulo de Rezende Pinatti To: libvir-list@redhat.com, fiuczy@linux.ibm.com, mihajlov@linux.ibm.com, berrange@redhat.com, brijesh.singh@amd.com, borntraeger@de.ibm.com, eskultet@redhat.com Subject: [PATCH v2 6/7] docs: update AMD launch secure description Date: Fri, 29 May 2020 12:10:08 +0200 Message-Id: <20200529101009.130358-7-ppinatti@linux.ibm.com> In-Reply-To: <20200529101009.130358-1-ppinatti@linux.ibm.com> References: <20200529101009.130358-1-ppinatti@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216, 18.0.687 definitions=2020-05-29_02:2020-05-28, 2020-05-29 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 bulkscore=0 mlxlogscore=999 cotscore=-2147483648 malwarescore=0 spamscore=0 phishscore=0 priorityscore=1501 clxscore=1015 adultscore=0 suspectscore=0 mlxscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005290080 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 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.11 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" From: Boris Fiuczynski Update document with changes in qemu capability caching and the added secure guest support checking for AMD SEV in virt-host-validate. Signed-off-by: Boris Fiuczynski Reviewed-by: Erik Skultety --- docs/kbase/launch_security_sev.rst | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/kbase/launch_security_sev.rst b/docs/kbase/launch_securit= y_sev.rst index 65f258587d..19b978481a 100644 --- a/docs/kbase/launch_security_sev.rst +++ b/docs/kbase/launch_security_sev.rst @@ -30,8 +30,11 @@ Enabling SEV on the host =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 Before VMs can make use of the SEV feature you need to make sure your -AMD CPU does support SEV. You can check whether SEV is among the CPU -flags with: +AMD CPU does support SEV. You can run ``libvirt-host-validate`` +(libvirt >=3D 6.5.0) to check if your host supports secure guests or you +can follow the manual checks below. + +You can manually check whether SEV is among the CPU flags with: =20 :: =20 @@ -109,7 +112,7 @@ following: =20 -Note that if libvirt was already installed and libvirtd running before +Note that if libvirt (<6.5.0) was already installed and libvirtd running b= efore enabling SEV in the kernel followed by the host reboot you need to force libvirtd to re-probe both the host and QEMU capabilities. First stop libvirtd: --=20 2.25.4 From nobody Sun May 5 16:06:25 2024 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=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1590747143; cv=none; d=zohomail.com; s=zohoarc; b=FVooQH9LNcd2mxCQgGtpzw5Wm0CTBv38AmhWZtOZub0m7yrT+RiA7pKYZSHPJAfLaxgDCnN41Im9YVRIhb8ZYxl6JwaHdtV85qJNr2JV34XdMaEgdSpJ4kgfpQR/6IkcORhqQZKLn5loAg4ovEbWXFncjrO5k83yH17XGKjy3v0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590747143; 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=Hhrq9dwh1nm+IAihu45+M0LUCJC0/OSF7ayoIfdaOqA=; b=EIFPrUAIV+7SLwcpWTdK1s8L0VshYP89hHVrhjnl8fgXocuBHt6yCsqrxTv+ZxDItafiFoomtbyGbLdDP5XqfOQk5LNeRQnfXufVkUdwIK6uTRTjrWFNMfGJ+FNLDQKK0EbKb5Ovdp6L6lsja+xaUQfBix+GlnZfVINBBQTIGIc= 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 1590747143857132.38476650961286; Fri, 29 May 2020 03:12:23 -0700 (PDT) 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-148-duun0BUWMjy5cri-COjiEg-1; Fri, 29 May 2020 06:12:19 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4141E18A0761; Fri, 29 May 2020 10:12:14 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1F9CE6298C; Fri, 29 May 2020 10:12:14 +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 E53356B5F2; Fri, 29 May 2020 10:12:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04TAASS9030481 for ; Fri, 29 May 2020 06:10:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 969552166BA4; Fri, 29 May 2020 10:10:28 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 893712166BA0 for ; Fri, 29 May 2020 10:10:28 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (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 6170E101A526 for ; Fri, 29 May 2020 10:10:28 +0000 (UTC) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-151-VyVYQlVXMjCq0PPzzpM5zA-1; Fri, 29 May 2020 06:10:20 -0400 Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 04TA3CKm103861; Fri, 29 May 2020 06:10:20 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 31as1au08m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 29 May 2020 06:10:19 -0400 Received: from m0127361.ppops.net (m0127361.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 04TA3NSC104527; Fri, 29 May 2020 06:10:19 -0400 Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 31as1au07x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 29 May 2020 06:10:19 -0400 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 04TA6m5W020136; Fri, 29 May 2020 10:10:17 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma03fra.de.ibm.com with ESMTP id 316uf84qxt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 29 May 2020 10:10:17 +0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 04TAAEJw17891632 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 29 May 2020 10:10:14 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 63E2E42057; Fri, 29 May 2020 10:10:14 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D59574204F; Fri, 29 May 2020 10:10:13 +0000 (GMT) Received: from normandy.boeblingen.de.ibm.com (unknown [9.145.145.249]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 29 May 2020 10:10:13 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590747142; 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=Hhrq9dwh1nm+IAihu45+M0LUCJC0/OSF7ayoIfdaOqA=; b=W8xMQNRZ05y0/5GR0gnvW2gOreGkwW2i3hCnbIEPHgqkelcohFQtZmH4dTTFDof1UYSSDA OIrEp76uwgTD7Je37NjTcs1v/+2S9/LhRZRuaJOEvN3mSgCZbwX3BYVJ3GaZlr2DVMv0q5 jTHdlpIZSpefZ9C7i4BmLoCttzdhr1s= X-MC-Unique: duun0BUWMjy5cri-COjiEg-1 X-MC-Unique: VyVYQlVXMjCq0PPzzpM5zA-1 From: Paulo de Rezende Pinatti To: libvir-list@redhat.com, fiuczy@linux.ibm.com, mihajlov@linux.ibm.com, berrange@redhat.com, brijesh.singh@amd.com, borntraeger@de.ibm.com, eskultet@redhat.com Subject: [PATCH v2 7/7] docs: Describe protected virtualization guest setup Date: Fri, 29 May 2020 12:10:09 +0200 Message-Id: <20200529101009.130358-8-ppinatti@linux.ibm.com> In-Reply-To: <20200529101009.130358-1-ppinatti@linux.ibm.com> References: <20200529101009.130358-1-ppinatti@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216, 18.0.687 definitions=2020-05-29_02:2020-05-28, 2020-05-29 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 priorityscore=1501 spamscore=0 mlxscore=0 suspectscore=0 malwarescore=0 lowpriorityscore=0 bulkscore=0 adultscore=0 phishscore=0 clxscore=1015 impostorscore=0 cotscore=-2147483648 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005290080 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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.15 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" From: Viktor Mihajlovski Protected virtualization/IBM Secure Execution for Linux protects guest memory and state from the host. Add some basic information about technology and a brief guide on setting up secure guests with libvirt. Signed-off-by: Viktor Mihajlovski Signed-off-by: Boris Fiuczynski Reviewed-by: Paulo de Rezende Pinatti Reviewed-by: Erik Skultety --- docs/kbase.html.in | 3 + docs/kbase/s390_protected_virt.rst | 189 +++++++++++++++++++++++++++++ 2 files changed, 192 insertions(+) create mode 100644 docs/kbase/s390_protected_virt.rst diff --git a/docs/kbase.html.in b/docs/kbase.html.in index c586e0f676..241a212fa9 100644 --- a/docs/kbase.html.in +++ b/docs/kbase.html.in @@ -14,6 +14,9 @@
Secure usage
Secure usage of the libvirt APIs
=20 +
Protected virtualiz= ation on s390
+
Running secure s390 guests with IBM Secure Execution
+
Launch security=
Securely launching VMs with AMD SEV
=20 diff --git a/docs/kbase/s390_protected_virt.rst b/docs/kbase/s390_protected= _virt.rst new file mode 100644 index 0000000000..f38d16d743 --- /dev/null +++ b/docs/kbase/s390_protected_virt.rst @@ -0,0 +1,189 @@ +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D +Protected Virtualization on s390 +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D + +.. contents:: + +Overview +=3D=3D=3D=3D=3D=3D=3D=3D + +Protected virtualization, also known as IBM Secure Execution is a +hardware-based privacy protection technology for s390x (IBM Z). +It allows to execute virtual machines such that the host system +has no access to a VM's state and memory contents. + +Unlike other similar technologies, the memory of a running guest +is not encrypted but protected by hardware access controls, which +may only be manipulated by trusted system firmware, called +ultravisor. + +For the cases where the host needs access to guest memory (e.g. for +paging), it can request pages to be exported to it. The exported page +will be encrypted with a unique key for the running guest by the +ultravisor. The ultravisor also computes an integrity value for +the page, and stores it in a special table, together with the page +index and a counter. This way it can verify the integrity of +the page content upon re-import into the guest. + +In other cases it may be necessary for a guest to grant the host access +to dedicated memory regions (e.g. for I/O). The guest can request +that the ultravisor removes the memory protection from individual +pages, so that they can be shared with the host. Likewise, the +guest can undo the sharing. + +A secure guest will initially start in a regular non-protected VM. +The start-up is controlled by a small bootstrap program loaded +into memory together with encrypted operating system components and +a control structure (the PV header). +The operating system components (e.g. Linux kernel, initial RAM +file system, kernel parameters) are encrypted and integrity +protected. The component encryption keys and integrity values are +stored in the PV header. +The PV header is wrapped with a public key belonging to a specific +system (in fact it can be wrapped with multiple such keys). The +matching private key is only accessible by trusted hardware and +firmware in that specific system. +Consequently, such a secure guest boot image can only be run on the +systems it has been prepared for. Its contents can't be decrypted +without access to the private key and it can't be modified as +it is integrity protected. + +Host Requirements +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +IBM Secure Execution for Linux has some hardware and firmware +requirements. The system hardware must be an IBM z15 (or newer), +or an IBM LinuxONE III (or newer). + +It is also necessary that the IBM Secure Execution feature is +enabled for that system. With libvirt >=3D 6.5.0 you can run +``libvirt-host--validate`` or otherwise check for facility '158', e.g. + +:: + + $ grep facilities /proc/cpuinfo | grep 158 + +The kernel must include the protected virtualization support +which can be verified by checking for the presence of directory +``/sys/firmware/uv``. It will only be present when both the +hardware and the kernel support are available. + +Finally, the host operating system must donate some memory to +the ultravisor needed to store memory security information. +This is achieved by specifying the following kernel command +line parameter to the host boot configuration + +:: + + prot_virt=3D1 + + +Guest Requirements +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Guest Boot +---------- + +To start a guest in protected virtualization secure mode, the +boot image must have been prepared first with the program +``genprotimg`` using the correct public key for this host. +``genprotimg`` is part of the package ``s390-tools``, or +``s390-utils``, depending on the Linux distribution being used. +It can also be found at +``_ + +The guests have to be configured to use the host CPU model, which +must contain the ``unpack`` facility indicating ultravisor guest support. + +With the following command it's possible to check whether the host +CPU model satisfies the requirement + +:: + + $ virsh domcapabilities | grep unpack + +which should return + +:: + + + +Note that on hosts with libvirt < 6.5.0 if the check fails despite +the host system actually supporting protected virtualization guests, +this can be caused by a stale libvirt capabilities cache. +To recover, run the following commands + +:: + + $ systemctl stop libvirtd + $ rm /var/cache/libvirt/qemu/capabilities/*.xml + $ systemctl start libvirtd + + +Guest I/O +--------- + +Protected virtualization guests support I/O using virtio devices. +As the virtio data structures of secure guests are not accessible +by the host, it is necessary to use shared memory ('bounce buffers'). + +To enable virtio devices to use shared buffers, it is necessary +to configure them with platform_iommu enabled. This can done by adding +``iommu=3D'on'`` to the driver element of a virtio device definition in the +guest's XML, e.g. + +:: + + + + + + + +It is mandatory to define all virtio bus devices in this way to +prevent the host from attempting to access protected memory. +Ballooning will not work and is fenced by QEMU. It should be +disabled by specifying + +:: + + + +Finally, the guest Linux must be instructed to allocate I/O +buffers using memory shared between host and guest using SWIOTLB. +This is done by adding ``swiotlb=3Dnnn`` to the guest's kernel command +line string, where ``nnn`` stands for the number of statically +allocated 2K entries. A commonly used value for swiotlb is 262144. + +Example guest definition +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Minimal domain XML for a protected virtualization guest, essentially +it's mostly about the ``iommu`` property + +:: + + + protected + 2048000 + 2048000 + 1 + + hvm + + + + + + + + + + + + + + + + + --=20 2.25.4