From patchwork Fri Jan 27 11:39:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49274 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp787269wrn; Fri, 27 Jan 2023 03:43:54 -0800 (PST) X-Google-Smtp-Source: AK7set9u69bBJQ1nA7tCa7GByhTjSwF419YGZRfleuGRCEg3nwx12AE04mRLJSBceEcy89IEAkex X-Received: by 2002:a17:90b:4c52:b0:22c:46a1:67ca with SMTP id np18-20020a17090b4c5200b0022c46a167camr2651078pjb.37.1674819834175; Fri, 27 Jan 2023 03:43:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674819834; cv=none; d=google.com; s=arc-20160816; b=TDR5FF5zZnka70XksWlRjWTILkk0DsdTqlCvsT+WpdBz2j2H/wX9W4Jxh0muLEbBE6 8UyX5X9/gjbl0hLMYk0B8x2/6lcHQ/7yRv5gnDlEVHdL4qagg9pdf9ZLtZ2oUphOMoOb SltP6J/UV7i0sn5XiTtpCukyNOSo/1IIy2uPJ+glyilEOZwWCDnokZus4G8TlQBDwoVv nErHaXjIGd1xA7plW4GpE4R5ukF+0vqaogsUA1IqtL42xNH39fOLpgzX2ejcQTPUHNNt q7egLhlhAzegORBQh2c+BfiL5m9B7Z42/Vh6Kyu9/ICm/GXlUkKcESoCc3QXYTf9qgKv xxbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Ia8hhE7WXst822ROUVg6x4qIQ7YANAOPdASZThWEqx0=; b=h6/QR8VncPpwMRuZQTCYo/jlr6TMaeCvNNeEN6BwVXmVLBBsVgvJllftKANxc6oBx9 Udz441o1OhJfDqsBIFXXcq8LjNu16EN0sNBTJKqICyflYcCWPKXRT3x5ijpY+k0ysxLd UE+GopcroPGc2dT/4lBrrGdFFRfXUVghTCJI7dunl07ql1LenlB6t41Mel75Z2H88KbE f3OijKxx89IUFM9eyuAZYyM1jreTgMTtEupqPpkY9vxUfNgY2vNIpICH+5QRdqx+Sbbx jdWfXdmIyXg7vkGB+FVKYsojOEvitWRgq3Kni4/YNEfYS+mXh7I29GIxR73kZU2F8LqP saZw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c191-20020a6335c8000000b004de69e905d1si3989175pga.570.2023.01.27.03.43.41; Fri, 27 Jan 2023 03:43:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233766AbjA0Lkq (ORCPT + 99 others); Fri, 27 Jan 2023 06:40:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234143AbjA0Lkf (ORCPT ); Fri, 27 Jan 2023 06:40:35 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4C14D70D54; Fri, 27 Jan 2023 03:40:15 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A44601576; Fri, 27 Jan 2023 03:40:33 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1E5433F64C; Fri, 27 Jan 2023 03:39:49 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 01/31] arm64: Disable MTE when CFI flash is emulated Date: Fri, 27 Jan 2023 11:39:02 +0000 Message-Id: <20230127113932.166089-2-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756175882377361999?= X-GMAIL-MSGID: =?utf-8?q?1756175882377361999?= CFI Flash file image cannot be mapped into the memory of the guest if MTE is enabled. Thus disable MTE if flash emulation is requested. Signed-off-by: Suzuki K Poulose --- arm/aarch64/kvm.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c index 54200c9e..5a53badb 100644 --- a/arm/aarch64/kvm.c +++ b/arm/aarch64/kvm.c @@ -145,6 +145,12 @@ void kvm__arch_enable_mte(struct kvm *kvm) return; } + if (kvm->cfg.flash_filename) { + kvm->cfg.arch.mte_disabled = true; + pr_info("MTE is incompatible with CFI flash support, disabling"); + return; + } + if (kvm->cfg.arch.mte_disabled) { pr_debug("MTE disabled by user"); return; From patchwork Fri Jan 27 11:39:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49286 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp787628wrn; Fri, 27 Jan 2023 03:45:01 -0800 (PST) X-Google-Smtp-Source: AMrXdXvLUOfJbRgC49yj6sGjBXXUNcGm+ALV86+riJkaScjntRSX3agqcc5pcKhHKN94apHvmAJD X-Received: by 2002:a17:902:7c0c:b0:193:b58:2b0c with SMTP id x12-20020a1709027c0c00b001930b582b0cmr38192359pll.23.1674819900716; Fri, 27 Jan 2023 03:45:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674819900; cv=none; d=google.com; s=arc-20160816; b=iwP1DLaG+auLYKQF3ZWY0g0AbSWerYuZiWpTqI4EZyzYTepT+OOJ54y/0I42yc7vsT 8dQAWE+tD8A30+L4fqyrXUUkrtVg2FO3IOuiRklYRU5Dip1VpEm5bgDGY0rIgD9CFwUY NhMtmqhDU0UhRIfe4hlnpw/yE1JmSTiizoaHV99MJ1nrXrSGv1jd4l1OSjFz3NeqMsdY O0K63ccLlojb1HynGrPsaKaP7AUr3HrQt4V5ah6biJPAam/h7Q6O8t7ydyuK3zgniPs3 WHQ52gvYwEMVf48uY7fXSWcVOYfH/HYsrJKjpv0MjFZBXkwuEV/WufHDFOdE8sjgP02S Vnqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=tNKPqb35Zitonxahtf2aMrPunLzAn5+7c9Rlg249+ZU=; b=cmk71Vo8Ky2aJYrC+lR7By0eq3Ft9SVstrfXvWTlZ6DrEWSBbc94xvxWXBLfX/Pffx yCjM0ufnb5lhN0vslDhDmb2/A/mgpWp9Ge6u59+XccLcjuk6eC5FP0ptW2sa1IRDPl+X ypf3+xEf0l2wu99fSW4j6/NFfHjCtZ80KI7WCfaxeImogN49tfAi50AAaqAmrKOWXVVs 6wyATJlhWa40C3SM/EF+3O2+F7xPld4lmL1OP9rfwoEMbCkJGYfIm4HaTcnnpAlb5ZJT hmsa03W8FhCI5hYeouBWsi2NChgcwJAg2s2jq9hboFiTiOpSP7IAMfAxxIEi00ulswjb IEhA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h8-20020a170902f54800b00189847745f1si4885609plf.395.2023.01.27.03.44.47; Fri, 27 Jan 2023 03:45:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232334AbjA0Lks (ORCPT + 99 others); Fri, 27 Jan 2023 06:40:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234168AbjA0Lkg (ORCPT ); Fri, 27 Jan 2023 06:40:36 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 648F2C650; Fri, 27 Jan 2023 03:40:18 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 86EAB15BF; Fri, 27 Jan 2023 03:40:36 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id F3FB23F64C; Fri, 27 Jan 2023 03:39:51 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 02/31] script: update_headers: Ignore missing architectures Date: Fri, 27 Jan 2023 11:39:03 +0000 Message-Id: <20230127113932.166089-3-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756175952036857707?= X-GMAIL-MSGID: =?utf-8?q?1756175952036857707?= Ignore missing architectures for header updates, for use with older kernels. Signed-off-by: Suzuki K Poulose --- util/update_headers.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/util/update_headers.sh b/util/update_headers.sh index 789e2a42..bdfb798c 100755 --- a/util/update_headers.sh +++ b/util/update_headers.sh @@ -48,6 +48,7 @@ copy_optional_arch () { for arch in arm64 mips powerpc riscv x86 do + [ -f $LINUX_ROOT/arch/${arch} ] || continue; case "$arch" in arm64) KVMTOOL_PATH=arm/aarch64 copy_optional_arch asm/sve_context.h ;; From patchwork Fri Jan 27 11:39:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49287 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp787645wrn; Fri, 27 Jan 2023 03:45:02 -0800 (PST) X-Google-Smtp-Source: AMrXdXv5t6ReUIOCaIlY7M8NRKPtm3F8iGriSLCB2hV2DKoNhzm2B27k916SsV/lESz/53xcFUYw X-Received: by 2002:a05:6a20:c6c9:b0:b8:8a19:d6ad with SMTP id gw9-20020a056a20c6c900b000b88a19d6admr37534427pzb.24.1674819902581; Fri, 27 Jan 2023 03:45:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674819902; cv=none; d=google.com; s=arc-20160816; b=bNpMXSserEF8S4Vf1u+3uP7Lk93OnX7+z5BFfHevZvuvN8bFrUmXHkZMRycS44X7cu lxUEEx3Teaau6vuhTzrRvyVLXJhIqkXqNvZoDfaRNvdAyuLqB7WLlAwyBijXtcM8CfVW /gZttlCErK7/s/djDPKjqXc6GMAkhYA8ptbI+VYgTA43H1vclEx9IiZGKad90+XUfTST M1S9J0wXv8Qvq2wJiZL9DE0/sh5HHvOrMJIPCc1FdGcO0z4a/9TWZM9RXLdFkOwK90JI HpDTPEAwLZNkxrlnovTB1GspJR5Bl7OdM2KCYbctzhUkkbjoJBBCeUlrOE//+FdXYiQ2 hNDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=45tJhW8LK9kOcuv5g0pkTmwLQYYbK8Y9dFRZ1ypH7SI=; b=ghAQwihbyaA+dBddBkQ4S6r20POADnLdXhCqnrugBjMv6EEB30+qO9RyXJF3/Q7h/C QspUNM/61EUIP338/aKXgaO982zC8ELlT6dtfBN4urgPT2THIGYYXUM7My101BeSKD6L KFlGfcA/HEfEmJf+FMDiGwTUg587O126DpIfG2Getzpecck+da4ZdxJ7SqgKEye+2CoR xz4miHjQwrJRDqkJ6+0VRygqVC7ikAHaE9BKQ3zCkZ0agglur0c/bxM65WctaT1Z3x4K p8F4LPZFMiG3JtTh34Tp12oW7nauIxw96SSaqedodeimQo0kI4pFHYRq9av7T5HDa9Mp zDZg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i4-20020a639d04000000b004a26c35feeesi4089572pgd.859.2023.01.27.03.44.49; Fri, 27 Jan 2023 03:45:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233838AbjA0Lky (ORCPT + 99 others); Fri, 27 Jan 2023 06:40:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234195AbjA0Lki (ORCPT ); Fri, 27 Jan 2023 06:40:38 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 80CC710F4; Fri, 27 Jan 2023 03:40:20 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 68AA515DB; Fri, 27 Jan 2023 03:40:39 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D6A303F64C; Fri, 27 Jan 2023 03:39:54 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 03/31] hw: cfi flash: Handle errors in memory transitions Date: Fri, 27 Jan 2023 11:39:04 +0000 Message-Id: <20230127113932.166089-4-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756175954460918007?= X-GMAIL-MSGID: =?utf-8?q?1756175954460918007?= Handle failures in creating the memory maps and back in transitioning the CFI flash. e.g., with MTE enabled, CFI flash emulation breaks with the map operation, silently. And we later hit unhandled aborts in the guest. To avoid such issues, let us make sure we catch the error and handle it right at source. Signed-off-by: Suzuki K Poulose --- hw/cfi_flash.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/cfi_flash.c b/hw/cfi_flash.c index 7faecdfb..bce546bc 100644 --- a/hw/cfi_flash.c +++ b/hw/cfi_flash.c @@ -455,6 +455,8 @@ static int map_flash_memory(struct kvm *kvm, struct cfi_flash_device *sfdev) KVM_MEM_TYPE_RAM | KVM_MEM_TYPE_READONLY); if (!ret) sfdev->is_mapped = true; + else + die("CFI Flash: ERROR: Unable to map memory: %d\n", ret); return ret; } @@ -472,6 +474,8 @@ static int unmap_flash_memory(struct kvm *kvm, struct cfi_flash_device *sfdev) if (!ret) sfdev->is_mapped = false; + else + die("CFI Flash: Failed to unmap Flash %d", ret); return ret; } From patchwork Fri Jan 27 11:39:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49273 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp787231wrn; Fri, 27 Jan 2023 03:43:49 -0800 (PST) X-Google-Smtp-Source: AMrXdXs0mFY//C46bsvUFgClnXCYc8rQcQa2RcW15TYTD6HeI2hP1aZEnSYiKG7w9rAiMWx+Jue+ X-Received: by 2002:a05:6a20:8e03:b0:b8:a19f:4f6c with SMTP id y3-20020a056a208e0300b000b8a19f4f6cmr56050531pzj.62.1674819829511; Fri, 27 Jan 2023 03:43:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674819829; cv=none; d=google.com; s=arc-20160816; b=uARcrTv6jfPbg2N4Z14ULQKFbe8IHNGy8Bc1g3ETPfKSr7MphZYT0pt6+HzFFg7/05 6yaq2XMR3L0ceLP/D7OIUfzTj2pCTbr217rCiLlIxQ/oGm/apwDQn1peFqR2GV8E7zJE //bpkfmMIHk4pOlur+ynftGdJ9AVRh60K95Oo0/KZjfgR43ABQM+KXAqDu/SixR6SMK3 8ZGsV7Hno+60cO9um2K7wuvSEg3fMwYZSWirvDNbhbqtV3DXTlRh/Fiy7Z8VYidgddfy 5MFsxe447oBuDDLkUHkiPmM5a1PjOYD4F6Rv2tIcYzAqqN9EhGL5UsJli32L2gr1fIlX nIBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=mlBzns4MOFzSwChaRLYDR7Xi0+DbmuSihTx+TZLNWRw=; b=vUxB6wpmMHr+C29RM0Y2dfYTCpTNJkMs9//YkcvwChleF/1ASLVpi4p9E2JSkENytO flpDiKj0fl2ZEiTLwEfm5I26mIC3YEmtRRWFWi0KW5RWafOLg10vTVGK3gzdzmOSsSFa nVUEa9HoeteawufaW+j4fqyjEEtjrG3XNH7DjUp/FSY0Plb8OzT4ehw5raPC8JT+GNjq tJ378+EjwIPpzg2RJcebr6EJ3hZofHm6JZcDL2Nc9yA00WoYEN6zmAY5PnzQlihY0G/B MvkhfXz8hPl0WohZnC8/Egr7e80tQrQE+sZWU7TgIYeOSgWxVsh7mFOIW949KQunY+dz N0Iw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i4-20020a633c44000000b00478831d07f9si3967362pgn.312.2023.01.27.03.43.37; Fri, 27 Jan 2023 03:43:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233643AbjA0Lko (ORCPT + 99 others); Fri, 27 Jan 2023 06:40:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234219AbjA0Lkk (ORCPT ); Fri, 27 Jan 2023 06:40:40 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0BE7024CB3; Fri, 27 Jan 2023 03:40:22 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 415CD1650; Fri, 27 Jan 2023 03:40:42 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B89653F64C; Fri, 27 Jan 2023 03:39:57 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 04/31] Add --nocompat option to disable compat warnings Date: Fri, 27 Jan 2023 11:39:05 +0000 Message-Id: <20230127113932.166089-5-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756175877746281226?= X-GMAIL-MSGID: =?utf-8?q?1756175877746281226?= From: Alexandru Elisei Commit e66942073035 ("kvm tools: Guest kernel compatability") added the functionality that enables devices to print a warning message if the device hasn't been initialized by the time the VM is destroyed. The purpose of these messages is to let the user know if the kernel hasn't been built with the correct Kconfig options to take advantage of the said devices (all using virtio). Since then, kvmtool has evolved and now supports loading different payloads (like firmware images), and having those warnings even when it is entirely intentional for the payload not to touch the devices can be confusing for the user and makes the output unnecessarily verbose in those cases. Add the --nocompat option to disable the warnings; the warnings are still enabled by default. Reported-by: Christoffer Dall Signed-off-by: Alexandru Elisei Signed-off-by: Suzuki K Poulose --- builtin-run.c | 5 ++++- guest_compat.c | 1 + include/kvm/kvm-config.h | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/builtin-run.c b/builtin-run.c index bb7e6e8d..f8edfb3f 100644 --- a/builtin-run.c +++ b/builtin-run.c @@ -183,6 +183,8 @@ static int mem_parser(const struct option *opt, const char *arg, int unset) OPT_BOOLEAN('\0', "nodefaults", &(cfg)->nodefaults, "Disable" \ " implicit configuration that cannot be" \ " disabled otherwise"), \ + OPT_BOOLEAN('\0', "nocompat", &(cfg)->nocompat, "Disable" \ + " compat warnings"), \ OPT_CALLBACK('\0', "9p", NULL, "dir_to_share,tag_name", \ "Enable virtio 9p to share files between host and" \ " guest", virtio_9p_rootdir_parser, kvm), \ @@ -797,7 +799,8 @@ static int kvm_cmd_run_work(struct kvm *kvm) static void kvm_cmd_run_exit(struct kvm *kvm, int guest_ret) { - compat__print_all_messages(); + if (!kvm->cfg.nocompat) + compat__print_all_messages(); init_list__exit(kvm); diff --git a/guest_compat.c b/guest_compat.c index fd4704b2..a413c12c 100644 --- a/guest_compat.c +++ b/guest_compat.c @@ -88,6 +88,7 @@ int compat__print_all_messages(void) printf("\n # KVM compatibility warning.\n\t%s\n\t%s\n", msg->title, msg->desc); + printf("\tTo stop seeing this warning, use the --nocompat option.\n"); list_del(&msg->list); compat__free(msg); diff --git a/include/kvm/kvm-config.h b/include/kvm/kvm-config.h index 368e6c7d..88df7cc2 100644 --- a/include/kvm/kvm-config.h +++ b/include/kvm/kvm-config.h @@ -30,6 +30,7 @@ struct kvm_config { u64 vsock_cid; bool virtio_rng; bool nodefaults; + bool nocompat; int active_console; int debug_iodelay; int nrcpus; From patchwork Fri Jan 27 11:39:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49275 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp787308wrn; Fri, 27 Jan 2023 03:44:00 -0800 (PST) X-Google-Smtp-Source: AMrXdXvcSbGm+KS5EaQ0Vz8cSKEnt3FQzPcfnn1DRU+P3/3hAjp7oo9rJIXswJHQSUbSUuLh7kkW X-Received: by 2002:a05:6a20:3d23:b0:b0:4c16:10a6 with SMTP id y35-20020a056a203d2300b000b04c1610a6mr52736277pzi.0.1674819840146; Fri, 27 Jan 2023 03:44:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674819840; cv=none; d=google.com; s=arc-20160816; b=cAnoPjY2N0cyEmPEfnF/QDoDLosXqEpYet9fbSFUn/RVfb9l3KIhRxsNuNmRA0tFCk 0EH2ha9cXp4tMYBcnu7XY0k0OdrbK+pX6ApizGUqdj2LzT4eUXJ1aqqCkv06v+LHkGXu U4j5qdsRwddVzStXA8db3M1frcfJ7JEFN8IuySyoCIK3JFKstOF6YoMkNqHpHkKC8IjX pUGwjVwU50+CT09xhaoenjpM9V6ejKLn8gvkIGdAum8lq9wkGE0dTfKblhATX62q7II6 dPZiZGv4YIGocjapxAMBPLSabL+YcDr5HFzRHZDgW2o4y6J0b2BzY9pk9tZ7phXLHmIB fD/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=84sfHZoRfLpS3lGGYLyZQlR4dPkp/LvqJgaPIu9wwv8=; b=j0sV8us6EWmy57/HVTR2gGwA23WZMOGGTS9sZ0PaPJpWQss/SRwE9t2Jgz29WrXpc2 asGLRMS7LDr45M3jJ8Sc929miuqNwj3hLlMAo79J/4LWqf61oou8nThN7wr4iKrTwSFi JFucGDRp1safNRYMbYBCOCuzJz0/7zJcGg6yIU/p3w7F4waeT9OVPxbhZjm0cmX9tMtU oPF/FzDiB64ZlzGu3avVSqzPt9RhMKZbwIZIZqLDWioL0vHAYVk8BeiyE2/W0jAFzvy2 tOwntCOVRZKDhlprzCVqwgzanvzBNmu0WL8/sY8DzgDOPEpNvTMt+pP/jaCmAWEGp36u YA7Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z29-20020a637e1d000000b004e0d688fb7bsi782475pgc.706.2023.01.27.03.43.47; Fri, 27 Jan 2023 03:44:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232781AbjA0LlR (ORCPT + 99 others); Fri, 27 Jan 2023 06:41:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233857AbjA0LlK (ORCPT ); Fri, 27 Jan 2023 06:41:10 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 94271F77F; Fri, 27 Jan 2023 03:40:41 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2471D1684; Fri, 27 Jan 2023 03:40:45 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 911713F64C; Fri, 27 Jan 2023 03:40:00 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 05/31] arm64: Check pvtime support against the KVM instance Date: Fri, 27 Jan 2023 11:39:06 +0000 Message-Id: <20230127113932.166089-6-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756175888587412376?= X-GMAIL-MSGID: =?utf-8?q?1756175888587412376?= KVM_CAP_STEAL_TIME can be checked against a VM instance. To allow controlling the feature depending on the VM type, use the cap against the VM. Signed-off-by: Suzuki K Poulose --- arm/aarch64/pvtime.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arm/aarch64/pvtime.c b/arm/aarch64/pvtime.c index 2933ac7c..839aa8a7 100644 --- a/arm/aarch64/pvtime.c +++ b/arm/aarch64/pvtime.c @@ -58,8 +58,8 @@ int kvm_cpu__setup_pvtime(struct kvm_cpu *vcpu) if (kvm_cfg->no_pvtime) return 0; - has_stolen_time = kvm__supports_extension(vcpu->kvm, - KVM_CAP_STEAL_TIME); + has_stolen_time = kvm__supports_vm_extension(vcpu->kvm, + KVM_CAP_STEAL_TIME); if (!has_stolen_time) { kvm_cfg->no_pvtime = true; return 0; From patchwork Fri Jan 27 11:39:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49276 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp787313wrn; Fri, 27 Jan 2023 03:44:01 -0800 (PST) X-Google-Smtp-Source: AMrXdXuS+kMJxIzmFkJQs9nUoxbhT5jdn+vnVrpnAB2rQrbiHm6r8255KDU9xpUxdQsGagv8UPTV X-Received: by 2002:a05:6a20:3d11:b0:b9:6932:7d71 with SMTP id y17-20020a056a203d1100b000b969327d71mr37185791pzi.26.1674819840781; Fri, 27 Jan 2023 03:44:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674819840; cv=none; d=google.com; s=arc-20160816; b=UaI/1KXI9E93W8F9MCXNItEe/p8lp3AIFZfeVQg7uSdWyyS2CuOC0CDXpUf6za2Csh W9Lm0NF5k+GweQ78FOafzNaaWeQo2HTaExsNIpcSQaAtRUdUXdes+3PASYHwrTS2BzDc 6MgrTfJWfi79mzDfLLf5K7pQ9J8D+g27wuseTwkcyHdQdDIej1AdcRm55aaOcAXQNl+7 xJ8UPcLXkxwdBz13atY0H91kS0vBD4phsk/UNIOIQjxKrTXFTLdvvJdZqETVzY2QUhGC CgIYEIynsib7EX4uH+38PNbBM7Hb5w99FLvzYVWZoopf0WLeW8GeWJM5E2WBUV0jwwdC 9arg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=7+bsampohgBv39ASPzSj9WgXs7rydq/Xscviu/N5stE=; b=IYJRCFlihcGw/egpXsfeKYd+z7eNLlmG13lRF3Mj/PbmqLZsEtslYE8AVYgyY8A/Zw 95o/OmM0z1oKtCo4kxv4x1EVrlL9H8g3VMPlsZ4k0SBOBcP77CdktoV0Snq1Oz+kpOJL /KJ4uP1ksCznlavUGI02mmUYZMP/5gwum3iJ8yw2CF7dt8iNbWqMZEXPE+a4TuXeGJg0 QgMRSKYRQIgrV+Ri0wbPcjC6UfjJaucH4LgRWGAxiTlXExGf70QMIYuOoqvjg1bHo4QE c/+Ia1GWdFizfVir2zUx/B8TlQPIC6+tRsbdH3G0CT1OtgBXEyxYxZP+tKhkNLrQfxrt 54mg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u2-20020a63a902000000b004de819c6255si4003592pge.132.2023.01.27.03.43.48; Fri, 27 Jan 2023 03:44:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233742AbjA0LlV (ORCPT + 99 others); Fri, 27 Jan 2023 06:41:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233855AbjA0LlK (ORCPT ); Fri, 27 Jan 2023 06:41:10 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9446B10250; Fri, 27 Jan 2023 03:40:41 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 06F48165C; Fri, 27 Jan 2023 03:40:48 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7406D3F64C; Fri, 27 Jan 2023 03:40:03 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 06/31] arm64: Check SVE capability on the VM instance Date: Fri, 27 Jan 2023 11:39:07 +0000 Message-Id: <20230127113932.166089-7-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756175889089350753?= X-GMAIL-MSGID: =?utf-8?q?1756175889089350753?= Similar to PVtime, check the SVE capability on the VM instance to account for the different VM types and the corresponding support. Signed-off-by: Suzuki K Poulose --- arm/aarch64/kvm-cpu.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arm/aarch64/kvm-cpu.c b/arm/aarch64/kvm-cpu.c index c8be10b3..da809806 100644 --- a/arm/aarch64/kvm-cpu.c +++ b/arm/aarch64/kvm-cpu.c @@ -150,13 +150,15 @@ void kvm_cpu__select_features(struct kvm *kvm, struct kvm_vcpu_init *init) } /* Enable SVE if available */ - if (kvm__supports_extension(kvm, KVM_CAP_ARM_SVE)) + if (kvm__supports_vm_extension(kvm, KVM_CAP_ARM_SVE)) init->features[0] |= 1UL << KVM_ARM_VCPU_SVE; } int kvm_cpu__configure_features(struct kvm_cpu *vcpu) { - if (kvm__supports_extension(vcpu->kvm, KVM_CAP_ARM_SVE)) { + struct kvm *kvm = vcpu->kvm; + + if (kvm__supports_vm_extension(kvm, KVM_CAP_ARM_SVE)) { int feature = KVM_ARM_VCPU_SVE; if (ioctl(vcpu->vcpu_fd, KVM_ARM_VCPU_FINALIZE, &feature)) { From patchwork Fri Jan 27 11:39:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49277 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp787330wrn; Fri, 27 Jan 2023 03:44:04 -0800 (PST) X-Google-Smtp-Source: AK7set9rW8RX9WbopF5LM2PUc5oD+UuniPFn4zTOVQn+EzkP7JuioBb/47zkgpODKvLB6pRqnaML X-Received: by 2002:a05:6a00:f05:b0:592:eb50:1608 with SMTP id cr5-20020a056a000f0500b00592eb501608mr863175pfb.25.1674819844133; Fri, 27 Jan 2023 03:44:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674819844; cv=none; d=google.com; s=arc-20160816; b=ez7P3LlGtUNCA2fhXq2x1zX6oQoBWu2P8iO9EwMRiQAmRNOvAhbFeBgapLDJ9/J/hM /3ILq2xe9UCBNiBSn7APcdMGhSUhYXGBOQDdyUeFPI+4wEf72He9Pd516DJms5xnkVIz HIJW1BLwBYqd2aJZUvEmgEf2rOwjq0NAHwNJIWQomtfUw6I51Uq1YsfqvtbLfYbEcyLq OoX7zW0fKj3FKA8CoLSWcgec76dPbfKtXWg9hx1tSEhAMYBUX7bE4M4hPu37wqCvgqqK c+LQ+tWHBJw77vZjIM+YO1QBlGKX8u9wUX//r9CH2Hv/qUy7e2rqeZqu4l7liuTOaEKc YAeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=P/YmgDRfk18VCIffG0onLj3PmlY0drXgt8mvlDK7nCU=; b=Z0rGqD9Y6yjmVIB0fO8AXIlWZSXKO4kkrx4L/HOxcMCyStd+xGmG4lQNDwnngsEY4u /AZW73AQsJtdMg0LUjjOJ5Bpq0jn7a/W34Tq3lPYtnFsPtbgbPnWDyuuWClQg9LUnGvk dec6ZuuMq/Ki1ApZx2naPSYz5H32ze60Z9OTkp83MA1oUgR0WKLVF7V3UP5okkeebBh8 f9yeDyUxaLHUWy5elYZQv3ExrJiyJcrOwM76HHc6ynreykyWgcdlMNak8fyZXo+evxPW XGej0GN4io5i1aN7fEg4ENaQYUoLDQbmqwt9b8vcQyEcYtkgjFxiMoYvaY6uiduvVaK/ 215w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j5-20020aa78005000000b00563a0453c55si3861490pfi.268.2023.01.27.03.43.51; Fri, 27 Jan 2023 03:44:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233808AbjA0LlX (ORCPT + 99 others); Fri, 27 Jan 2023 06:41:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233174AbjA0LlK (ORCPT ); Fri, 27 Jan 2023 06:41:10 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 68A7411650; Fri, 27 Jan 2023 03:40:42 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D42961688; Fri, 27 Jan 2023 03:40:50 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 56CDA3F64C; Fri, 27 Jan 2023 03:40:06 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 07/31] arm64: Add option to disable SVE Date: Fri, 27 Jan 2023 11:39:08 +0000 Message-Id: <20230127113932.166089-8-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756175892877263919?= X-GMAIL-MSGID: =?utf-8?q?1756175892877263919?= kvmtool enables SVE whenever it is supported by the KVM. However, Realm VMs may want controlled features, which gets measured during the creation. Thus, provide an option to disable the SVE, to preserve the current behavior of SVE on by default. Signed-off-by: Suzuki K Poulose --- arm/aarch64/include/kvm/kvm-config-arch.h | 4 +++- arm/aarch64/kvm-cpu.c | 8 +++++--- arm/include/arm-common/kvm-config-arch.h | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/arm/aarch64/include/kvm/kvm-config-arch.h b/arm/aarch64/include/kvm/kvm-config-arch.h index eae8080d..b055fef4 100644 --- a/arm/aarch64/include/kvm/kvm-config-arch.h +++ b/arm/aarch64/include/kvm/kvm-config-arch.h @@ -19,7 +19,9 @@ int vcpu_affinity_parser(const struct option *opt, const char *arg, int unset); "Specify random seed for Kernel Address Space " \ "Layout Randomization (KASLR)"), \ OPT_BOOLEAN('\0', "no-pvtime", &(cfg)->no_pvtime, "Disable" \ - " stolen time"), + " stolen time"), \ + OPT_BOOLEAN('\0', "disable-sve", &(cfg)->disable_sve, \ + "Disable SVE"), #include "arm-common/kvm-config-arch.h" #endif /* KVM__KVM_CONFIG_ARCH_H */ diff --git a/arm/aarch64/kvm-cpu.c b/arm/aarch64/kvm-cpu.c index da809806..e7649239 100644 --- a/arm/aarch64/kvm-cpu.c +++ b/arm/aarch64/kvm-cpu.c @@ -149,8 +149,9 @@ void kvm_cpu__select_features(struct kvm *kvm, struct kvm_vcpu_init *init) init->features[0] |= 1UL << KVM_ARM_VCPU_PTRAUTH_GENERIC; } - /* Enable SVE if available */ - if (kvm__supports_vm_extension(kvm, KVM_CAP_ARM_SVE)) + /* If SVE is not disabled explicitly, enable if available */ + if (!kvm->cfg.arch.disable_sve && + kvm__supports_vm_extension(kvm, KVM_CAP_ARM_SVE)) init->features[0] |= 1UL << KVM_ARM_VCPU_SVE; } @@ -158,7 +159,8 @@ int kvm_cpu__configure_features(struct kvm_cpu *vcpu) { struct kvm *kvm = vcpu->kvm; - if (kvm__supports_vm_extension(kvm, KVM_CAP_ARM_SVE)) { + if (!kvm->cfg.arch.disable_sve && + kvm__supports_vm_extension(kvm, KVM_CAP_ARM_SVE)) { int feature = KVM_ARM_VCPU_SVE; if (ioctl(vcpu->vcpu_fd, KVM_ARM_VCPU_FINALIZE, &feature)) { diff --git a/arm/include/arm-common/kvm-config-arch.h b/arm/include/arm-common/kvm-config-arch.h index 9949bfe4..6599305b 100644 --- a/arm/include/arm-common/kvm-config-arch.h +++ b/arm/include/arm-common/kvm-config-arch.h @@ -15,6 +15,7 @@ struct kvm_config_arch { enum irqchip_type irqchip; u64 fw_addr; bool no_pvtime; + bool disable_sve; }; int irqchip_parser(const struct option *opt, const char *arg, int unset); From patchwork Fri Jan 27 11:39:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49284 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp787535wrn; Fri, 27 Jan 2023 03:44:48 -0800 (PST) X-Google-Smtp-Source: AK7set/suyBBFQP9Em/96MpOXMjqpSK5EI82jC4jMbyDIR8e/TonorEjPoRZfEUuVM8QKNZ70ZxT X-Received: by 2002:a17:902:f203:b0:192:7f35:90ed with SMTP id m3-20020a170902f20300b001927f3590edmr4298136plc.11.1674819887758; Fri, 27 Jan 2023 03:44:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674819887; cv=none; d=google.com; s=arc-20160816; b=RDl11eX8vhgS3n+03rHgr2+xwrzvQvy3aNF+dv/Qwt/vJ43NyDvWtzNit4lt9qpSX0 GBMDdVB27fRdnw9T+Iz+3xKvpiobrNFehZUxEAXlw2FHaS8Dgu/xr+W5wgrPdSmcvUhT mo0/D7ZBWJxexm7Y2tsMaRrCUtXb3j08vCce3k8jstSdMv988I4nr4ocV+AIc2LjEcK7 hGSb8nFKJouicKpSB0iUsiTTmkQ7BubROJxdO4LOpQeuk9PAoDtop+yv5s6ssUAPqBHW H1cTqm4SlYqeIAXVHiykoxvnWSSks8RQj/YfURXnGo+s/LHyeXX5sVSaw597m4j77jwM S8cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Tjnm3kWBfPTu5ULSERq6Q77KWaDtfThZXkoAE5UTu+0=; b=sQwtsvB930kur+cWb19h6agc2FPP7TwRT5lPpmysIGRt79boZe4Jfr7QfY0BlesHOL 5DNoGEVSnp2gEyrNrviWIWZ0n7facqscIfkjwrEgrhi5181mjD8CJesjgeCArUBldqN7 K76Hhl4/HRYeORBrsQCRjll8/E5bVBdnHHc8enfDEbLNin9V8/2c3GIDFWxz+yhm5VPV t8qcZT2VGGuejmL02xXb1mxe3AOQU2Indlqe/fX/UZuYQi+k23Zub3G6Cg2xydDuR0Wk 8+gau8P6twzEyVeyok5cKis4suqiEuT976aDkPEFW0a/ovR2tVq41av5BO1L1uKPJtb3 MZmg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u5-20020a17090282c500b001949d488c0asi4257907plz.508.2023.01.27.03.44.35; Fri, 27 Jan 2023 03:44:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232782AbjA0Ll1 (ORCPT + 99 others); Fri, 27 Jan 2023 06:41:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233863AbjA0LlK (ORCPT ); Fri, 27 Jan 2023 06:41:10 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BCE2320D1B; Fri, 27 Jan 2023 03:40:42 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id ADE761691; Fri, 27 Jan 2023 03:40:53 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 30A043F64C; Fri, 27 Jan 2023 03:40:09 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 08/31] linux: Update kernel headers for RME support Date: Fri, 27 Jan 2023 11:39:09 +0000 Message-Id: <20230127113932.166089-9-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756175938936991450?= X-GMAIL-MSGID: =?utf-8?q?1756175938936991450?= Update the RME specific ABI bits from the kernel headers. Signed-off-by: Suzuki K Poulose --- arm/aarch64/include/asm/kvm.h | 64 +++++++++++++++++++++++++++++++++++ include/linux/kvm.h | 22 +++++++++--- include/linux/virtio_blk.h | 19 ----------- include/linux/virtio_net.h | 14 ++++---- include/linux/virtio_ring.h | 16 +++------ 5 files changed, 93 insertions(+), 42 deletions(-) diff --git a/arm/aarch64/include/asm/kvm.h b/arm/aarch64/include/asm/kvm.h index 316917b9..653a08fb 100644 --- a/arm/aarch64/include/asm/kvm.h +++ b/arm/aarch64/include/asm/kvm.h @@ -108,6 +108,7 @@ struct kvm_regs { #define KVM_ARM_VCPU_SVE 4 /* enable SVE for this CPU */ #define KVM_ARM_VCPU_PTRAUTH_ADDRESS 5 /* VCPU uses address authentication */ #define KVM_ARM_VCPU_PTRAUTH_GENERIC 6 /* VCPU uses generic authentication */ +#define KVM_ARM_VCPU_REC 7 /* VCPU REC state as part of Realm */ struct kvm_vcpu_init { __u32 target; @@ -400,6 +401,69 @@ enum { #define KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES 3 #define KVM_DEV_ARM_ITS_CTRL_RESET 4 +/* KVM_CAP_ARM_RME kvm_enable_cap->args[0] points to this */ +#define KVM_CAP_ARM_RME_CONFIG_REALM 0 +#define KVM_CAP_ARM_RME_CREATE_RD 1 +#define KVM_CAP_ARM_RME_INIT_IPA_REALM 2 +#define KVM_CAP_ARM_RME_POPULATE_REALM 3 +#define KVM_CAP_ARM_RME_ACTIVATE_REALM 4 + +#define KVM_CAP_ARM_RME_MEASUREMENT_ALGO_ZERO (0x01ULL << 7) +#define KVM_CAP_ARM_RME_MEASUREMENT_ALGO_SHA256 0 +#define KVM_CAP_ARM_RME_MEASUREMENT_ALGO_SHA512 1 + +#define KVM_CAP_ARM_RME_RPV_SIZE 64 + +/* List of configuration items accepted for KVM_CAP_ARM_RME_CONFIG_REALM */ +#define KVM_CAP_ARM_RME_CFG_RPV 0 +#define KVM_CAP_ARM_RME_CFG_HASH_ALGO 1 +#define KVM_CAP_ARM_RME_CFG_SVE 2 +#define KVM_CAP_ARM_RME_CFG_DBG 3 +#define KVM_CAP_ARM_RME_CFG_PMU 4 + +struct kvm_cap_arm_rme_config_item { + __u32 cfg; + union { + /* cfg == KVM_CAP_ARM_RME_CFG_RPV */ + struct { + __u8 rpv[KVM_CAP_ARM_RME_RPV_SIZE]; + }; + + /* cfg == KVM_CAP_ARM_RME_CFG_HASH_ALGO */ + struct { + __u32 hash_algo; + }; + + /* cfg == KVM_CAP_ARM_RME_CFG_SVE */ + struct { + __u32 sve_vq; + }; + + /* cfg == KVM_CAP_ARM_RME_CFG_DBG */ + struct { + __u32 num_brps; + __u32 num_wrps; + }; + + /* cfg == KVM_CAP_ARM_RME_CFG_PMU */ + struct { + __u32 num_pmu_cntrs; + }; + /* Fix the size of the union */ + __u8 reserved[256]; + }; +}; + +struct kvm_cap_arm_rme_populate_realm_args { + __u64 populate_ipa_base; + __u64 populate_ipa_size; +}; + +struct kvm_cap_arm_rme_init_ipa_args { + __u64 init_ipa_base; + __u64 init_ipa_size; +}; + /* Device Control API on vcpu fd */ #define KVM_ARM_VCPU_PMU_V3_CTRL 0 #define KVM_ARM_VCPU_PMU_V3_IRQ 0 diff --git a/include/linux/kvm.h b/include/linux/kvm.h index 0d5d4419..789c7f89 100644 --- a/include/linux/kvm.h +++ b/include/linux/kvm.h @@ -903,14 +903,25 @@ struct kvm_ppc_resize_hpt { #define KVM_S390_SIE_PAGE_OFFSET 1 /* - * On arm64, machine type can be used to request the physical - * address size for the VM. Bits[7-0] are reserved for the guest - * PA size shift (i.e, log2(PA_Size)). For backward compatibility, - * value 0 implies the default IPA size, 40bits. + * On arm64, machine type can be used to request both the machine type and + * the physical address size for the VM. + * + * Bits[11-8] are reserved for the ARM specific machine type. + * + * Bits[7-0] are reserved for the guest PA size shift (i.e, log2(PA_Size)). + * For backward compatibility, value 0 implies the default IPA size, 40bits. */ +#define KVM_VM_TYPE_ARM_SHIFT 8 +#define KVM_VM_TYPE_ARM_MASK (0xfULL << KVM_VM_TYPE_ARM_SHIFT) +#define KVM_VM_TYPE_ARM(_type) \ + (((_type) << KVM_VM_TYPE_ARM_SHIFT) & KVM_VM_TYPE_ARM_MASK) +#define KVM_VM_TYPE_ARM_NORMAL KVM_VM_TYPE_ARM(0) +#define KVM_VM_TYPE_ARM_REALM KVM_VM_TYPE_ARM(1) + #define KVM_VM_TYPE_ARM_IPA_SIZE_MASK 0xffULL #define KVM_VM_TYPE_ARM_IPA_SIZE(x) \ ((x) & KVM_VM_TYPE_ARM_IPA_SIZE_MASK) + /* * ioctls for /dev/kvm fds: */ @@ -1177,7 +1188,8 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_VM_DISABLE_NX_HUGE_PAGES 220 #define KVM_CAP_S390_ZPCI_OP 221 #define KVM_CAP_S390_CPU_TOPOLOGY 222 -#define KVM_CAP_DIRTY_LOG_RING_ACQ_REL 223 + +#define KVM_CAP_ARM_RME 300 // FIXME: Large number to prevent conflicts #ifdef KVM_CAP_IRQ_ROUTING diff --git a/include/linux/virtio_blk.h b/include/linux/virtio_blk.h index 58e70b24..d888f013 100644 --- a/include/linux/virtio_blk.h +++ b/include/linux/virtio_blk.h @@ -40,7 +40,6 @@ #define VIRTIO_BLK_F_MQ 12 /* support more than one vq */ #define VIRTIO_BLK_F_DISCARD 13 /* DISCARD is supported */ #define VIRTIO_BLK_F_WRITE_ZEROES 14 /* WRITE ZEROES is supported */ -#define VIRTIO_BLK_F_SECURE_ERASE 16 /* Secure Erase is supported */ /* Legacy feature bits */ #ifndef VIRTIO_BLK_NO_LEGACY @@ -122,21 +121,6 @@ struct virtio_blk_config { __u8 write_zeroes_may_unmap; __u8 unused1[3]; - - /* the next 3 entries are guarded by VIRTIO_BLK_F_SECURE_ERASE */ - /* - * The maximum secure erase sectors (in 512-byte sectors) for - * one segment. - */ - __virtio32 max_secure_erase_sectors; - /* - * The maximum number of secure erase segments in a - * secure erase command. - */ - __virtio32 max_secure_erase_seg; - /* Secure erase commands must be aligned to this number of sectors. */ - __virtio32 secure_erase_sector_alignment; - } __attribute__((packed)); /* @@ -171,9 +155,6 @@ struct virtio_blk_config { /* Write zeroes command */ #define VIRTIO_BLK_T_WRITE_ZEROES 13 -/* Secure erase command */ -#define VIRTIO_BLK_T_SECURE_ERASE 14 - #ifndef VIRTIO_BLK_NO_LEGACY /* Barrier before this op. */ #define VIRTIO_BLK_T_BARRIER 0x80000000 diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h index 6cb842ea..29ced555 100644 --- a/include/linux/virtio_net.h +++ b/include/linux/virtio_net.h @@ -56,7 +56,7 @@ #define VIRTIO_NET_F_MQ 22 /* Device supports Receive Flow * Steering */ #define VIRTIO_NET_F_CTRL_MAC_ADDR 23 /* Set MAC address */ -#define VIRTIO_NET_F_NOTF_COAL 53 /* Device supports notifications coalescing */ +#define VIRTIO_NET_F_NOTF_COAL 53 /* Guest can handle notifications coalescing */ #define VIRTIO_NET_F_HASH_REPORT 57 /* Supports hash report */ #define VIRTIO_NET_F_RSS 60 /* Supports RSS RX steering */ #define VIRTIO_NET_F_RSC_EXT 61 /* extended coalescing info */ @@ -364,24 +364,24 @@ struct virtio_net_hash_config { */ #define VIRTIO_NET_CTRL_NOTF_COAL 6 /* - * Set the tx-usecs/tx-max-packets parameters. + * Set the tx-usecs/tx-max-packets patameters. + * tx-usecs - Maximum number of usecs to delay a TX notification. + * tx-max-packets - Maximum number of packets to send before a TX notification. */ struct virtio_net_ctrl_coal_tx { - /* Maximum number of packets to send before a TX notification */ __le32 tx_max_packets; - /* Maximum number of usecs to delay a TX notification */ __le32 tx_usecs; }; #define VIRTIO_NET_CTRL_NOTF_COAL_TX_SET 0 /* - * Set the rx-usecs/rx-max-packets parameters. + * Set the rx-usecs/rx-max-packets patameters. + * rx-usecs - Maximum number of usecs to delay a RX notification. + * rx-max-frames - Maximum number of packets to receive before a RX notification. */ struct virtio_net_ctrl_coal_rx { - /* Maximum number of packets to receive before a RX notification */ __le32 rx_max_packets; - /* Maximum number of usecs to delay a RX notification */ __le32 rx_usecs; }; diff --git a/include/linux/virtio_ring.h b/include/linux/virtio_ring.h index f8c20d3d..476d3e5c 100644 --- a/include/linux/virtio_ring.h +++ b/include/linux/virtio_ring.h @@ -93,21 +93,15 @@ #define VRING_USED_ALIGN_SIZE 4 #define VRING_DESC_ALIGN_SIZE 16 -/** - * struct vring_desc - Virtio ring descriptors, - * 16 bytes long. These can chain together via @next. - * - * @addr: buffer address (guest-physical) - * @len: buffer length - * @flags: descriptor flags - * @next: index of the next descriptor in the chain, - * if the VRING_DESC_F_NEXT flag is set. We chain unused - * descriptors via this, too. - */ +/* Virtio ring descriptors: 16 bytes. These can chain together via "next". */ struct vring_desc { + /* Address (guest-physical). */ __virtio64 addr; + /* Length. */ __virtio32 len; + /* The flags as indicated above. */ __virtio16 flags; + /* We chain unused descriptors via this, too */ __virtio16 next; }; From patchwork Fri Jan 27 11:39:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49282 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp787481wrn; Fri, 27 Jan 2023 03:44:36 -0800 (PST) X-Google-Smtp-Source: AMrXdXs99tNgWUA1bsM7yp1ybqQzZaleIoG7yqpdgrL4IRqVkM8CkbRj9VFC2qzxGUL7cDq4igez X-Received: by 2002:a05:6a20:a682:b0:ad:5747:9f6e with SMTP id ba2-20020a056a20a68200b000ad57479f6emr38953925pzb.39.1674819876383; Fri, 27 Jan 2023 03:44:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674819876; cv=none; d=google.com; s=arc-20160816; b=OBZunOespFLpNqYK8lsZPvlsvOd8IcPCpms8W8ZHkqiNWSXpX3RVTlduR0WM4AhKCC ZYIRw5XuDnBVtTkm1Ll8dc0X3lEvF1MUogttvU3HTVtW7Ue/DQHI9e+ngnwTHDhwv3+w FkArYyWt/xbKWRfBF/BTzFMbE810p+X2UFs8hHLPpD9p6mguZ4vKbbSCKNmcAJIOYcGs BpOYxWe0lwAqh63t1MqYL4vQCZftCqcKJ6AdH7qBeIl1I1w0HQ10GvRysaVx1iECGTDR cbiF2l8WlvDm3MIj9ogvi5DaLDLUh3VOW/K4GNuxr0pCLY5bO+uweth9Vcj1fHnihi+F QCIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=/1o+bRjjE4XQGyRBsNTobl1l+DnZQ4gwHzvp83AEnVs=; b=ldzoq+GpIx9AFXX65ou1oWiPYLPYAE2af6/1+A39xKJBk++hoIW9Rlt5ZgzfLRibbB kaewiJc7ThZvavTsnbzcGX5sjbxd0MJl6XFgqopoC0AcHwkI4WOzOLacePJP8tli4VDO JH2ajpjhC5BfVbEAVndEWYibAMh/Be2ix9ibLLg6DKDp01dkZvopGiedtDWLGgnRU5eN 5T3yhmebKSxVcNLDDkVRDbfllT6dR9qvDeLo6wzaRVeA7wBV/tlkslQLRM+OPuIZLASZ CZIERtaRdoldxBKtKgql4MFNU/LxYB4zXEVKICge0N7r6eZ2nF7vYxTyZR8E0vmegNEa G5fw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j5-20020a637a45000000b004d2f5bb933dsi4087362pgn.76.2023.01.27.03.44.23; Fri, 27 Jan 2023 03:44:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233841AbjA0Lla (ORCPT + 99 others); Fri, 27 Jan 2023 06:41:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233864AbjA0LlK (ORCPT ); Fri, 27 Jan 2023 06:41:10 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EA711196B1; Fri, 27 Jan 2023 03:40:42 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8928E169C; Fri, 27 Jan 2023 03:40:56 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0A2453F64C; Fri, 27 Jan 2023 03:40:11 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 09/31] arm64: Add --realm command line option Date: Fri, 27 Jan 2023 11:39:10 +0000 Message-Id: <20230127113932.166089-10-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756175926688206228?= X-GMAIL-MSGID: =?utf-8?q?1756175926688206228?= From: Alexandru Elisei Add the --realm command line option which causes kvmtool to exit with an error if specified, but which will be enabled once realms are fully supported by kvmtool. Signed-off-by: Alexandru Elisei Signed-off-by: Suzuki K Poulose --- arm/aarch64/include/kvm/kvm-config-arch.h | 5 ++++- arm/aarch64/kvm.c | 20 ++++++++++++++++++-- arm/include/arm-common/kvm-config-arch.h | 1 + 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/arm/aarch64/include/kvm/kvm-config-arch.h b/arm/aarch64/include/kvm/kvm-config-arch.h index b055fef4..d2df850a 100644 --- a/arm/aarch64/include/kvm/kvm-config-arch.h +++ b/arm/aarch64/include/kvm/kvm-config-arch.h @@ -21,7 +21,10 @@ int vcpu_affinity_parser(const struct option *opt, const char *arg, int unset); OPT_BOOLEAN('\0', "no-pvtime", &(cfg)->no_pvtime, "Disable" \ " stolen time"), \ OPT_BOOLEAN('\0', "disable-sve", &(cfg)->disable_sve, \ - "Disable SVE"), + "Disable SVE"), \ + OPT_BOOLEAN('\0', "realm", &(cfg)->is_realm, \ + "Create VM running in a realm using Arm RME"), + #include "arm-common/kvm-config-arch.h" #endif /* KVM__KVM_CONFIG_ARCH_H */ diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c index 5a53badb..25be2f2d 100644 --- a/arm/aarch64/kvm.c +++ b/arm/aarch64/kvm.c @@ -38,9 +38,8 @@ int vcpu_affinity_parser(const struct option *opt, const char *arg, int unset) return 0; } -void kvm__arch_validate_cfg(struct kvm *kvm) +static void validate_mem_cfg(struct kvm *kvm) { - if (kvm->cfg.ram_addr < ARM_MEMORY_AREA) { die("RAM address is below the I/O region ending at %luGB", ARM_MEMORY_AREA >> 30); @@ -52,6 +51,23 @@ void kvm__arch_validate_cfg(struct kvm *kvm) } } +static void validate_realm_cfg(struct kvm *kvm) +{ + if (!kvm->cfg.arch.is_realm) + return; + + if (kvm->cfg.arch.aarch32_guest) + die("Realms supported only for 64bit guests"); + + die("Realms not supported"); +} + +void kvm__arch_validate_cfg(struct kvm *kvm) +{ + validate_mem_cfg(kvm); + validate_realm_cfg(kvm); +} + u64 kvm__arch_default_ram_address(void) { return ARM_MEMORY_AREA; diff --git a/arm/include/arm-common/kvm-config-arch.h b/arm/include/arm-common/kvm-config-arch.h index 6599305b..5eb791da 100644 --- a/arm/include/arm-common/kvm-config-arch.h +++ b/arm/include/arm-common/kvm-config-arch.h @@ -11,6 +11,7 @@ struct kvm_config_arch { bool aarch32_guest; bool has_pmuv3; bool mte_disabled; + bool is_realm; u64 kaslr_seed; enum irqchip_type irqchip; u64 fw_addr; From patchwork Fri Jan 27 11:39:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49283 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp787494wrn; Fri, 27 Jan 2023 03:44:39 -0800 (PST) X-Google-Smtp-Source: AK7set+SxpGgy/Tv7E1YprH0fMVD0yi2oP1mEYq5x7TkbTGHB4037nYT6jPR5XMf3mQLcnY2M7kI X-Received: by 2002:a17:902:d509:b0:196:4ed2:ec6a with SMTP id b9-20020a170902d50900b001964ed2ec6amr3256969plg.61.1674819879327; Fri, 27 Jan 2023 03:44:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674819879; cv=none; d=google.com; s=arc-20160816; b=rVR2/3PnvzFqbBISzzz8D3x54XySLw63aWw0RFGkjWt0gO9HHao/scQD3zOPfW4gQG AfAToPEF4Fsu9HdDLufQN3mVKTHlETbcfN0WhZSKRPIcMK65oo/8V36w8nAl4GvJCVYy bT1ellT/BKU0CWB2bv4q4Do3WdlfpbzrM7jgXIPEMMdwn54TlX0LMQ3f7rSAT9HOPUNd D0wDk0ndUYh6m331gaYuVPjKESPH1Z2vO8naHjp8m4qgheC/mEnOKgKGmdupbQiFbGvU YrMbPY6t6x1IwBRByD5WKgr+20Q/Nw5RqcYNwxFEBNd3b3V6XaZZv4cob4mGfeN7TDSR nN8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=rurA/eoZc2HF7wVVhzXYfUUSCv6D3Kn0qhAs34AfqVo=; b=Cxq/S4j5YbjI07y+TOHB2K9DUGBrT+gx0wWwOooUdfQIsm74b/Yd3nYMY8qDDbJipJ LgliQ9qIBSndPPjy5IL4r+yzv/qbiqvgOlmjIIr2CJtynJm7URTF77970PtsYgIfHyUf KBLZ3VePTQwjIQzHw3sQ15j48z4S4YU19h9fcZ4Wu38U2f1YBmbg9g18fRJW6SC4gHRh mbRon56+GtYePjKKw6JAzktUWU/f9HG2lBq7z1XbfnvJwZuKibW5tFQQko35kY5l7Blp mdDFXjtOoM1MW/RONlruZjOqCEne/s+SLjU5zoA9T9VPOGFpa+kEwpG/uk5+qOlZgmp7 AJMA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jg20-20020a17090326d400b0017486813f81si4234767plb.528.2023.01.27.03.44.27; Fri, 27 Jan 2023 03:44:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232494AbjA0Lle (ORCPT + 99 others); Fri, 27 Jan 2023 06:41:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233865AbjA0LlK (ORCPT ); Fri, 27 Jan 2023 06:41:10 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 19C1C20D28; Fri, 27 Jan 2023 03:40:43 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 62808169E; Fri, 27 Jan 2023 03:40:59 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D96673F64C; Fri, 27 Jan 2023 03:40:14 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 10/31] arm64: Create a realm virtual machine Date: Fri, 27 Jan 2023 11:39:11 +0000 Message-Id: <20230127113932.166089-11-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756175929353532381?= X-GMAIL-MSGID: =?utf-8?q?1756175929353532381?= From: Christoffer Dall Set the machine type to realm when creating a VM via the KVM_CREATE_VM ioctl. Signed-off-by: Christoffer Dall [ Alex E: Reworked patch, split the command line option into a different patch ] Signed-off-by: Alexandru Elisei Signed-off-by: Suzuki K Poulose --- arm/aarch64/kvm.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c index 25be2f2d..5db4c572 100644 --- a/arm/aarch64/kvm.c +++ b/arm/aarch64/kvm.c @@ -131,12 +131,15 @@ int kvm__arch_get_ipa_limit(struct kvm *kvm) int kvm__get_vm_type(struct kvm *kvm) { unsigned int ipa_bits, max_ipa_bits; - unsigned long max_ipa; + unsigned long max_ipa, vm_type; - /* If we're running on an old kernel, use 0 as the VM type */ + vm_type = kvm->cfg.arch.is_realm ? \ + KVM_VM_TYPE_ARM_REALM : KVM_VM_TYPE_ARM_NORMAL; + + /* If we're running on an old kernel, use 0 as the IPA bits */ max_ipa_bits = kvm__arch_get_ipa_limit(kvm); if (!max_ipa_bits) - return 0; + return vm_type; /* Otherwise, compute the minimal required IPA size */ max_ipa = kvm->cfg.ram_addr + kvm->cfg.ram_size - 1; @@ -147,7 +150,8 @@ int kvm__get_vm_type(struct kvm *kvm) if (ipa_bits > max_ipa_bits) die("Memory too large for this system (needs %d bits, %d available)", ipa_bits, max_ipa_bits); - return KVM_VM_TYPE_ARM_IPA_SIZE(ipa_bits); + vm_type |= KVM_VM_TYPE_ARM_IPA_SIZE(ipa_bits); + return vm_type; } void kvm__arch_enable_mte(struct kvm *kvm) From patchwork Fri Jan 27 11:39:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49289 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp787698wrn; Fri, 27 Jan 2023 03:45:10 -0800 (PST) X-Google-Smtp-Source: AK7set+jEIcoFWNPyeaUKbcOkZegchZZzAQI0J5jhF1VVco5OV4TRsWepgTzLJeCO+XTE0mpm2LF X-Received: by 2002:a17:906:7155:b0:87b:d3b1:e116 with SMTP id z21-20020a170906715500b0087bd3b1e116mr1615563ejj.20.1674819910263; Fri, 27 Jan 2023 03:45:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674819910; cv=none; d=google.com; s=arc-20160816; b=GsDZ5jsv7GXgfQypCaJhp/n9XwdCyv74By1CxQrP16aZunzOzAtn3+mJL83IwDrTFp D9kq3gn/8hzBifDRhyCep4il8+GBSBhzg0F8ODetVaGImrF0HviakNCTOr8KyAwXi6Tf Otjp0ZABbMz1B0s31v7is13jzkrjFIGzmP2vx7c0XOF8f/gRy1GjgfNW/R7g7KgL4qbE BdJARPO73cJzCHxGVCed+I9yA5mq3S+LfDvyRVCSIj3pkHAz4NhJeghwpucFM9pW1A2O n8MVsS0ndFhba/TX570FRSvlX/togrdEib1fugltp40AMQIoPmmNUVfK/dIClsN3nuEK 7Lzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=8RX/2h5XNX3qlMiQxN95nX+2mc4G3KkCcmKz7L34SUg=; b=xDDrHj5X595rNfi1EazlyfFzqGMfYNJ0LiryfEWgykvAKGAC2NXdh7Bc4ly892D0Mk Crv07lZ8Q6dU9TQhjFannBO9cdCoLwvNpd5Kip2V8MNGrOanQlkpUvtFHLBU9hrgfYnP xO6UYeKJWh4vmh3tbr5TZBm6hMAbZuJarzt32epXMvQeDYue5Ne7rv1SYGrjv7uTZibZ VTXabykYdHKAbotoTIucgWx6jbZTRS+UktMhgKESYx8IiEQvPCb0UDm8XTBhwfJZwUAJ xeCr82+8KA+TRVuS3hDBCHF0qWFin4/EkOWjkyYCA+QbTzxyGLHIBK7F3ojLSwrnTF5v 8r2g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ge10-20020a170907908a00b0087858b74a0bsi3865699ejb.983.2023.01.27.03.44.46; Fri, 27 Jan 2023 03:45:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233713AbjA0Llh (ORCPT + 99 others); Fri, 27 Jan 2023 06:41:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233690AbjA0LlL (ORCPT ); Fri, 27 Jan 2023 06:41:11 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 18908126CA; Fri, 27 Jan 2023 03:40:44 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3C11D16A3; Fri, 27 Jan 2023 03:41:02 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B29523F64C; Fri, 27 Jan 2023 03:40:17 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 11/31] arm64: Lock realm RAM in memory Date: Fri, 27 Jan 2023 11:39:12 +0000 Message-Id: <20230127113932.166089-12-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756175962553210510?= X-GMAIL-MSGID: =?utf-8?q?1756175962553210510?= From: Alexandru Elisei RMM doesn't yet support paging protected memory pages. Thus the VMM must pin the entire VM memory. Use mlock2 to keep the realm pages pinned in memory once they are faulted in. Use the MLOCK_ONFAULT flag to prevent pre-mapping the pages and maintain some semblance of on demand-paging for a realm VM. Signed-off-by: Alexandru Elisei Signed-off-by: Suzuki K Poulose --- arm/kvm.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/arm/kvm.c b/arm/kvm.c index d51cc15d..0e40b753 100644 --- a/arm/kvm.c +++ b/arm/kvm.c @@ -7,6 +7,8 @@ #include "arm-common/gic.h" +#include + #include #include #include @@ -24,6 +26,25 @@ bool kvm__arch_cpu_supports_vm(void) return true; } +static void try_increase_mlock_limit(struct kvm *kvm) +{ + u64 size = kvm->arch.ram_alloc_size; + struct rlimit mlock_limit, new_limit; + + if (getrlimit(RLIMIT_MEMLOCK, &mlock_limit)) { + perror("getrlimit(RLIMIT_MEMLOCK)"); + return; + } + + if (mlock_limit.rlim_cur > size) + return; + + new_limit.rlim_cur = size; + new_limit.rlim_max = max((rlim_t)size, mlock_limit.rlim_max); + /* Requires CAP_SYS_RESOURCE capability. */ + setrlimit(RLIMIT_MEMLOCK, &new_limit); +} + void kvm__init_ram(struct kvm *kvm) { u64 phys_start, phys_size; @@ -49,8 +70,27 @@ void kvm__init_ram(struct kvm *kvm) kvm->ram_start = (void *)ALIGN((unsigned long)kvm->arch.ram_alloc_start, SZ_2M); - madvise(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size, - MADV_MERGEABLE); + /* + * Do not merge pages if this is a Realm. + * a) We cannot replace a page in realm stage2 without export/import + * + * Pin the realm memory until we have export/import, due to the same + * reason as above. + * + * Use mlock2(,,MLOCK_ONFAULT) to allow faulting in pages and thus + * allowing to lazily populate the PAR. + */ + if (kvm->cfg.arch.is_realm) { + int ret; + + try_increase_mlock_limit(kvm); + ret = mlock2(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size, + MLOCK_ONFAULT); + if (ret) + die_perror("mlock2"); + } else { + madvise(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size, MADV_MERGEABLE); + } madvise(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size, MADV_HUGEPAGE); From patchwork Fri Jan 27 11:39:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49290 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp787701wrn; Fri, 27 Jan 2023 03:45:10 -0800 (PST) X-Google-Smtp-Source: AMrXdXuDkF0F7HtXXeofk2Ve9KcMRX53F0uV06XN9PRpOPeKM+6QXnpQMv2Kj8zkua6hHWXGteh/ X-Received: by 2002:aa7:c052:0:b0:475:dddc:374a with SMTP id k18-20020aa7c052000000b00475dddc374amr40560159edo.18.1674819910657; Fri, 27 Jan 2023 03:45:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674819910; cv=none; d=google.com; s=arc-20160816; b=gTdiGzBVEzaRTku+RRZ2uBKFjLjKFjYdlKhBFmIetSisJvZQ1OVT7dAC5K8NeZlCjt 86f1r7FnKtReipktHzcG9zhgwtAtSPL53V8J3UcWPskQNsSqvVO/zqPpAs+lu2fgzGD8 UhxrW5uAAKBCBvH3Ck1YHIaIwkFzB0cSp+XainJ1bVwxGR0mEHVKqmlA0JUxUDSlJw5R R9pR8J2kl4HprxuTbshdfGwVFonsseOGzqeRFvTNX4k0kDwXiYq9GEmKoiB7h5SAatoM ZA5un5WpfO1mBEX41qIIfUB6VxX11R5WJGnxhM9WigGEZdvasH05ZZIM0i3h24cJXTG0 U+Sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=1GltkYO/CGgB32TMjqUQ/TmxTZLldJg+J1rjwp8x+Ko=; b=MaOCZIt7Q2pQJa9mM+w06YOn/2TfmfVhZPUfVs+OnSlcGRhOM+KVSTnxo96HXe+ACE m1cfDkIFHAcSmhAajp197WqgmjWQo0AP/gB8ZRHXULmt8U/G+r2zWu/9kFuc6UlizI2w 9iGz7JU5eQVTHxWqeYa5xRf1jEdGzNcs9l1MYUx0qTZXJIBAscIgrR8DO9qiXBRbFxEF aVKir1RlZbRiw4w94JHjkfu5fwmppSE5psnV/O/Ed+sH2wRN3E4ab8iKYGVPLHA30Bxo pEpbCOyswuCRej9dhmF8yN8HN8dobm0iIwusx4o9bY2LyVY3RRXhleXOM5SL4fYPTGot PBpA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n1-20020a5099c1000000b0046e635ee69esi5967491edb.210.2023.01.27.03.44.46; Fri, 27 Jan 2023 03:45:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233819AbjA0Lll (ORCPT + 99 others); Fri, 27 Jan 2023 06:41:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233874AbjA0LlM (ORCPT ); Fri, 27 Jan 2023 06:41:12 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9F27722A29; Fri, 27 Jan 2023 03:40:44 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 14FA01692; Fri, 27 Jan 2023 03:41:05 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 8C0393F64C; Fri, 27 Jan 2023 03:40:20 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 12/31] arm64: Create Realm Descriptor Date: Fri, 27 Jan 2023 11:39:13 +0000 Message-Id: <20230127113932.166089-13-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756175962402304568?= X-GMAIL-MSGID: =?utf-8?q?1756175962402304568?= From: Alexandru Elisei Create the Realm Descriptor using the measurement algorithm set with --measurement-algo. Signed-off-by: Alexandru Elisei Signed-off-by: Suzuki K Poulose --- Makefile | 1 + arm/aarch32/include/asm/realm.h | 10 ++++++++++ arm/aarch64/include/asm/realm.h | 10 ++++++++++ arm/aarch64/realm.c | 14 ++++++++++++++ arm/kvm.c | 3 +++ 5 files changed, 38 insertions(+) create mode 100644 arm/aarch32/include/asm/realm.h create mode 100644 arm/aarch64/include/asm/realm.h create mode 100644 arm/aarch64/realm.c diff --git a/Makefile b/Makefile index ed2414bd..88cdf6d2 100644 --- a/Makefile +++ b/Makefile @@ -192,6 +192,7 @@ ifeq ($(ARCH), arm64) OBJS += arm/aarch64/kvm.o OBJS += arm/aarch64/pvtime.o OBJS += arm/aarch64/pmu.o + OBJS += arm/aarch64/realm.o ARCH_INCLUDE := $(HDRS_ARM_COMMON) ARCH_INCLUDE += -Iarm/aarch64/include diff --git a/arm/aarch32/include/asm/realm.h b/arm/aarch32/include/asm/realm.h new file mode 100644 index 00000000..5aca6cca --- /dev/null +++ b/arm/aarch32/include/asm/realm.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __ASM_REALM_H +#define __ASM_REALM_H + +#include "kvm/kvm.h" + +static inline void kvm_arm_realm_create_realm_descriptor(struct kvm *kvm) {} + +#endif /* ! __ASM_REALM_H */ diff --git a/arm/aarch64/include/asm/realm.h b/arm/aarch64/include/asm/realm.h new file mode 100644 index 00000000..e176f15f --- /dev/null +++ b/arm/aarch64/include/asm/realm.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __ASM_REALM_H +#define __ASM_REALM_H + +#include "kvm/kvm.h" + +void kvm_arm_realm_create_realm_descriptor(struct kvm *kvm); + +#endif /* ! __ASM_REALM_H */ diff --git a/arm/aarch64/realm.c b/arm/aarch64/realm.c new file mode 100644 index 00000000..3a4adb66 --- /dev/null +++ b/arm/aarch64/realm.c @@ -0,0 +1,14 @@ +#include "kvm/kvm.h" + +#include + +void kvm_arm_realm_create_realm_descriptor(struct kvm *kvm) +{ + struct kvm_enable_cap rme_create_rd = { + .cap = KVM_CAP_ARM_RME, + .args[0] = KVM_CAP_ARM_RME_CREATE_RD, + }; + + if (ioctl(kvm->vm_fd, KVM_ENABLE_CAP, &rme_create_rd) < 0) + die_perror("KVM_CAP_RME(KVM_CAP_ARM_RME_CREATE_RD)"); +} diff --git a/arm/kvm.c b/arm/kvm.c index 0e40b753..2510a322 100644 --- a/arm/kvm.c +++ b/arm/kvm.c @@ -127,6 +127,9 @@ void kvm__arch_set_cmdline(char *cmdline, bool video) void kvm__arch_init(struct kvm *kvm) { + if (kvm->cfg.arch.is_realm) + kvm_arm_realm_create_realm_descriptor(kvm); + /* Create the virtual GIC. */ if (gic__create(kvm, kvm->cfg.arch.irqchip)) die("Failed to create virtual GIC"); From patchwork Fri Jan 27 11:39:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49278 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp787407wrn; Fri, 27 Jan 2023 03:44:21 -0800 (PST) X-Google-Smtp-Source: AMrXdXtjFlcuZdV8tZ+zarGs4DvF3wfvrGVx/L1h3Uoi5P4w1HDT+8vL0Ss9VN8VmrAb0WwmD/xf X-Received: by 2002:a05:6a20:6f06:b0:ad:5cde:8f05 with SMTP id gt6-20020a056a206f0600b000ad5cde8f05mr36467443pzb.37.1674819861699; Fri, 27 Jan 2023 03:44:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674819861; cv=none; d=google.com; s=arc-20160816; b=z3avgceO4V7xvjHwaqcioBnKE9eFwk9qZHeTSHWzm7aaea749DEeQQr8s4SSAHs313 fR1QLQLzLo1euN/IZN3th3EA2CtadJZw+Bg45U0a60KzLOb/jPWXPLsgVVeDqypUpWjF PGiHIqV56uQw9D9DaLXQaP7gGxuXc7po6ba5UM/VlR5Ii6KmEqaIzhGxxU4N8HGkrFxz BopoNiVqEjIXA8xZZCex95JOcpxRgVxP9rv9qPNZr14HeX8fBlKboFG/MUVKG71P97bG CDCvSweHHrGl/r38DSfub42WDYy2yFNnhqCWANjkJvYjbP5aXrS94CsedJRMhodVwiq3 ukMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=AEetKLrO/EAAOpcCFNMbF8UYHwul1xyne71qn3eMHU8=; b=NmhqRTfLs5ZDnJOqwKGPyZXWY84GdnZnepqL6auf35ldCPrz+0RoTIhaVAbYmR+rov sMH/Z9yyWEJSsgHQQsdjlMbY+20VtL8aQhac5VkOmqpvgO35pxZmU1uhUJM2WVvMhqPI i3h5wF6eeWq62SsKgjZjcLrK2P7vBi4vbUlbxp/t6YtgLGZCw15p9CO79t+SZg3pW6be 8TqYoZ64pxlwCWG3xu5CVytswvUi56M9RqibzZfHWDd7ZMRGrhoWYok22WhNUupLzNbM jwo9Uj7K7jC/Vh4KK+Om5tGm09gID5392Lj3rCLXpDZlSpBKmyrJQRFlLQ9MpOi5ipD8 cv6g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j71-20020a638b4a000000b004dfb11310dbsi1785662pge.164.2023.01.27.03.44.08; Fri, 27 Jan 2023 03:44:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229819AbjA0Llp (ORCPT + 99 others); Fri, 27 Jan 2023 06:41:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233878AbjA0LlM (ORCPT ); Fri, 27 Jan 2023 06:41:12 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 66D6C22A39; Fri, 27 Jan 2023 03:40:45 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E28C316F8; Fri, 27 Jan 2023 03:41:07 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6552D3F64C; Fri, 27 Jan 2023 03:40:23 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 13/31] arm64: Add --measurement-algo command line option for a realm Date: Fri, 27 Jan 2023 11:39:14 +0000 Message-Id: <20230127113932.166089-14-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756175911328360157?= X-GMAIL-MSGID: =?utf-8?q?1756175911328360157?= From: Christoffer Dall Add the command line option to specify the algorithm that will be used to create the cryptographic measurement of the realm. Valid options are "sha256" and "sha512". The final measurement will be a hash using the selected algorithm Signed-off-by: Christoffer Dall Signed-off-by: Alexandru Elisei Signed-off-by: Suzuki K Poulose --- arm/aarch64/include/kvm/kvm-config-arch.h | 5 ++++- arm/aarch64/kvm.c | 17 ++++++++++++++++- arm/include/arm-common/kvm-arch.h | 1 + arm/include/arm-common/kvm-config-arch.h | 1 + 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/arm/aarch64/include/kvm/kvm-config-arch.h b/arm/aarch64/include/kvm/kvm-config-arch.h index d2df850a..b93999b6 100644 --- a/arm/aarch64/include/kvm/kvm-config-arch.h +++ b/arm/aarch64/include/kvm/kvm-config-arch.h @@ -23,7 +23,10 @@ int vcpu_affinity_parser(const struct option *opt, const char *arg, int unset); OPT_BOOLEAN('\0', "disable-sve", &(cfg)->disable_sve, \ "Disable SVE"), \ OPT_BOOLEAN('\0', "realm", &(cfg)->is_realm, \ - "Create VM running in a realm using Arm RME"), + "Create VM running in a realm using Arm RME"), \ + OPT_STRING('\0', "measurement-algo", &(cfg)->measurement_algo, \ + "sha256, sha512", \ + "Realm Measurement algorithm, default: sha256"), #include "arm-common/kvm-config-arch.h" diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c index 5db4c572..a5a98b2e 100644 --- a/arm/aarch64/kvm.c +++ b/arm/aarch64/kvm.c @@ -53,12 +53,27 @@ static void validate_mem_cfg(struct kvm *kvm) static void validate_realm_cfg(struct kvm *kvm) { - if (!kvm->cfg.arch.is_realm) + if (!kvm->cfg.arch.is_realm) { + if (kvm->cfg.arch.measurement_algo) + die("--measurement-algo valid only with --realm"); return; + } if (kvm->cfg.arch.aarch32_guest) die("Realms supported only for 64bit guests"); + if (kvm->cfg.arch.measurement_algo) { + if (strcmp(kvm->cfg.arch.measurement_algo, "sha256") == 0) + kvm->arch.measurement_algo = KVM_CAP_ARM_RME_MEASUREMENT_ALGO_SHA256; + else if (strcmp(kvm->cfg.arch.measurement_algo, "sha512") == 0) + kvm->arch.measurement_algo = KVM_CAP_ARM_RME_MEASUREMENT_ALGO_SHA512; + else + die("unknown realm measurement algorithm"); + } else { + pr_debug("Realm Hash algorithm: Using default SHA256\n"); + kvm->arch.measurement_algo = KVM_CAP_ARM_RME_MEASUREMENT_ALGO_SHA256; + } + die("Realms not supported"); } diff --git a/arm/include/arm-common/kvm-arch.h b/arm/include/arm-common/kvm-arch.h index b2ae373c..68224b1c 100644 --- a/arm/include/arm-common/kvm-arch.h +++ b/arm/include/arm-common/kvm-arch.h @@ -113,6 +113,7 @@ struct kvm_arch { u64 dtb_guest_start; cpu_set_t *vcpu_affinity_cpuset; + u64 measurement_algo; }; #endif /* ARM_COMMON__KVM_ARCH_H */ diff --git a/arm/include/arm-common/kvm-config-arch.h b/arm/include/arm-common/kvm-config-arch.h index 5eb791da..a2faa3af 100644 --- a/arm/include/arm-common/kvm-config-arch.h +++ b/arm/include/arm-common/kvm-config-arch.h @@ -6,6 +6,7 @@ struct kvm_config_arch { const char *dump_dtb_filename; const char *vcpu_affinity; + const char *measurement_algo; unsigned int force_cntfrq; bool virtio_trans_pci; bool aarch32_guest; From patchwork Fri Jan 27 11:39:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49279 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp787448wrn; Fri, 27 Jan 2023 03:44:29 -0800 (PST) X-Google-Smtp-Source: AMrXdXsF8N6i/1jhmrVpHxhV6n9ypZ/0tzKaXFvfKv6a4BfVEU9ivQah9aeCW/aWTftzwuNHFyE+ X-Received: by 2002:a62:1488:0:b0:586:b33c:be2 with SMTP id 130-20020a621488000000b00586b33c0be2mr38008748pfu.26.1674819869138; Fri, 27 Jan 2023 03:44:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674819869; cv=none; d=google.com; s=arc-20160816; b=pLMvRe3dtWOKkArcoDOkieqpRuhoPgaHpBdw3V4eMtV/EDuWsGrcHBjuMQ5TKPVO/K WYJ8FuYbiCjYr02hevpyRDVIEYtal0nzDsHj3w9KgaeRKoYAosGDNKhSVktBqTthWBS8 v4vel+JCF1Lyv0+7ZZu9Ojtb/YFDwMIPhu9XyU495tVuLIYYYo6F11Fb9Bx3LzaiDVs7 ipeGXYf9eFETqAXBjlIXKW2jzmfOQS3GtwEgB++l649K231sd31j24hH8ZY2FA4e3LNe lA0ot6lJsZSOpRDAhwzTm/0xkjhR3Hr/8jIe+7KJ6DumOEp7Vuj52Gtkj0FXrIitAz0N MOhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=rAj+t5481vqv5uYMmsZa0P0CjPM3Gvt5jPf04zIHy3E=; b=YZDoU/N1vGS9y69wXSwrmKiUMIpLANqpG0VQjxBSTKtQx56wE1w3KhZK3VGcNVHy5H o+wttdsxyMVJ+/TgMYZB85DcW2Xhhl//eujIRMRlq0u8ZX5NZcBhPQ1CnZstrTAdYYEh ovPQf6hEHm21cwREDVw1Ce/WDr1/dxt3yhuNj5sO+CeJJT7GPFLBMWXcW2vFusyvnl3Z kduy06ijeoJBROGaIirt7bgrPNLH19B2kt8fTocsSRY6s0stgCgA4raA6LxBRL/+uAVC W+hC90+0WUZ9wK9svG4fT0iboNmSN5i7hB8XZeJrTFhfjhUH2Orf/BjacCF41eTpDH5h TCgg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t10-20020a056a00138a00b0058df20ff0e3si4827834pfg.54.2023.01.27.03.44.09; Fri, 27 Jan 2023 03:44:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232385AbjA0Llr (ORCPT + 99 others); Fri, 27 Jan 2023 06:41:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233816AbjA0LlM (ORCPT ); Fri, 27 Jan 2023 06:41:12 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 730BC22DD3; Fri, 27 Jan 2023 03:40:45 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BC9521758; Fri, 27 Jan 2023 03:41:10 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3E5DB3F64C; Fri, 27 Jan 2023 03:40:26 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 14/31] arm64: Add configuration step for Realms Date: Fri, 27 Jan 2023 11:39:15 +0000 Message-Id: <20230127113932.166089-15-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756175919034715311?= X-GMAIL-MSGID: =?utf-8?q?1756175919034715311?= Realm must be configured before it is created. Add the step to specify the parameters for the Realm. Signed-off-by: Suzuki K Poulose --- arm/aarch64/realm.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/arm/aarch64/realm.c b/arm/aarch64/realm.c index 3a4adb66..31543e55 100644 --- a/arm/aarch64/realm.c +++ b/arm/aarch64/realm.c @@ -2,6 +2,29 @@ #include + +static void realm_configure_hash_algo(struct kvm *kvm) +{ + struct kvm_cap_arm_rme_config_item hash_algo_cfg = { + .cfg = KVM_CAP_ARM_RME_CFG_HASH_ALGO, + .hash_algo = kvm->arch.measurement_algo, + }; + + struct kvm_enable_cap rme_config = { + .cap = KVM_CAP_ARM_RME, + .args[0] = KVM_CAP_ARM_RME_CONFIG_REALM, + .args[1] = (u64)&hash_algo_cfg, + }; + + if (ioctl(kvm->vm_fd, KVM_ENABLE_CAP, &rme_config) < 0) + die_perror("KVM_CAP_RME(KVM_CAP_ARM_RME_CONFIG_REALM) hash_algo"); +} + +static void realm_configure_parameters(struct kvm *kvm) +{ + realm_configure_hash_algo(kvm); +} + void kvm_arm_realm_create_realm_descriptor(struct kvm *kvm) { struct kvm_enable_cap rme_create_rd = { @@ -9,6 +32,7 @@ void kvm_arm_realm_create_realm_descriptor(struct kvm *kvm) .args[0] = KVM_CAP_ARM_RME_CREATE_RD, }; + realm_configure_parameters(kvm); if (ioctl(kvm->vm_fd, KVM_ENABLE_CAP, &rme_create_rd) < 0) die_perror("KVM_CAP_RME(KVM_CAP_ARM_RME_CREATE_RD)"); } From patchwork Fri Jan 27 11:39:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49351 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp808479wrn; Fri, 27 Jan 2023 04:34:18 -0800 (PST) X-Google-Smtp-Source: AK7set/newgxU8slGEQA9K3dBvQb/qavrn4KsJNooWTVsexRtyMBDx3ckjr+LB27Jpf6G6eO2cK8 X-Received: by 2002:a17:90b:38ca:b0:229:ee6d:4178 with SMTP id nn10-20020a17090b38ca00b00229ee6d4178mr6354937pjb.38.1674822858049; Fri, 27 Jan 2023 04:34:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674822858; cv=none; d=google.com; s=arc-20160816; b=FOkonZeXwgqmDyy5aZsCkDV0eJql8fiYhdG6Ing0kiZfG7UFZdidg72xP9lS4xiFkK v6MBWV2sANhL8PYDvHPHB68jojk92RYSoHceaWT3gzpkoPHd1V4OgucZ3jKHkvRlsHag qPCaclI2byMeHTNfvP/+VfYGVL/I+fPFAmt2P2+dfLV42bYDzuCnF8DOMUroE8RfPmB1 MkjqmODeNpGXhPe3DLmfan9w1cQmHhTrmPvhHOEAm4W3k2G1ylt5o33dG99eE2aLh1b9 W7haKIFYc5ux6mr/wEejMD+da/hL0it1Hhumx399H0HS8uY1EFD+96CW2cCtbM5zyPZL QFAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=OlKyCiUBlVLKfaW9BUDrCJzCFpXiBMb5iaEca12x1Uo=; b=vCHZKRISPcQ7fEGN4dU467BEhfiwfrLws2eHlWS9cIaYhpPpaEi0fF48gQGs0un+SZ ZHwB2GBapXO0AwuEeqOt/5F8z1tg+ogNuXcNer6SMN7ZZKu9+rYDePIOpgyMC3HOTf9l ndDx8Et8050UI6NMjzJ9i91BpVX6A7Qz58OuHZcZslZ9DwUN5xFb63iFjusXWlUC7e8q Qo/C4uyeg4BYughhsBEmz8P4F9vAlxz5kqrRdt+u1w2dXpE7J9ONhudBcTawurR/jpjQ SgH/p6029/YMganiQsddh/672rCRpB0f5ajToNBKefUOn+fxwoH82XIHfDTRy1zgh/CX kFpA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i11-20020a63bf4b000000b004adff260cc0si3880900pgo.352.2023.01.27.04.34.05; Fri, 27 Jan 2023 04:34:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233446AbjA0MUC (ORCPT + 99 others); Fri, 27 Jan 2023 07:20:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233541AbjA0MT3 (ORCPT ); Fri, 27 Jan 2023 07:19:29 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 349088324C; Fri, 27 Jan 2023 04:16:08 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 95E9C175D; Fri, 27 Jan 2023 03:41:13 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 186843F64C; Fri, 27 Jan 2023 03:40:28 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 15/31] arm64: Add support for Realm Personalisation Value Date: Fri, 27 Jan 2023 11:39:16 +0000 Message-Id: <20230127113932.166089-16-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756179053200288796?= X-GMAIL-MSGID: =?utf-8?q?1756179053200288796?= Add option to specify Realm personalisation value Signed-off-by: Suzuki K Poulose --- arm/aarch64/include/kvm/kvm-config-arch.h | 6 +++++- arm/aarch64/kvm.c | 7 +++++++ arm/aarch64/realm.c | 23 +++++++++++++++++++++++ arm/include/arm-common/kvm-config-arch.h | 1 + 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/arm/aarch64/include/kvm/kvm-config-arch.h b/arm/aarch64/include/kvm/kvm-config-arch.h index b93999b6..f2e659ad 100644 --- a/arm/aarch64/include/kvm/kvm-config-arch.h +++ b/arm/aarch64/include/kvm/kvm-config-arch.h @@ -26,7 +26,11 @@ int vcpu_affinity_parser(const struct option *opt, const char *arg, int unset); "Create VM running in a realm using Arm RME"), \ OPT_STRING('\0', "measurement-algo", &(cfg)->measurement_algo, \ "sha256, sha512", \ - "Realm Measurement algorithm, default: sha256"), + "Realm Measurement algorithm, default: sha256"),\ + OPT_STRING('\0', "realm-pv", &(cfg)->realm_pv, \ + "personalisation value", \ + "Personalisation Value (only) for Realm VMs"), + #include "arm-common/kvm-config-arch.h" diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c index a5a98b2e..4798e359 100644 --- a/arm/aarch64/kvm.c +++ b/arm/aarch64/kvm.c @@ -56,6 +56,8 @@ static void validate_realm_cfg(struct kvm *kvm) if (!kvm->cfg.arch.is_realm) { if (kvm->cfg.arch.measurement_algo) die("--measurement-algo valid only with --realm"); + if (kvm->cfg.arch.realm_pv) + die("--realm-pv valid only with --realm"); return; } @@ -74,6 +76,11 @@ static void validate_realm_cfg(struct kvm *kvm) kvm->arch.measurement_algo = KVM_CAP_ARM_RME_MEASUREMENT_ALGO_SHA256; } + if (kvm->cfg.arch.realm_pv) { + if (strlen(kvm->cfg.arch.realm_pv) > KVM_CAP_ARM_RME_RPV_SIZE) + die("Invalid size for Realm Personalization Value\n"); + } + die("Realms not supported"); } diff --git a/arm/aarch64/realm.c b/arm/aarch64/realm.c index 31543e55..2e0be982 100644 --- a/arm/aarch64/realm.c +++ b/arm/aarch64/realm.c @@ -20,9 +20,32 @@ static void realm_configure_hash_algo(struct kvm *kvm) die_perror("KVM_CAP_RME(KVM_CAP_ARM_RME_CONFIG_REALM) hash_algo"); } +static void realm_configure_rpv(struct kvm *kvm) +{ + struct kvm_cap_arm_rme_config_item rpv_cfg = { + .cfg = KVM_CAP_ARM_RME_CFG_RPV, + }; + + struct kvm_enable_cap rme_config = { + .cap = KVM_CAP_ARM_RME, + .args[0] = KVM_CAP_ARM_RME_CONFIG_REALM, + .args[1] = (u64)&rpv_cfg, + }; + + if (!kvm->cfg.arch.realm_pv) + return; + + memset(&rpv_cfg.rpv, 0, sizeof(rpv_cfg.rpv)); + memcpy(&rpv_cfg.rpv, kvm->cfg.arch.realm_pv, strlen(kvm->cfg.arch.realm_pv)); + + if (ioctl(kvm->vm_fd, KVM_ENABLE_CAP, &rme_config) < 0) + die_perror("KVM_CAP_RME(KVM_CAP_ARM_RME_CONFIG_REALM) RPV"); +} + static void realm_configure_parameters(struct kvm *kvm) { realm_configure_hash_algo(kvm); + realm_configure_rpv(kvm); } void kvm_arm_realm_create_realm_descriptor(struct kvm *kvm) diff --git a/arm/include/arm-common/kvm-config-arch.h b/arm/include/arm-common/kvm-config-arch.h index a2faa3af..80a3b18e 100644 --- a/arm/include/arm-common/kvm-config-arch.h +++ b/arm/include/arm-common/kvm-config-arch.h @@ -7,6 +7,7 @@ struct kvm_config_arch { const char *dump_dtb_filename; const char *vcpu_affinity; const char *measurement_algo; + const char *realm_pv; unsigned int force_cntfrq; bool virtio_trans_pci; bool aarch32_guest; From patchwork Fri Jan 27 11:39:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49280 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp787450wrn; Fri, 27 Jan 2023 03:44:29 -0800 (PST) X-Google-Smtp-Source: AK7set8JOkkFjGHl3z8J9xbZITXA21OB/2QSaravydyWdIerul6PrQB0t7rCtzC0HO8fJb+gPv4O X-Received: by 2002:a17:90a:1ca:b0:22c:491b:2cd7 with SMTP id 10-20020a17090a01ca00b0022c491b2cd7mr2500959pjd.34.1674819869550; Fri, 27 Jan 2023 03:44:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674819869; cv=none; d=google.com; s=arc-20160816; b=vf/pb7lkbU0NEgZNtLrvCJrrZPGCLrQzwfQjepKllaowiEB2066bbX+b9htqBDQM6i ceurE6cLngIiLUsE8uy2Ny4SWCJ2cR3IjJgddADIo1a5cOc6KbEtGA3b9879/57wQqr9 OdwSYo5vbbQDXXwmJvu7IQXMGwNMJrx3aMzyNrdtZXGwmlbyfp8V5HnMNKaeUu3phZ6P PcrXN8Nu774zOPBhcJOraWCBHuxo/ccKgeV79niNQ0xbdHWyJFo0h+YXBym1pnd62yfN gf31CZpMB3trJ/Dcpiw8iZKMKYpP1h6abLNx5/jkehlqRgUc2jOjvwLDJlY1L/awleN3 FMsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=0ARYFgRneShivPkrtFFWMnz/Btm+510ZFPhm33jy+fM=; b=il6vceXXp/jlACHgFVDufhiQv/apyRMgUf++3MoDFUmUsb3asiPJkTL1DuuCVBr2/f DDLsGz2NR0HsFQvYub8IDgrx5LuxYjTb5X9rDNJ+2n4S1grrOqckz/nhNgx98QwFG9X3 yVaMYOSPlHRxtJIK06d9qsGPtDhI6XQaq5XMfsiwJI9usJRxIBRYqZYvDlIiQSdKtaib 7y04Xbv+xz+sIiyGfGKVlYgXZZAuecGp3ai6WI9W9uNbwElanz1c3OV9Csstzp+VzZcl cvUBgU2bkKazNpySDlp4ewICTvp11cZ6/bNkURESYDUz7zbDPpCwkDsq/wzpgaJz9dFV savg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p28-20020a637f5c000000b004e0d688fb84si805605pgn.847.2023.01.27.03.44.16; Fri, 27 Jan 2023 03:44:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231996AbjA0LmA (ORCPT + 99 others); Fri, 27 Jan 2023 06:42:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232834AbjA0Ll2 (ORCPT ); Fri, 27 Jan 2023 06:41:28 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E971C78ACD; Fri, 27 Jan 2023 03:41:05 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6EDC71763; Fri, 27 Jan 2023 03:41:16 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E5B2D3F64C; Fri, 27 Jan 2023 03:40:31 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 16/31] arm64: Add support for specifying the SVE vector length for Realm Date: Fri, 27 Jan 2023 11:39:17 +0000 Message-Id: <20230127113932.166089-17-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756175919583242915?= X-GMAIL-MSGID: =?utf-8?q?1756175919583242915?= Add option to specify SVE vector length for realms. Signed-off-by: Suzuki K Poulose --- arm/aarch64/include/kvm/kvm-config-arch.h | 6 ++++-- arm/aarch64/kvm.c | 23 +++++++++++++++++++++++ arm/aarch64/realm.c | 21 +++++++++++++++++++++ arm/include/arm-common/kvm-arch.h | 1 + arm/include/arm-common/kvm-config-arch.h | 1 + 5 files changed, 50 insertions(+), 2 deletions(-) diff --git a/arm/aarch64/include/kvm/kvm-config-arch.h b/arm/aarch64/include/kvm/kvm-config-arch.h index f2e659ad..0f42c2c2 100644 --- a/arm/aarch64/include/kvm/kvm-config-arch.h +++ b/arm/aarch64/include/kvm/kvm-config-arch.h @@ -29,8 +29,10 @@ int vcpu_affinity_parser(const struct option *opt, const char *arg, int unset); "Realm Measurement algorithm, default: sha256"),\ OPT_STRING('\0', "realm-pv", &(cfg)->realm_pv, \ "personalisation value", \ - "Personalisation Value (only) for Realm VMs"), - + "Personalisation Value (only) for Realm VMs"), \ + OPT_U64('\0', "sve-vl", &(cfg)->sve_vl, \ + "SVE Vector Length the VM" \ + "(only supported for Realms)"), #include "arm-common/kvm-config-arch.h" diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c index 4798e359..fca1410b 100644 --- a/arm/aarch64/kvm.c +++ b/arm/aarch64/kvm.c @@ -51,13 +51,19 @@ static void validate_mem_cfg(struct kvm *kvm) } } +#define SVE_VL_ALIGN 128 + static void validate_realm_cfg(struct kvm *kvm) { + u32 sve_vl; + if (!kvm->cfg.arch.is_realm) { if (kvm->cfg.arch.measurement_algo) die("--measurement-algo valid only with --realm"); if (kvm->cfg.arch.realm_pv) die("--realm-pv valid only with --realm"); + if (kvm->cfg.arch.sve_vl) + die("--sve-vl valid only with --realm"); return; } @@ -76,6 +82,23 @@ static void validate_realm_cfg(struct kvm *kvm) kvm->arch.measurement_algo = KVM_CAP_ARM_RME_MEASUREMENT_ALGO_SHA256; } + sve_vl = kvm->cfg.arch.sve_vl; + if (sve_vl) { + if (kvm->cfg.arch.disable_sve) + die("SVE VL requested when SVE is disabled"); + if (!IS_ALIGNED(sve_vl, SVE_VL_ALIGN)) + die("SVE VL is not aligned to %dbit\n", SVE_VL_ALIGN); + kvm->arch.sve_vq = (sve_vl / SVE_VL_ALIGN) - 1; + } else { + /* + * Disable SVE for Realms, if a VL is not requested. + * The SVE VL will be measured as part of the parameter + * and we do not want to add an unknown entity to the + * measurement. + */ + kvm->cfg.arch.disable_sve = true; + } + if (kvm->cfg.arch.realm_pv) { if (strlen(kvm->cfg.arch.realm_pv) > KVM_CAP_ARM_RME_RPV_SIZE) die("Invalid size for Realm Personalization Value\n"); diff --git a/arm/aarch64/realm.c b/arm/aarch64/realm.c index 2e0be982..fc7f8d6a 100644 --- a/arm/aarch64/realm.c +++ b/arm/aarch64/realm.c @@ -42,10 +42,31 @@ static void realm_configure_rpv(struct kvm *kvm) die_perror("KVM_CAP_RME(KVM_CAP_ARM_RME_CONFIG_REALM) RPV"); } +static void realm_configure_sve(struct kvm *kvm) +{ + struct kvm_cap_arm_rme_config_item sve_cfg = { + .cfg = KVM_CAP_ARM_RME_CFG_SVE, + .sve_vq = kvm->arch.sve_vq, + }; + + struct kvm_enable_cap rme_config = { + .cap = KVM_CAP_ARM_RME, + .args[0] = KVM_CAP_ARM_RME_CONFIG_REALM, + .args[1] = (u64)&sve_cfg, + }; + + if (kvm->cfg.arch.disable_sve) + return; + + if (ioctl(kvm->vm_fd, KVM_ENABLE_CAP, &rme_config) < 0) + die_perror("KVM_CAP_RME(KVM_CAP_ARM_RME_CONFIG_REALM) SVE"); +} + static void realm_configure_parameters(struct kvm *kvm) { realm_configure_hash_algo(kvm); realm_configure_rpv(kvm); + realm_configure_sve(kvm); } void kvm_arm_realm_create_realm_descriptor(struct kvm *kvm) diff --git a/arm/include/arm-common/kvm-arch.h b/arm/include/arm-common/kvm-arch.h index 68224b1c..41b31f11 100644 --- a/arm/include/arm-common/kvm-arch.h +++ b/arm/include/arm-common/kvm-arch.h @@ -114,6 +114,7 @@ struct kvm_arch { cpu_set_t *vcpu_affinity_cpuset; u64 measurement_algo; + u64 sve_vq; }; #endif /* ARM_COMMON__KVM_ARCH_H */ diff --git a/arm/include/arm-common/kvm-config-arch.h b/arm/include/arm-common/kvm-config-arch.h index 80a3b18e..d923fd9e 100644 --- a/arm/include/arm-common/kvm-config-arch.h +++ b/arm/include/arm-common/kvm-config-arch.h @@ -19,6 +19,7 @@ struct kvm_config_arch { u64 fw_addr; bool no_pvtime; bool disable_sve; + u64 sve_vl; }; int irqchip_parser(const struct option *opt, const char *arg, int unset); From patchwork Fri Jan 27 11:39:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49281 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp787460wrn; Fri, 27 Jan 2023 03:44:31 -0800 (PST) X-Google-Smtp-Source: AMrXdXsDMwgao6xAXDPxXEExzWpX5N/bAew5HFqheLqHmW02lQSLTT+DVagph+fdXMZLfWOJqrUG X-Received: by 2002:a05:6a20:cf44:b0:b6:d25:9a8b with SMTP id hz4-20020a056a20cf4400b000b60d259a8bmr32717538pzb.28.1674819871191; Fri, 27 Jan 2023 03:44:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674819871; cv=none; d=google.com; s=arc-20160816; b=GHaIKNL2X/QYMgOMmFjz7xH5B0m+VLZBWudeMG7bEMA343KYXPvX9scblK+WV7/cla /n7+hvvf84Vwup2ytZfBfNpeHyb9OisBhxiGbtc3miyHX7VKCAwVwNRUg250vFwuG/+k Fen2JUJjLBxIdGBGs+idlRFiwXvcpFf/95voJBmXvvuNfNpX+c3fCTV8g4hrmCPGAwW4 1G3mec1KREOu/Ih/utbaXYr1XOTxN4aeeUx2L4bw6gyYPX/GhB2CQ2RL3t60wFFpAXuL DBjFNQvrqNlFpCKmI7p+Qwo5trwVLg+45IUeD4sU2tWqLmaHUG6Jazhk3PJX/pjGyM1h D1oA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=7ywYRI9ZQK1lftGl5WrxVvq7URRwCdPtki45hAjXcBA=; b=ZWKMq3x0dh7bM/rPDURO5YDV+wqYCtWOsKzQW5YYC3WaEDvR7UHOKLKeyImCsKoEhb 8Jwbw+ucLtvAH7io2qRKgXyI3IZZgvrhCBW8eKM/lVYdhOdBuBjP3jiU2wzSueYH++9+ q9BHIyM88yKwxtO1Kv6tcMo+CSkygbqnQsm0lOnT6DnEdRkZmEZ6wd6I8VuyJyrOuJgt TBredmgHbLQ+iKhGz3Uy3FHdsukkSPPDFa6u1N4kJwTFoYmA27idMQ++NCtXQb597zsB fOlKnwD6GQOEpRtb+jU0yEhk3prffn8Xlo8aBbHZdH2Qm0fiBw7kX+vmoTxYz7/W/iCz th4g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b12-20020a63930c000000b004da46ea2717si4028643pge.35.2023.01.27.03.44.18; Fri, 27 Jan 2023 03:44:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233945AbjA0LmD (ORCPT + 99 others); Fri, 27 Jan 2023 06:42:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233513AbjA0Ll2 (ORCPT ); Fri, 27 Jan 2023 06:41:28 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2D2FF78AEB; Fri, 27 Jan 2023 03:41:06 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 480471576; Fri, 27 Jan 2023 03:41:19 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id BEBA93F64C; Fri, 27 Jan 2023 03:40:34 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 17/31] arm: Add kernel size to VM context Date: Fri, 27 Jan 2023 11:39:18 +0000 Message-Id: <20230127113932.166089-18-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756175921166978141?= X-GMAIL-MSGID: =?utf-8?q?1756175921166978141?= From: Alexandru Elisei Add the kernel image size to the VM context, as we are going to use it later. This matches what we already do with the initrd. Signed-off-by: Alexandru Elisei [Fix kernel size printed in debug messages] Signed-off-by: Suzuki K Poulose --- arm/include/arm-common/kvm-arch.h | 1 + arm/kvm.c | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/arm/include/arm-common/kvm-arch.h b/arm/include/arm-common/kvm-arch.h index 41b31f11..b5a4b851 100644 --- a/arm/include/arm-common/kvm-arch.h +++ b/arm/include/arm-common/kvm-arch.h @@ -108,6 +108,7 @@ struct kvm_arch { */ u64 memory_guest_start; u64 kern_guest_start; + u64 kern_size; u64 initrd_guest_start; u64 initrd_size; u64 dtb_guest_start; diff --git a/arm/kvm.c b/arm/kvm.c index 2510a322..acb627b2 100644 --- a/arm/kvm.c +++ b/arm/kvm.c @@ -153,7 +153,6 @@ bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd, limit = kvm->ram_start + min(kvm->ram_size, (u64)SZ_256M) - 1; pos = kvm->ram_start + kvm__arch_get_kern_offset(kvm, fd_kernel); - kvm->arch.kern_guest_start = host_to_guest_flat(kvm, pos); file_size = read_file(fd_kernel, pos, limit - pos); if (file_size < 0) { if (errno == ENOMEM) @@ -161,9 +160,12 @@ bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd, die_perror("kernel read"); } + + kvm->arch.kern_guest_start = host_to_guest_flat(kvm, pos); + kvm->arch.kern_size = file_size; kernel_end = pos + file_size; - pr_debug("Loaded kernel to 0x%llx (%zd bytes)", - kvm->arch.kern_guest_start, file_size); + pr_debug("Loaded kernel to 0x%llx (%llu bytes)", + kvm->arch.kern_guest_start, kvm->arch.kern_size); /* * Now load backwards from the end of memory so the kernel From patchwork Fri Jan 27 11:39:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49350 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp808318wrn; Fri, 27 Jan 2023 04:33:57 -0800 (PST) X-Google-Smtp-Source: AMrXdXt+OhJwGCIjO51Pi2I94ZBo9taGeXYFEmvZWzGPhmfs4gu+iB5H4sA9tq+ivg8+pl32OdY4 X-Received: by 2002:a17:902:b20f:b0:194:a268:1201 with SMTP id t15-20020a170902b20f00b00194a2681201mr35357524plr.43.1674822837288; Fri, 27 Jan 2023 04:33:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674822837; cv=none; d=google.com; s=arc-20160816; b=fpgF5rCPQVftWRouoH6v+3ZOpr7T+Pr3HFsZXBlrl6hhE94EK+PLHnYGa1t3ipCbF7 w+mQyJ7S29JZp8CNAu6Jsz1bpxAajVPzIeHPH50JIMv96Ci0QWf7g4hwtCkU38ZvHGVg qnVnQTyWihDRsP6CeTwaI41v2gfknlaZujvOjYIzViJAh96ezB8fNkMHjTbhyeMTlXpJ 336PhE3nDjvhqu102uwD+jYj2UBdtRQZHogM44X2gICxFjzZcHVl7Y9IH+1Cv41JQlLF CJusElED8sbRGsENxyCEo4I11FPUkG2Th8rVGDQnipLWKm1WegYIZ0OwgMsAu0GzDhi3 kCpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=jt2EztHJM3wfcHzDLQeRkxL8Ie1Rawu69I3AWZzjID4=; b=iuTSamHAlxUSia/sERO4UoJFzhAxVdfpgeWmjnb+afUjJTLeoOh/fJ1i6Ci51Nl29c Xm2ii3wrIEdtQaUeb6qpAG9R3iiBPzhXIzH+tTyz4MR/d2ytYrIcst2IpMN0/RPQ+nDY kx/Ecw5zB8ocITzkP29TlKQ686MA0yXLse9LT7PwtWzt7HWHv1NUO2866mlbrSmhtHxJ /1NYba+5aHpb2IPhQf/Lw7k/k+PQ6a/yd2z2sCCe0NqsP3h+3Nxx+5TieF1C/GWdEEh3 cXlOaPel0IO8usQ5n0txhPGtRSrh7T1hEJbiPW8iYpWVa+mq55v1NDYBELAMMDaB9fm+ J7kw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l5-20020a170902f68500b0019482b41aa4si5081239plg.174.2023.01.27.04.33.44; Fri, 27 Jan 2023 04:33:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231916AbjA0MUA (ORCPT + 99 others); Fri, 27 Jan 2023 07:20:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231909AbjA0MTk (ORCPT ); Fri, 27 Jan 2023 07:19:40 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 379C684976; Fri, 27 Jan 2023 04:16:14 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2199715DB; Fri, 27 Jan 2023 03:41:22 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 980F33F64C; Fri, 27 Jan 2023 03:40:37 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 18/31] arm64: Populate initial realm contents Date: Fri, 27 Jan 2023 11:39:19 +0000 Message-Id: <20230127113932.166089-19-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756179031532931225?= X-GMAIL-MSGID: =?utf-8?q?1756179031532931225?= From: Alexandru Elisei Populate the realm memory with the initial contents, which include the device tree blob, the kernel image, and initrd, if specified, or the firmware image. Populating an image in the realm involves two steps: a) Mark the IPA area as RAM - INIT_IPA_REALM b) Load the contents into the IPA - POPULATE_REALM Wherever we know the actual size of an image in memory, we make sure the "memory area" is initialised to RAM. e.g., Linux kernel image size from the header which includes the bss etc. The "file size" on disk for the Linux image is much smaller. We mark the region of size Image.header.size as RAM (a), from the kernel load address. And load the Image file into the memory (b) above. At the moment we only detect the Arm64 Linux Image header format. Since we're already touching the code that copies the initrd in guest memory, let's do a bit of cleaning and remove a useless local variable. Signed-off-by: Alexandru Elisei [ Make sure the Linux kernel image area is marked as RAM ] Signed-off-by: Suzuki K Poulose --- arm/aarch32/include/asm/realm.h | 3 + arm/aarch64/include/asm/realm.h | 3 + arm/aarch64/realm.c | 112 ++++++++++++++++++++++++++++++++ arm/fdt.c | 6 ++ arm/kvm.c | 20 ++++-- include/linux/kernel.h | 1 + 6 files changed, 140 insertions(+), 5 deletions(-) diff --git a/arm/aarch32/include/asm/realm.h b/arm/aarch32/include/asm/realm.h index 5aca6cca..fcff0e55 100644 --- a/arm/aarch32/include/asm/realm.h +++ b/arm/aarch32/include/asm/realm.h @@ -6,5 +6,8 @@ #include "kvm/kvm.h" static inline void kvm_arm_realm_create_realm_descriptor(struct kvm *kvm) {} +static inline void kvm_arm_realm_populate_kernel(struct kvm *kvm) {} +static inline void kvm_arm_realm_populate_initrd(struct kvm *kvm) {} +static inline void kvm_arm_realm_populate_dtb(struct kvm *kvm) {} #endif /* ! __ASM_REALM_H */ diff --git a/arm/aarch64/include/asm/realm.h b/arm/aarch64/include/asm/realm.h index e176f15f..6e760ac9 100644 --- a/arm/aarch64/include/asm/realm.h +++ b/arm/aarch64/include/asm/realm.h @@ -6,5 +6,8 @@ #include "kvm/kvm.h" void kvm_arm_realm_create_realm_descriptor(struct kvm *kvm); +void kvm_arm_realm_populate_kernel(struct kvm *kvm); +void kvm_arm_realm_populate_initrd(struct kvm *kvm); +void kvm_arm_realm_populate_dtb(struct kvm *kvm); #endif /* ! __ASM_REALM_H */ diff --git a/arm/aarch64/realm.c b/arm/aarch64/realm.c index fc7f8d6a..eddccece 100644 --- a/arm/aarch64/realm.c +++ b/arm/aarch64/realm.c @@ -1,5 +1,7 @@ #include "kvm/kvm.h" +#include +#include #include @@ -80,3 +82,113 @@ void kvm_arm_realm_create_realm_descriptor(struct kvm *kvm) if (ioctl(kvm->vm_fd, KVM_ENABLE_CAP, &rme_create_rd) < 0) die_perror("KVM_CAP_RME(KVM_CAP_ARM_RME_CREATE_RD)"); } + +static void realm_init_ipa_range(struct kvm *kvm, u64 start, u64 size) +{ + struct kvm_cap_arm_rme_init_ipa_args init_ipa_args = { + .init_ipa_base = start, + .init_ipa_size = size + }; + struct kvm_enable_cap rme_init_ipa_realm = { + .cap = KVM_CAP_ARM_RME, + .args[0] = KVM_CAP_ARM_RME_INIT_IPA_REALM, + .args[1] = (u64)&init_ipa_args + }; + + if (ioctl(kvm->vm_fd, KVM_ENABLE_CAP, &rme_init_ipa_realm) < 0) + die("unable to intialise IPA range for Realm %llx - %llx (size %llu)", + start, start + size, size); + +} + +static void __realm_populate(struct kvm *kvm, u64 start, u64 size) +{ + struct kvm_cap_arm_rme_populate_realm_args populate_args = { + .populate_ipa_base = start, + .populate_ipa_size = size + }; + struct kvm_enable_cap rme_populate_realm = { + .cap = KVM_CAP_ARM_RME, + .args[0] = KVM_CAP_ARM_RME_POPULATE_REALM, + .args[1] = (u64)&populate_args + }; + + if (ioctl(kvm->vm_fd, KVM_ENABLE_CAP, &rme_populate_realm) < 0) + die("unable to populate Realm memory %llx - %llx (size %llu)", + start, start + size, size); +} + +static void realm_populate(struct kvm *kvm, u64 start, u64 size) +{ + realm_init_ipa_range(kvm, start, size); + __realm_populate(kvm, start, size); +} + +static bool is_arm64_linux_kernel_image(void *header) +{ + struct arm64_image_header *hdr = header; + + return memcmp(&hdr->magic, ARM64_IMAGE_MAGIC, sizeof(hdr->magic)) == 0; +} + +static ssize_t arm64_linux_kernel_image_size(void *header) +{ + struct arm64_image_header *hdr = header; + + if (is_arm64_linux_kernel_image(header)) + return le64_to_cpu(hdr->image_size); + die("Not arm64 Linux kernel Image"); +} + +void kvm_arm_realm_populate_kernel(struct kvm *kvm) +{ + u64 start, end, mem_size; + void *header = guest_flat_to_host(kvm, kvm->arch.kern_guest_start); + + start = ALIGN_DOWN(kvm->arch.kern_guest_start, SZ_4K); + end = ALIGN(kvm->arch.kern_guest_start + kvm->arch.kern_size, SZ_4K); + + if (is_arm64_linux_kernel_image(header)) + mem_size = arm64_linux_kernel_image_size(header); + else + mem_size = end - start; + + realm_init_ipa_range(kvm, start, mem_size); + __realm_populate(kvm, start, end - start); +} + +void kvm_arm_realm_populate_initrd(struct kvm *kvm) +{ + u64 kernel_end, start, end; + + kernel_end = ALIGN(kvm->arch.kern_guest_start + kvm->arch.kern_size, SZ_4K); + start = ALIGN_DOWN(kvm->arch.initrd_guest_start, SZ_4K); + /* + * Because we align the initrd to 4 bytes, it is theoretically possible + * for the start of the initrd to overlap with the same page where the + * kernel ends. + */ + if (start < kernel_end) + start = kernel_end; + end = ALIGN(kvm->arch.initrd_guest_start + kvm->arch.initrd_size, SZ_4K); + if (end > start) + realm_populate(kvm, start, end - start); +} + +void kvm_arm_realm_populate_dtb(struct kvm *kvm) +{ + u64 initrd_end, start, end; + + initrd_end = ALIGN(kvm->arch.initrd_guest_start + kvm->arch.initrd_size, SZ_4K); + start = ALIGN_DOWN(kvm->arch.dtb_guest_start, SZ_4K); + /* + * Same situation as with the initrd, but now it is the DTB which is + * overlapping with the last page of the initrd, because the initrd is + * populated first. + */ + if (start < initrd_end) + start = initrd_end; + end = ALIGN(kvm->arch.dtb_guest_start + FDT_MAX_SIZE, SZ_4K); + if (end > start) + realm_populate(kvm, start, end - start); +} diff --git a/arm/fdt.c b/arm/fdt.c index 286ccadf..762a604d 100644 --- a/arm/fdt.c +++ b/arm/fdt.c @@ -7,6 +7,8 @@ #include "arm-common/gic.h" #include "arm-common/pci.h" +#include + #include #include @@ -231,6 +233,10 @@ static int setup_fdt(struct kvm *kvm) if (kvm->cfg.arch.dump_dtb_filename) dump_fdt(kvm->cfg.arch.dump_dtb_filename, fdt_dest); + + if (kvm->cfg.arch.is_realm) + kvm_arm_realm_populate_dtb(kvm); + return 0; } late_init(setup_fdt); diff --git a/arm/kvm.c b/arm/kvm.c index acb627b2..57c5b5f7 100644 --- a/arm/kvm.c +++ b/arm/kvm.c @@ -6,6 +6,7 @@ #include "kvm/fdt.h" #include "arm-common/gic.h" +#include #include @@ -167,6 +168,9 @@ bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd, pr_debug("Loaded kernel to 0x%llx (%llu bytes)", kvm->arch.kern_guest_start, kvm->arch.kern_size); + if (kvm->cfg.arch.is_realm) + kvm_arm_realm_populate_kernel(kvm); + /* * Now load backwards from the end of memory so the kernel * decompressor has plenty of space to work with. First up is @@ -188,7 +192,6 @@ bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd, /* ... and finally the initrd, if we have one. */ if (fd_initrd != -1) { struct stat sb; - unsigned long initrd_start; if (fstat(fd_initrd, &sb)) die_perror("fstat"); @@ -199,7 +202,6 @@ bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd, if (pos < kernel_end) die("initrd overlaps with kernel image."); - initrd_start = guest_addr; file_size = read_file(fd_initrd, pos, limit - pos); if (file_size == -1) { if (errno == ENOMEM) @@ -208,11 +210,13 @@ bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd, die_perror("initrd read"); } - kvm->arch.initrd_guest_start = initrd_start; + kvm->arch.initrd_guest_start = guest_addr; kvm->arch.initrd_size = file_size; pr_debug("Loaded initrd to 0x%llx (%llu bytes)", - kvm->arch.initrd_guest_start, - kvm->arch.initrd_size); + kvm->arch.initrd_guest_start, kvm->arch.initrd_size); + + if (kvm->cfg.arch.is_realm) + kvm_arm_realm_populate_initrd(kvm); } else { kvm->arch.initrd_size = 0; } @@ -269,6 +273,8 @@ bool kvm__load_firmware(struct kvm *kvm, const char *firmware_filename) /* Kernel isn't loaded by kvm, point start address to firmware */ kvm->arch.kern_guest_start = fw_addr; + kvm->arch.kern_size = fw_sz; + pr_debug("Loaded firmware to 0x%llx (%zd bytes)", kvm->arch.kern_guest_start, fw_sz); @@ -283,6 +289,10 @@ bool kvm__load_firmware(struct kvm *kvm, const char *firmware_filename) kvm->arch.dtb_guest_start, kvm->arch.dtb_guest_start + FDT_MAX_SIZE); + if (kvm->cfg.arch.is_realm) + /* We hijack the kernel fields to describe the firmware. */ + kvm_arm_realm_populate_kernel(kvm); + return true; } diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 6c22f1c0..25f19c20 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -9,6 +9,7 @@ #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) +#define ALIGN_DOWN(x,a) __ALIGN_MASK(x - (typeof(x))((a) - 1),(typeof(x))(a)-1) #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1) #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) #define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0) From patchwork Fri Jan 27 11:39:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49288 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp787673wrn; Fri, 27 Jan 2023 03:45:06 -0800 (PST) X-Google-Smtp-Source: AK7set9kWONbuPUOmo5Mfp1Z/j6dc4FUe5A2xOagJBkHRswjR/3OcgevRWKysuuVhEIScIGiDxWZ X-Received: by 2002:a17:90b:3a8a:b0:22c:4491:cbe4 with SMTP id om10-20020a17090b3a8a00b0022c4491cbe4mr3331001pjb.2.1674819905932; Fri, 27 Jan 2023 03:45:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674819905; cv=none; d=google.com; s=arc-20160816; b=HLU3fgcA+2q3Q4IMxiN+FBxnnEiLOOESHsE2TYI3FWuTgpVuVtxA041SECrXpwSUCq kNbSXdXoRhQD5Q8xGP7Y4zRdkwI9hsbS67zc0bQ3B9kMZ1cpeSUgGV20XTvBTTBbuy/g FMs7epANbixxL4r8HbOzl+axqIWArSRs6IA7nK3Ba0F4dhGVmddWMFtfC3Y2V4AKhWlG QVKCnB8aV11xGke9128GlP173EEz3heuWWZDD/EJg9S7EaSJmZJcY4/0J26TDqlpxYTw Nhr8kWo6/LMbHzNQykB2BXMWUxGd/yCPsG62xb7wzP5hCp8cY3QYiTwX0O5MvJngwI+Y zRHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Di89hcNPdPsHOLsUAMoHYLcLaeMPMiusS1vw2ja12hw=; b=ifjeHr3cNENLlMsNA8OTjY1CDxMl18ZWnsUuaVg3ue+yToESlY9zgRr8G0mjm1G6WB x+oUXFtzDAi5sAz3h3KvW2NEzyRQEoVnsu+8yvI2nPFAIKgeN21kgHGiYvaOUbXlzOmH PuVxp/KPVBWMObLs5L7WLGac434TdFZWWC3K1N3QmYQTmL2vygc9ZeTfSy/j/cx6UqSg 4XQlT3EBNzyJETAUCQJ/wJdHooP7i45fAEPq9GM1fxeDfmFLLpqKD+0Jx/B6HfZ97Qej sOpIxTq/ftsa3cTPf0sCzYg531EimXSRhqMhnrnI+kgRDPhg90vw0fNe0UGzJ4R4ZDsC +0zA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j132-20020a636e8a000000b004ad1e917143si4333577pgc.386.2023.01.27.03.44.53; Fri, 27 Jan 2023 03:45:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233182AbjA0LmJ (ORCPT + 99 others); Fri, 27 Jan 2023 06:42:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232155AbjA0Llf (ORCPT ); Fri, 27 Jan 2023 06:41:35 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 72D5D78AFC; Fri, 27 Jan 2023 03:41:06 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EF4CE2B; Fri, 27 Jan 2023 03:41:24 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 713E03F64C; Fri, 27 Jan 2023 03:40:40 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 19/31] arm64: Don't try to set PSTATE for VCPUs belonging to a realm Date: Fri, 27 Jan 2023 11:39:20 +0000 Message-Id: <20230127113932.166089-20-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756175957623114748?= X-GMAIL-MSGID: =?utf-8?q?1756175957623114748?= From: Christoffer Dall RME doesn't allow setting the PSTATE but resets it to an architectural value, and KVM also does not allow setting this register from user space, so stop trying to do that. Signed-off-by: Christoffer Dall Signed-off-by: Alexandru Elisei Signed-off-by: Suzuki K Poulose --- arm/aarch64/kvm-cpu.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/arm/aarch64/kvm-cpu.c b/arm/aarch64/kvm-cpu.c index e7649239..37f9aa9d 100644 --- a/arm/aarch64/kvm-cpu.c +++ b/arm/aarch64/kvm-cpu.c @@ -92,11 +92,13 @@ static void reset_vcpu_aarch64(struct kvm_cpu *vcpu) reg.addr = (u64)&data; - /* pstate = all interrupts masked */ - data = PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT | PSR_MODE_EL1h; - reg.id = ARM64_CORE_REG(regs.pstate); - if (ioctl(vcpu->vcpu_fd, KVM_SET_ONE_REG, ®) < 0) - die_perror("KVM_SET_ONE_REG failed (spsr[EL1])"); + if (!kvm->cfg.arch.is_realm) { + /* pstate = all interrupts masked */ + data = PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT | PSR_MODE_EL1h; + reg.id = ARM64_CORE_REG(regs.pstate); + if (ioctl(vcpu->vcpu_fd, KVM_SET_ONE_REG, ®) < 0) + die_perror("KVM_SET_ONE_REG failed (PSTATE)"); + } /* x1...x3 = 0 */ data = 0; From patchwork Fri Jan 27 11:39:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49352 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp808483wrn; Fri, 27 Jan 2023 04:34:18 -0800 (PST) X-Google-Smtp-Source: AMrXdXvIaB4PuKGfBsqIlaSjlR/7jZ7DN7jLGV3MweGGnO0vcxys5hs2Ly44uobZ+smMzJe0ebJV X-Received: by 2002:a17:902:b613:b0:194:457d:6dca with SMTP id b19-20020a170902b61300b00194457d6dcamr36048491pls.44.1674822858524; Fri, 27 Jan 2023 04:34:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674822858; cv=none; d=google.com; s=arc-20160816; b=gTmvT7CfMp2I/S/KV7xn0/IGj23gXAjN4CPzaYSaKv91WCctA79n3tUn+bacG66i3T pTWnn3Xw1VwVR63x1TbCHcLU041os47kxttcGB7K+ZkZxtJ+IYY8C+OvVnq7fVV35e+o cwYwKZoPb1bJ3mjWd0movLxq8KY3w7CEqYY8BjDOmCechbPomf4IKabbi0j3EAuo6fNQ aCTM7NzB8LVa3QgzW9t7pqDO+DE93pzZa2CdV4I/vOfH6L5EJA881AXK+1Fklp42t9Cq c8gPqREbKgWICLkd5GZbySNJ/AGon1M6HE0y9mXyOdEu7Lvq9VWbRzNxaain0L3T20UY hCDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=FNDxVN0vwSE1oTFDyBpw5EyJz5I6jBq/lbsd6C1JGaI=; b=d0NpVUpjxJFh7ZGOH2b4o9+DpIp23jIBiOoBsF6jZ9us45uF2r1qLqbuwuIluNocE1 dQ6KEbJwSDa9t+xmpN1V/oDtq3Tj9pIhlCb/OiSw030LhGmbqYAEmzJUhj6mtlKnI3y0 I7RuhXUk1n8pIzlVThVNvsTbdXKZikCpinlKy9bAEnUiTy81e2iv0NVGa+4VELvLXvcH hepDGTYP+LTFCvK7snvi0vl8OV6bED0wC+HU+p9d2FpjhmmL1qckGQvM4cfsTz2y5Mkx YEow3RFtqkDLdN5hMZs3/1d7AmdkItg9pT5sCMTBWxAaebFEN/4Xy2hcBVIAPd4TZtVS J54w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n12-20020a1709026a8c00b00194c49857acsi4277122plk.226.2023.01.27.04.34.06; Fri, 27 Jan 2023 04:34:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233784AbjA0MUE (ORCPT + 99 others); Fri, 27 Jan 2023 07:20:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234012AbjA0MT3 (ORCPT ); Fri, 27 Jan 2023 07:19:29 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 387E783251; Fri, 27 Jan 2023 04:16:08 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D149115BF; Fri, 27 Jan 2023 03:41:27 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 4AF653F64C; Fri, 27 Jan 2023 03:40:43 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 20/31] arm64: Finalize realm VCPU after reset Date: Fri, 27 Jan 2023 11:39:21 +0000 Message-Id: <20230127113932.166089-21-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756179053494333644?= X-GMAIL-MSGID: =?utf-8?q?1756179053494333644?= From: Alexandru Elisei In order to run a VCPU belonging to a realm, that VCPU must be in the finalized state. Finalize the CPU after reset, since kvmtool won't be touching the VCPU state afterwards. Signed-off-by: Alexandru Elisei Signed-off-by: Suzuki K Poulose --- arm/aarch64/kvm-cpu.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arm/aarch64/kvm-cpu.c b/arm/aarch64/kvm-cpu.c index 37f9aa9d..24e570c4 100644 --- a/arm/aarch64/kvm-cpu.c +++ b/arm/aarch64/kvm-cpu.c @@ -128,6 +128,13 @@ static void reset_vcpu_aarch64(struct kvm_cpu *vcpu) if (ioctl(vcpu->vcpu_fd, KVM_SET_ONE_REG, ®) < 0) die_perror("KVM_SET_ONE_REG failed (pc)"); } + + if (kvm->cfg.arch.is_realm) { + int feature = KVM_ARM_VCPU_REC; + + if (ioctl(vcpu->vcpu_fd, KVM_ARM_VCPU_FINALIZE, &feature) < 0) + die_perror("KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_REC)"); + } } void kvm_cpu__select_features(struct kvm *kvm, struct kvm_vcpu_init *init) From patchwork Fri Jan 27 11:39:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49346 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp804564wrn; Fri, 27 Jan 2023 04:25:15 -0800 (PST) X-Google-Smtp-Source: AMrXdXt3KC7c/LqKgddg1/XPLnp9/ENKUdtUFxMwYvXfBDF4Xsdb8Lno95oM099vUHDk2jiewju9 X-Received: by 2002:a05:6402:5110:b0:499:8849:5fb3 with SMTP id m16-20020a056402511000b0049988495fb3mr53045827edd.31.1674822314766; Fri, 27 Jan 2023 04:25:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674822314; cv=none; d=google.com; s=arc-20160816; b=o1KmB/cmkm4X7zA3MuGpDKUT2WI6H6aOFepw158celdYuwzUhgenfhcJXbTZ2L0Uw0 Lv6Uwc+c7QcZbZ3sK2k9f/IuMgZpPD/mJ3CEYFoOx6ANfbl2wlrlvvmcN851R1Csygj+ 1zcM9QCqw7RIApmZZpFI/emrZSSf7GQ/PYrHOd8TMKVrjogWw19RaEnruqTJPsXskkmY vdKkPSV5jBxk0cKaC4biWg+C0zhkzYg3cMdu8Txzsg955QsgUz8j5H/1Z76kufRCVMPv 03MKMatYwYqvUX4zCXltgyUx0IcKCUTsfsg0N3FUxdlRF9jwzy0b3bAGRZ2LccRkqRrr oOtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=r3KIz7myT/2cEyREdDWYFF0MzAECVUHcZokxc5b2FZI=; b=YRllT1nCgJYoUzaWARwUAUh32attoGy1kJn8x1P6TbFFmY+VhzbSViKAIJ2xVMbRrt /SeRU0wdWtiK7kWPX/qjXyVx2FD26+ZeK3z7ye9laqhymZ/1cJb+d6Z9se19CGCoP3/3 OHBrLTmYNttpnvHBpOwFuMhjx8XW1XxY0kqO/bEvIXFj6O5V7dgHfVGoA32AJQDATW/s 5xJ41sMeYkKBXBTv6T+rLTfL1pB4N8CTiW4LOhZcUUUEGyobkNgov4V21XJV5LF+u6UJ COBLiTayLuZXnr40FK0/wKY8ZGZHHgiJz6/Mlsq/0o1eoeQt2FMwg5nRDjuNR2I5qaHJ TwnQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q28-20020a056402249c00b00489e993b8easi5432486eda.630.2023.01.27.04.24.20; Fri, 27 Jan 2023 04:25:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233561AbjA0MQI (ORCPT + 99 others); Fri, 27 Jan 2023 07:16:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232851AbjA0MPq (ORCPT ); Fri, 27 Jan 2023 07:15:46 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E546B8627B; Fri, 27 Jan 2023 04:11:17 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id AAE681650; Fri, 27 Jan 2023 03:41:30 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2D7A03F64C; Fri, 27 Jan 2023 03:40:46 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 21/31] init: Add last_{init, exit} list macros Date: Fri, 27 Jan 2023 11:39:22 +0000 Message-Id: <20230127113932.166089-22-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756178483632887950?= X-GMAIL-MSGID: =?utf-8?q?1756178483632887950?= From: Alexandru Elisei Add a last_init macro for constructor functions that will be executed last in the initialization process. Add a symmetrical macro, last_exit, for destructor functions that will be the last to be executed when kvmtool exits. The list priority for the late_{init, exit} macros has been bumped down a spot, but their relative priority remains unchanged, to keep the same size for the init_lists and exit_lists. Signed-off-by: Alexandru Elisei Signed-off-by: Suzuki K Poulose --- include/kvm/util-init.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/kvm/util-init.h b/include/kvm/util-init.h index 13d4f04d..e6a0e169 100644 --- a/include/kvm/util-init.h +++ b/include/kvm/util-init.h @@ -39,7 +39,8 @@ static void __attribute__ ((constructor)) __init__##cb(void) \ #define dev_init(cb) __init_list_add(cb, 5) #define virtio_dev_init(cb) __init_list_add(cb, 6) #define firmware_init(cb) __init_list_add(cb, 7) -#define late_init(cb) __init_list_add(cb, 9) +#define late_init(cb) __init_list_add(cb, 8) +#define last_init(cb) __init_list_add(cb, 9) #define core_exit(cb) __exit_list_add(cb, 0) #define base_exit(cb) __exit_list_add(cb, 2) @@ -47,5 +48,6 @@ static void __attribute__ ((constructor)) __init__##cb(void) \ #define dev_exit(cb) __exit_list_add(cb, 5) #define virtio_dev_exit(cb) __exit_list_add(cb, 6) #define firmware_exit(cb) __exit_list_add(cb, 7) -#define late_exit(cb) __exit_list_add(cb, 9) +#define late_exit(cb) __exit_list_add(cb, 8) +#define last_exit(cb) __exit_list_add(cb, 9) #endif From patchwork Fri Jan 27 11:39:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49345 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp804107wrn; Fri, 27 Jan 2023 04:24:07 -0800 (PST) X-Google-Smtp-Source: AMrXdXv2D5PCWR+xS7ZxXni7nP1OGlkBTx2IBKrXxr/i81KRBqre7url3yel0b1sMBzhFcz45T5u X-Received: by 2002:a17:907:8c14:b0:84c:e9c4:5751 with SMTP id ta20-20020a1709078c1400b0084ce9c45751mr43548196ejc.74.1674822247338; Fri, 27 Jan 2023 04:24:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674822247; cv=none; d=google.com; s=arc-20160816; b=TgAwUEVU9gZGDwD+W+Qslvzx/GOodjeO7X48kncsi4pVEMW7CEMrqEG5n5fRcUxu5m FhzbwQWKPKYurczzWMt6EmiK2LZZ39OAX0W1xXh2Oaq5nk6J+AKxz8v8gMDnaaQiawrb a8lUhd51Z68YXWw37bQovTkfrmMxmPbzm8DqY3rgeEvFlEX0M6vFQ9/0PKV9vUgjlaKV 56g2b29ThjrgZMpUW+I7xGVu9yNMV1Oj+EcOhrWNGAIxmFCh+E2TcYOIZxciNwQFExpz rBQidil/Fyi7UNfxENSyE/t3x7uQAELMPsfxmtM/VyAgK04XkDogrybNO0fyY8zivldz 9YPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=W/1KQLSnah0gOQJzSHDIX2sXehTNsKNGtbq092gxqw4=; b=JkglEVDvxNlfVoAaS7sGWBsXt7T+WOOZRV6AcTg4ZLtZxOULAbYXyFXRHF5GS4OSuu Ofsh8+EF3Fzj/DzD+oupV7/WO1BfgiDdrfmY3ob8/EPYncGLG7dggs9KneXw5WCKvXW4 UPEpLzmX5khiglCMCCEz0SIasTe+s7ddt9o+KUYbmMHKdDrpxf/HKYm59RLn9OByT1/u fk8BpXeJpp6Rwur+PH2WhaYorU9N8+6agc6qH201GlMx41S937TDOiIN4u3WxMgZA+u6 XOY6QFcWK7TSprekBQR8924dt7H5RvLNFDIO9uiAWMNcVWz+iDhsYv1sKDFzwdW2Wlos 4z8Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mt19-20020a170907619300b00870b608e433si4830649ejc.36.2023.01.27.04.23.43; Fri, 27 Jan 2023 04:24:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232316AbjA0MQi (ORCPT + 99 others); Fri, 27 Jan 2023 07:16:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233975AbjA0MQT (ORCPT ); Fri, 27 Jan 2023 07:16:19 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F3475A5C8; Fri, 27 Jan 2023 04:11:52 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 85B3D175A; Fri, 27 Jan 2023 03:41:33 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 068563F64C; Fri, 27 Jan 2023 03:40:48 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 22/31] arm64: Activate realm before the first VCPU is run Date: Fri, 27 Jan 2023 11:39:23 +0000 Message-Id: <20230127113932.166089-23-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756178412878940658?= X-GMAIL-MSGID: =?utf-8?q?1756178412878940658?= From: Alexandru Elisei Before KVM can run a VCPU belong to a realm, the realm be activated. Activating a realm prevents the adding of new object and seals the cryptographic measurement of that realm. The VCPU state is part of the measurement, which means that realm activation must be performed after all VCPUs have been reset. Current RMM implementation can only create RECs in the order of their MPIDRs. VCPUs get assigned MPIDRs by KVM based on their VCPU id. Reset the VCPUs in the order they were created from the main thread instead of doing it from their own thread, which doesn't guarantee any ordering. Signed-off-by: Alexandru Elisei Signed-off-by: Suzuki K Poulose --- arm/aarch64/kvm-cpu.c | 4 ++++ arm/aarch64/realm.c | 35 +++++++++++++++++++++++++++++++ arm/include/arm-common/kvm-arch.h | 1 + 3 files changed, 40 insertions(+) diff --git a/arm/aarch64/kvm-cpu.c b/arm/aarch64/kvm-cpu.c index 24e570c4..32fa7609 100644 --- a/arm/aarch64/kvm-cpu.c +++ b/arm/aarch64/kvm-cpu.c @@ -187,6 +187,10 @@ void kvm_cpu__reset_vcpu(struct kvm_cpu *vcpu) cpu_set_t *affinity; int ret; + /* VCPU reset is done before activating the realm. */ + if (kvm->arch.realm_is_active) + return; + affinity = kvm->arch.vcpu_affinity_cpuset; if (affinity) { ret = sched_setaffinity(0, sizeof(cpu_set_t), affinity); diff --git a/arm/aarch64/realm.c b/arm/aarch64/realm.c index eddccece..808d39c5 100644 --- a/arm/aarch64/realm.c +++ b/arm/aarch64/realm.c @@ -1,4 +1,5 @@ #include "kvm/kvm.h" +#include "kvm/kvm-cpu.h" #include #include @@ -192,3 +193,37 @@ void kvm_arm_realm_populate_dtb(struct kvm *kvm) if (end > start) realm_populate(kvm, start, end - start); } + +static void kvm_arm_realm_activate_realm(struct kvm *kvm) +{ + struct kvm_enable_cap activate_realm = { + .cap = KVM_CAP_ARM_RME, + .args[0] = KVM_CAP_ARM_RME_ACTIVATE_REALM, + }; + + if (ioctl(kvm->vm_fd, KVM_ENABLE_CAP, &activate_realm) < 0) + die_perror("KVM_CAP_ARM_RME(KVM_CAP_ARM_RME_ACTIVATE_REALM)"); + + kvm->arch.realm_is_active = true; +} + +static int kvm_arm_realm_finalize(struct kvm *kvm) +{ + int i; + + if (!kvm->cfg.arch.is_realm) + return 0; + + /* + * VCPU reset must happen before the realm is activated, because their + * state is part of the cryptographic measurement for the realm. + */ + for (i = 0; i < kvm->nrcpus; i++) + kvm_cpu__reset_vcpu(kvm->cpus[i]); + + /* Activate and seal the measurement for the realm. */ + kvm_arm_realm_activate_realm(kvm); + + return 0; +} +last_init(kvm_arm_realm_finalize) diff --git a/arm/include/arm-common/kvm-arch.h b/arm/include/arm-common/kvm-arch.h index b5a4b851..6d48e13c 100644 --- a/arm/include/arm-common/kvm-arch.h +++ b/arm/include/arm-common/kvm-arch.h @@ -116,6 +116,7 @@ struct kvm_arch { cpu_set_t *vcpu_affinity_cpuset; u64 measurement_algo; u64 sve_vq; + bool realm_is_active; }; #endif /* ARM_COMMON__KVM_ARCH_H */ From patchwork Fri Jan 27 11:39:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49293 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp787783wrn; Fri, 27 Jan 2023 03:45:21 -0800 (PST) X-Google-Smtp-Source: AMrXdXtRSGpxwPaeIz1o3VGjr7DUfzlnEWi5k7AGt7PRQ6YfmQi6bmCTw0HTu05HbVcvw1b5vEbr X-Received: by 2002:a05:6402:3906:b0:49e:f5d5:c264 with SMTP id fe6-20020a056402390600b0049ef5d5c264mr28934134edb.27.1674819921628; Fri, 27 Jan 2023 03:45:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674819921; cv=none; d=google.com; s=arc-20160816; b=sDE0+tUpauUPjwuJhobTVl8eBTOqmJ5fDfz7S1UZq9d5o0c9q+KXjUYLyeJyF3+kVT IksTHV8RG2SP6RSpltUcUd2dmQNjrsiCPPjPK4xOaRxkNQZYK0Hr+WrNw2O2iSVaeaFT GdHCMumrMoyUguOkH9EhxFzanW0wOcezRPu5A96d0vr60p7SJ3pooyKbASNU/n1+9D4E 8hPQCxH6nFjGISh7TVbn/F19PrgwKuvvbWtkqu6IDxvWHQPD/TM4BQkz20OVXX12TRSI dxX5HL8o4FNhZ5izatYchyQkpruW4LsLmz5CSYDhWh22cIHPRjuK5eIXn1N9MzfxlDox G2jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=wAZSgheIzZt3iJX48AmDi5YRv0cAc1RwUuRkKSWEA38=; b=FOCACd0UvU8xL9eiHHqEraws2ZtuHMFGtnY6PGumCxiF3PBfbE4QPBTGYXbJ1f3ZGc fdqGGl5fmqfG1nYTWAZWjeZMiyQGcL2F2MGf/opdDzGO6gI5cHd1PqkhcmI/un+bXPD7 uwb8EokWd3oZB3YYaypMuWJZ7/qdItcNpkPaASHjA/8dUnxTCFZCu/d7XoIFukEkP/g/ /IvVUjW7b0fwg+Gpa0OTJHgisbD2YZNzH2ie35WbTILiRPT/eawORlEA2b5Rx7c45JqJ RAq2wtOUM+3DKdcowxwK9i4nAeFnFtuRUhXzNQWhSv/ISR/SyKZImZoi6/c7DR5aQ9lQ yI9A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d4-20020a056402078400b004a0e2b93456si4327762edy.456.2023.01.27.03.44.57; Fri, 27 Jan 2023 03:45:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232281AbjA0LmW (ORCPT + 99 others); Fri, 27 Jan 2023 06:42:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233870AbjA0Llo (ORCPT ); Fri, 27 Jan 2023 06:41:44 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DFAFA7264A; Fri, 27 Jan 2023 03:41:10 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 68CBE1595; Fri, 27 Jan 2023 03:41:36 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D6C173F64C; Fri, 27 Jan 2023 03:40:51 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 23/31] arm64: Specify SMC as the PSCI conduits for realms Date: Fri, 27 Jan 2023 11:39:24 +0000 Message-Id: <20230127113932.166089-24-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756175973944885515?= X-GMAIL-MSGID: =?utf-8?q?1756175973944885515?= From: Christoffer Dall This lets the VM use the RMM implementation for PSCI. Signed-off-by: Christoffer Dall Signed-off-by: Alexandru Elisei Signed-off-by: Suzuki K Poulose --- arm/fdt.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arm/fdt.c b/arm/fdt.c index 762a604d..c46ff410 100644 --- a/arm/fdt.c +++ b/arm/fdt.c @@ -208,7 +208,14 @@ static int setup_fdt(struct kvm *kvm) _FDT(fdt_property_string(fdt, "compatible", "arm,psci")); fns = &psci_0_1_fns; } - _FDT(fdt_property_string(fdt, "method", "hvc")); + + + if (kvm->cfg.arch.is_realm) { + _FDT(fdt_property_string(fdt, "method", "smc")); + } else { + _FDT(fdt_property_string(fdt, "method", "hvc")); + } + _FDT(fdt_property_cell(fdt, "cpu_suspend", fns->cpu_suspend)); _FDT(fdt_property_cell(fdt, "cpu_off", fns->cpu_off)); _FDT(fdt_property_cell(fdt, "cpu_on", fns->cpu_on)); From patchwork Fri Jan 27 11:39:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49292 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp787771wrn; Fri, 27 Jan 2023 03:45:20 -0800 (PST) X-Google-Smtp-Source: AK7set/OYuPSDlc/TP+Mhp2aRVB8Lo0MwFaXyzorZ1PzvcLqKk750BmFqsJNVPNFRFs9eyXPhzc5 X-Received: by 2002:a05:6a20:6985:b0:bb:a0a2:c37a with SMTP id t5-20020a056a20698500b000bba0a2c37amr18272102pzk.33.1674819920146; Fri, 27 Jan 2023 03:45:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674819920; cv=none; d=google.com; s=arc-20160816; b=VsZ9RYocwPw2PMZY3InU9oIU3RQhNihpvUgewJh4UR6xMxYHJjFNIJMKmpIq1SYDT6 WBf48zlZ/wFyFZnQcpMbC3WZGEPW3+7G9aO0zFOY/N+G1ivBj1Wyj47rdaH0/fRv0kYr kTTOrmE6dUz7rosBcb3BYZT0RXvR68eXCGh2v2Iq+KxnPtYxxpRxe9sTF9xI+eKmW0zf +PoaZ2Sa2FcPNFTULC1PujuaEGsiAGtyVFl5e8HldZI/+WKR6wfg+ilviwSCOl3yR77h rXuK9475txQUh8tbFn39a9/Ytm3ZqvZMMjaYKOF9N/JwR9/34+RGSWWqLBOXhDmf3yOe OP9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=8cm6MleZ69lmQ7FeZNj6PGM0Ua1vGF08LWBV7bp3DOk=; b=iB+TTcLfEM8cYJMgZYsh1o5BbQ2i57NzlHGqx2CNdHz8yddBbz4e9THjkflumGrBRB cCCyihYU//2gYFhuye0iEnjDvOYWY5CUIHI9ZcTFZyjPw4LwHG8CFyMoj2L4xovV8/U6 qPP0fBzC3qJCdi6Tdoe58uVGZHnnmwLC3stlLkC3MFa+p4MeOq/MJYPlfhD5x/59U50f i/qqobS93nX29bnuQz4kMv33ndTSoy3lqitvJMdomTjQNLzwnJbDU4cTKKhUI8/Z6oz1 aHc28B7ei+Whj/UzWvUANrbVfT+2uJ9+6S8HOB5INEx9ux39APZEkZhAwQGS/iaY2s/j OmDw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k27-20020aa7973b000000b0058d9266a507si4304167pfg.376.2023.01.27.03.45.07; Fri, 27 Jan 2023 03:45:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231663AbjA0Lm2 (ORCPT + 99 others); Fri, 27 Jan 2023 06:42:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233825AbjA0Llp (ORCPT ); Fri, 27 Jan 2023 06:41:45 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 00A527AE7F; Fri, 27 Jan 2023 03:41:10 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4B9CB1762; Fri, 27 Jan 2023 03:41:39 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B8BF43F8D6; Fri, 27 Jan 2023 03:40:54 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 24/31] arm64: Don't try to debug a realm Date: Fri, 27 Jan 2023 11:39:25 +0000 Message-Id: <20230127113932.166089-25-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756175972719225429?= X-GMAIL-MSGID: =?utf-8?q?1756175972719225429?= From: Alexandru Elisei Don't read the register values for a running realm, because they don't reflect the actual hardware state of a realm. And don't try to read realm memory, because that will promptly lead to kvmtool being killed. Signed-off-by: Alexandru Elisei Signed-off-by: Suzuki K Poulose --- arm/aarch64/kvm-cpu.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arm/aarch64/kvm-cpu.c b/arm/aarch64/kvm-cpu.c index 32fa7609..a29a3413 100644 --- a/arm/aarch64/kvm-cpu.c +++ b/arm/aarch64/kvm-cpu.c @@ -250,6 +250,9 @@ void kvm_cpu__show_code(struct kvm_cpu *vcpu) reg.addr = (u64)&data; + if (vcpu->kvm->cfg.arch.is_realm) + return; + dprintf(debug_fd, "\n*pc:\n"); reg.id = ARM64_CORE_REG(regs.pc); if (ioctl(vcpu->vcpu_fd, KVM_GET_ONE_REG, ®) < 0) @@ -274,6 +277,11 @@ void kvm_cpu__show_registers(struct kvm_cpu *vcpu) reg.addr = (u64)&data; dprintf(debug_fd, "\n Registers:\n"); + if (vcpu->kvm->cfg.arch.is_realm) { + dprintf(debug_fd, " UNACCESSIBLE\n"); + return; + } + reg.id = ARM64_CORE_REG(regs.pc); if (ioctl(vcpu->vcpu_fd, KVM_GET_ONE_REG, ®) < 0) die("KVM_GET_ONE_REG failed (pc)"); From patchwork Fri Jan 27 11:39:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49301 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp788286wrn; Fri, 27 Jan 2023 03:46:27 -0800 (PST) X-Google-Smtp-Source: AK7set9K+D4c51DMk98sUVNVUnMUszq55QKgVWIhFoNtNOzvHyRwug9ahU5O7BRnXCx1KAbsoC5y X-Received: by 2002:a17:907:2d07:b0:87b:daca:aa1a with SMTP id gs7-20020a1709072d0700b0087bdacaaa1amr1503429ejc.45.1674819987684; Fri, 27 Jan 2023 03:46:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674819987; cv=none; d=google.com; s=arc-20160816; b=L1Kj/Qmn4+2K3lPYV1JnxvhCw3ghx/d420QP48B2VgDEdYiokQ/Av7BDA8awdtN+kO tmHnpBVdK07gPrYaSMRdV8M05+hJawRQhKkKiSyXuAcvmGHAyIp2b3wmXyFk6U2F6jmL U2sd5zJGKAgWveaxp0EupjTFJVkTPcHNujLjxRA0YmdrCb56nlKyY8NnR4is9jdcOWKV rOymYC1C+bzWOpUVFqzasU6xi5lsWZ1P+3zReD2u8mLS1xXiKhjMtP4442M9WB6Qc8pN eE/DWuM8xjvNCIoMYzL6/fI59s8IV3DH/XLZb+UISYIwEnxZa+hqvR+F1VIncKIfi9cm XZYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=sNQiej5jsQyq0PeHIq0jITBcc9ALWIhX6feJOk+R5GY=; b=DKPM0JVzVM+kCdQpx5ZHCVEQkRwnZqoaXzseZoun4JZR+hWyXbSOYBL//fuWR/XiHV zxpy50VexrcHvPwNNCrG6L32gSh7Ely7+sxZnGKyjrDPwg1dCB14jl7d0WNmNEkiyNMy qHNKtfGvxMXqKSihN/VrtyLs40WNmpr25ipPHwZyH3c0vZ8KKkHjCoOfniqA2JRsX/Wz aBX8C3Yauz0IB75qmChOS3cK4zqs3Zswzc62/EFAX0s5JSPpqZZasKgzR/J6TGI+piy2 ETLUuVOImLljL0wA73+jZPalk3MvAf01eaZee2HyUa7y6sjvo+rpMDbVmUbjbks+H9vI goXg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ay24-20020a170907901800b0087bce26e657si1649301ejc.924.2023.01.27.03.46.03; Fri, 27 Jan 2023 03:46:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233017AbjA0Lnv (ORCPT + 99 others); Fri, 27 Jan 2023 06:43:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234032AbjA0Lnd (ORCPT ); Fri, 27 Jan 2023 06:43:33 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 33B737C313; Fri, 27 Jan 2023 03:42:13 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2D1C71764; Fri, 27 Jan 2023 03:41:42 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9B35E3F64C; Fri, 27 Jan 2023 03:40:57 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 25/31] arm64: realm: Double the IPA space Date: Fri, 27 Jan 2023 11:39:26 +0000 Message-Id: <20230127113932.166089-26-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756176043219554701?= X-GMAIL-MSGID: =?utf-8?q?1756176043219554701?= The Realm's IPA space is divided into 2 halves. Protected (lower half) and Unprotected (upper half). KVM implements aliasing of the IPA, where the unprotected IPA is alias of the corresponding protected ipa. Thus we must double the IPA space required for a given VM. Signed-off-by: Suzuki K Poulose --- arm/aarch64/kvm.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c index fca1410b..344c568b 100644 --- a/arm/aarch64/kvm.c +++ b/arm/aarch64/kvm.c @@ -189,6 +189,9 @@ int kvm__get_vm_type(struct kvm *kvm) /* Otherwise, compute the minimal required IPA size */ max_ipa = kvm->cfg.ram_addr + kvm->cfg.ram_size - 1; ipa_bits = max(32, fls_long(max_ipa)); + /* Realm needs double the IPA space */ + if (kvm->cfg.arch.is_realm) + ipa_bits++; pr_debug("max_ipa %lx ipa_bits %d max_ipa_bits %d", max_ipa, ipa_bits, max_ipa_bits); From patchwork Fri Jan 27 11:39:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49298 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp788037wrn; Fri, 27 Jan 2023 03:45:53 -0800 (PST) X-Google-Smtp-Source: AMrXdXsnygQhjKcOM958ulrOH1OUIBR5AI9WZy77clcBJ+r9vtngu3q0uI9jOX7GeMx2LubL4IvM X-Received: by 2002:a05:6a20:1e64:b0:b8:63bd:7c3e with SMTP id cy36-20020a056a201e6400b000b863bd7c3emr36268218pzb.2.1674819953318; Fri, 27 Jan 2023 03:45:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674819953; cv=none; d=google.com; s=arc-20160816; b=NRvlE80u1ltekyrVJvvt1MwG4P7S/9djylkhWFRfF+z2INhF+AJAHkb+uDso+2SccL 1+R/Vu5+JzP/GD/jinLvYowz+7vHkjEhpLhaAqQmJthFeHvoWorPJldz/dLkS7scIf+9 70JWp5hoKYeiydpaZprv1nqWUsABigTnNInZuoEN/DcF+k0hS47aCgcqeUOPiMUoDwVs 6h+RvNPJKego45JnrIuPcnahLejd3laV7VysFtHvkGNays7Zn+RhyU/YYeLJ+pSiU54n 3mKEdSfoy+IxdQ924GM8X+UHs2V+hICP2P1sZo4OAVXEEAnv0tKpvs18RaV1Y7aypRDN pchQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=1m/+FvQpO8U9prPz1n17ph3x+s7qWHS7eGLm4H1yzmo=; b=stCz25rL63fWZ+MtQf6rPvH0kX/9xfeU0roFQ6tQJJOEQLG16XnjAy12OFK6UHbxne BB/7No7fc/emEefYsJ2KiydAVhD1ne9VmGGi2akORylyQxmnImPuS9zCyuhGorSJu/GB vanMefmpvUSUPMOw/oRhMzjE/Bvx9SK8GJpFwJdkKzo+zSMiWFQh3ZuX2DIcbiY3Y2c4 CQKa0zhjR7zvHEx37XwvHpwc6OAnvjp3bVc9VKCj559f+0gQN7cS6L48JkVT6ta82O7b nQ5tXl8snISV5GtMgABhuACd19B+/0954xPFuFei+MsXItQnn8NBxKzx4WIMM+sQLAdU eLpA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x17-20020a656ab1000000b004769983b39asi4165183pgu.667.2023.01.27.03.45.40; Fri, 27 Jan 2023 03:45:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230092AbjA0Lmp (ORCPT + 99 others); Fri, 27 Jan 2023 06:42:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233879AbjA0LmA (ORCPT ); Fri, 27 Jan 2023 06:42:00 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3586270D7E; Fri, 27 Jan 2023 03:41:28 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 06657176A; Fri, 27 Jan 2023 03:41:45 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7CD023F64C; Fri, 27 Jan 2023 03:41:00 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 26/31] virtio: Add a wrapper for get_host_features Date: Fri, 27 Jan 2023 11:39:27 +0000 Message-Id: <20230127113932.166089-27-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756176007447567035?= X-GMAIL-MSGID: =?utf-8?q?1756176007447567035?= Add a wrapper to the vdev->ops->get_host_features() to allow setting platform specific flags outside the device Signed-off-by: Suzuki K Poulose --- include/kvm/virtio.h | 2 ++ virtio/core.c | 5 +++++ virtio/mmio-legacy.c | 2 +- virtio/mmio-modern.c | 2 +- virtio/pci-legacy.c | 2 +- virtio/pci-modern.c | 2 +- 6 files changed, 11 insertions(+), 4 deletions(-) diff --git a/include/kvm/virtio.h b/include/kvm/virtio.h index 94bddefe..e95cfad5 100644 --- a/include/kvm/virtio.h +++ b/include/kvm/virtio.h @@ -248,4 +248,6 @@ void virtio_set_guest_features(struct kvm *kvm, struct virtio_device *vdev, void virtio_notify_status(struct kvm *kvm, struct virtio_device *vdev, void *dev, u8 status); +u64 virtio_dev_get_host_features(struct virtio_device *vdev, struct kvm *kvm, void *dev); + #endif /* KVM__VIRTIO_H */ diff --git a/virtio/core.c b/virtio/core.c index ea0e5b65..50e7f86d 100644 --- a/virtio/core.c +++ b/virtio/core.c @@ -283,6 +283,11 @@ void virtio_notify_status(struct kvm *kvm, struct virtio_device *vdev, vdev->ops->notify_status(kvm, dev, ext_status); } +u64 virtio_dev_get_host_features(struct virtio_device *vdev, struct kvm *kvm, void *dev) +{ + return vdev->ops->get_host_features(kvm, dev); +} + bool virtio_access_config(struct kvm *kvm, struct virtio_device *vdev, void *dev, unsigned long offset, void *data, size_t size, bool is_write) diff --git a/virtio/mmio-legacy.c b/virtio/mmio-legacy.c index 7ca7e69f..42673236 100644 --- a/virtio/mmio-legacy.c +++ b/virtio/mmio-legacy.c @@ -26,7 +26,7 @@ static void virtio_mmio_config_in(struct kvm_cpu *vcpu, break; case VIRTIO_MMIO_DEVICE_FEATURES: if (vmmio->hdr.host_features_sel == 0) - val = vdev->ops->get_host_features(vmmio->kvm, + val = virtio_dev_get_host_features(vdev, vmmio->kvm, vmmio->dev); ioport__write32(data, val); break; diff --git a/virtio/mmio-modern.c b/virtio/mmio-modern.c index 6c0bb382..a09fa8e9 100644 --- a/virtio/mmio-modern.c +++ b/virtio/mmio-modern.c @@ -26,7 +26,7 @@ static void virtio_mmio_config_in(struct kvm_cpu *vcpu, case VIRTIO_MMIO_DEVICE_FEATURES: if (vmmio->hdr.host_features_sel > 1) break; - features |= vdev->ops->get_host_features(vmmio->kvm, vmmio->dev); + features |= virtio_dev_get_host_features(vdev, vmmio->kvm, vmmio->dev); val = features >> (32 * vmmio->hdr.host_features_sel); break; case VIRTIO_MMIO_QUEUE_NUM_MAX: diff --git a/virtio/pci-legacy.c b/virtio/pci-legacy.c index 58047967..d5f5dee7 100644 --- a/virtio/pci-legacy.c +++ b/virtio/pci-legacy.c @@ -44,7 +44,7 @@ static bool virtio_pci__data_in(struct kvm_cpu *vcpu, struct virtio_device *vdev switch (offset) { case VIRTIO_PCI_HOST_FEATURES: - val = vdev->ops->get_host_features(kvm, vpci->dev); + val = virtio_dev_get_host_features(vdev, kvm, vpci->dev); ioport__write32(data, val); break; case VIRTIO_PCI_QUEUE_PFN: diff --git a/virtio/pci-modern.c b/virtio/pci-modern.c index c5b4bc50..2c5bf3f8 100644 --- a/virtio/pci-modern.c +++ b/virtio/pci-modern.c @@ -158,7 +158,7 @@ static bool virtio_pci__common_read(struct virtio_device *vdev, case VIRTIO_PCI_COMMON_DF: if (vpci->device_features_sel > 1) break; - features |= vdev->ops->get_host_features(vpci->kvm, vpci->dev); + features |= virtio_dev_get_host_features(vdev, vpci->kvm, vpci->dev); val = features >> (32 * vpci->device_features_sel); ioport__write32(data, val); break; From patchwork Fri Jan 27 11:39:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49302 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp788327wrn; Fri, 27 Jan 2023 03:46:35 -0800 (PST) X-Google-Smtp-Source: AMrXdXvZH7uz2vVJhmtkVxvJgaj95rBrvkwjlq5vJ7ExmI8pNGmnqGwrQO6aibOUj09WZksijQ6T X-Received: by 2002:a05:6402:209:b0:47e:15ec:155e with SMTP id t9-20020a056402020900b0047e15ec155emr38562040edv.26.1674819995106; Fri, 27 Jan 2023 03:46:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674819995; cv=none; d=google.com; s=arc-20160816; b=fYuHmicmBoFx+BXz5jXr0lUtsg/Dx1AMHce+bWd2+3cYlUKJImid/MQ9INeLQPBB8x 5WCzpAA4OI3AT4VE4L9MaaF7BXN/EjQ1cqPcrr6joN8Bbshq/YaBU+BiIZqvWlr6yPmN 8tceGshsSERxkpiD04Btc+TV4a8aPQtxMc4tXpP8OMaqRfT9GoPTe+eyawpV3SZ5SYHj 1Vd3StL1n/QwLOpTfFAbqJXPrl/8oKEYlIFrtuUVQeN6wd5jZEY7HjNiTmAHJcEH9M2b WvnOMvGQ9bdCC2cSzKPxRdg/isvSayTT24BoAAxUQZISPQ9W3NDcKXLOEtVxU66ygm4/ Y4ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=IhaJTe6HaHPbf/qwv5Ljk1YWsAk3FTJOOGfpr6OYJXU=; b=Q/TAZeMKS7dX6lh2Vd2Qhg/vERxaYl88PJsTR6IehGBNUr8sYaNKmfc8XVaSExggQN pFxObjTxgf0adm37/ugjn15N+OiGzj3sk1q/weUCcLDLQXn+LeJpdI1lDmNW4O2m3yi2 gLxTRucYXa6jjzz9PB3q4mp5ihefCzGBs1fk9r3ndNHQsWbMgKf+W97Um8VQTgCHWtlb 92ZRpyWG5U9aF5Uh9pPPYNLtrwMAdJ73+We5BmoMcOWuycPw81+L0DDj978Q+zSo/VyY kgEq/n/ktjnU2pUTBadG8VY1A0SMgLgshdmDK/XB3YI1WrlR9RXm1OjGjEt6aM3cmFLQ 2BcA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bq13-20020a056402214d00b0049e6a6bacd4si3870639edb.548.2023.01.27.03.46.11; Fri, 27 Jan 2023 03:46:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233791AbjA0Lmu (ORCPT + 99 others); Fri, 27 Jan 2023 06:42:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233903AbjA0LmA (ORCPT ); Fri, 27 Jan 2023 06:42:00 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8AEF372659; Fri, 27 Jan 2023 03:41:28 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D6C8F1684; Fri, 27 Jan 2023 03:41:47 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 561883F64C; Fri, 27 Jan 2023 03:41:03 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 27/31] virtio: Add arch specific hook for virtio host flags Date: Fri, 27 Jan 2023 11:39:28 +0000 Message-Id: <20230127113932.166089-28-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756176050981995951?= X-GMAIL-MSGID: =?utf-8?q?1756176050981995951?= Add callbacks for archs to provide virtio host flags. Signed-off-by: Suzuki K Poulose --- arm/aarch32/kvm.c | 5 +++++ arm/aarch64/kvm.c | 5 +++++ include/kvm/kvm.h | 2 ++ mips/kvm.c | 5 +++++ powerpc/kvm.c | 5 +++++ riscv/kvm.c | 5 +++++ virtio/core.c | 5 ++++- x86/kvm.c | 5 +++++ 8 files changed, 36 insertions(+), 1 deletion(-) diff --git a/arm/aarch32/kvm.c b/arm/aarch32/kvm.c index 768a56bb..849c55d3 100644 --- a/arm/aarch32/kvm.c +++ b/arm/aarch32/kvm.c @@ -12,3 +12,8 @@ u64 kvm__arch_default_ram_address(void) { return ARM_MEMORY_AREA; } + +u64 kvm__arch_get_virtio_host_features(struct kvm *kvm) +{ + return 0; +} diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c index 344c568b..a4664237 100644 --- a/arm/aarch64/kvm.c +++ b/arm/aarch64/kvm.c @@ -234,3 +234,8 @@ void kvm__arch_enable_mte(struct kvm *kvm) pr_debug("MTE capability enabled"); } + +u64 kvm__arch_get_virtio_host_features(struct kvm *kvm) +{ + return 0; +} diff --git a/include/kvm/kvm.h b/include/kvm/kvm.h index 3872dc65..a3624de4 100644 --- a/include/kvm/kvm.h +++ b/include/kvm/kvm.h @@ -203,6 +203,8 @@ int kvm__arch_free_firmware(struct kvm *kvm); bool kvm__arch_cpu_supports_vm(void); void kvm__arch_read_term(struct kvm *kvm); +u64 kvm__arch_get_virtio_host_features(struct kvm *kvm); + #ifdef ARCH_HAS_CFG_RAM_ADDRESS static inline bool kvm__arch_has_cfg_ram_address(void) { diff --git a/mips/kvm.c b/mips/kvm.c index 0faa03a9..e23d5cf9 100644 --- a/mips/kvm.c +++ b/mips/kvm.c @@ -374,3 +374,8 @@ void ioport__map_irq(u8 *irq) void serial8250__inject_sysrq(struct kvm *kvm, char sysrq) { } + +u64 kvm__arch_get_virtio_host_features(struct kvm *kvm) +{ + return 0; +} diff --git a/powerpc/kvm.c b/powerpc/kvm.c index 7b0d0669..6b3ab93f 100644 --- a/powerpc/kvm.c +++ b/powerpc/kvm.c @@ -529,3 +529,8 @@ int kvm__arch_free_firmware(struct kvm *kvm) { return 0; } + +u64 kvm__arch_get_virtio_host_features(struct kvm *kvm) +{ + return 0; +} diff --git a/riscv/kvm.c b/riscv/kvm.c index 4d6f5cb5..884321ca 100644 --- a/riscv/kvm.c +++ b/riscv/kvm.c @@ -182,3 +182,8 @@ int kvm__arch_setup_firmware(struct kvm *kvm) { return 0; } + +u64 kvm__arch_get_virtio_host_features(struct kvm *kvm) +{ + return 0; +} diff --git a/virtio/core.c b/virtio/core.c index 50e7f86d..674f6fae 100644 --- a/virtio/core.c +++ b/virtio/core.c @@ -285,7 +285,10 @@ void virtio_notify_status(struct kvm *kvm, struct virtio_device *vdev, u64 virtio_dev_get_host_features(struct virtio_device *vdev, struct kvm *kvm, void *dev) { - return vdev->ops->get_host_features(kvm, dev); + u64 features = kvm__arch_get_virtio_host_features(kvm); + + features |= vdev->ops->get_host_features(kvm, dev); + return features; } bool virtio_access_config(struct kvm *kvm, struct virtio_device *vdev, diff --git a/x86/kvm.c b/x86/kvm.c index 328fa750..961b5d3f 100644 --- a/x86/kvm.c +++ b/x86/kvm.c @@ -387,3 +387,8 @@ void kvm__arch_read_term(struct kvm *kvm) serial8250__update_consoles(kvm); virtio_console__inject_interrupt(kvm); } + +u64 kvm__arch_get_virtio_host_features(struct kvm *kvm) +{ + return 0; +} From patchwork Fri Jan 27 11:39:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49296 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp787891wrn; Fri, 27 Jan 2023 03:45:35 -0800 (PST) X-Google-Smtp-Source: AK7set90RbtzxixM6uTt83Fwll/rsC6u/hHIABJC0/ro0AbKQMy8JDBujH3n0CgelzY1rJn9h3iA X-Received: by 2002:a17:90b:4f46:b0:22c:1211:89c0 with SMTP id pj6-20020a17090b4f4600b0022c121189c0mr8616387pjb.30.1674819934966; Fri, 27 Jan 2023 03:45:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674819934; cv=none; d=google.com; s=arc-20160816; b=ernMpdOYuehqJN3fK2+Yr2rIn14JjMeQeHRX8ntxD3lxR3T3NptcKAXFvV+uiWs8VO NEa6VICbMdlyUWMzw7vvMn/1Lo7HjSjlVYm6p3iIgEuRhJFilF94gxKutYdnp0EemDrL NHcOpSe1dhIvUNrIn3FeSv66IDCxBc+bv9EYAFI61hu1XYUmZq8i0UsA2a6H7rV9RsSN crYqaywm/23vQU46fjjQlMZ+cFehxGbclMqNnUpaJ17CsNX0NB8kAAf23lHHPPf9NxBm dR/wJ46zvzv/lkXifPzRMMhabTh89HDKyc9WMpRUFvGU4ChwY2NFfxxtOucfWEdbAIjm aG4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=55CzEaHyu3zC2RRESS1M/EgSOmQty8uOohnUSon2wxc=; b=ba8TDE35Q9iIlZ5SxPvRE+3n38xqXtUY/9X0NU6vmvQ3cIaQLszkS0ILmSrcWq9FNE 1q/XHtF/oqs4Xw/jBDfHNCBiuLo88sAJhvSB/cp44aGjvtF2EYcp87Bm5Q/6B4S10Oj5 E2JM6WdKeMLmgM+rQZmd0FBl0YUnmgz1an2KPRWve8NVnoU6KhqW/HkxLj/O6UAqn0fY zX0NDOqYlGiUUNNelfBRwwTTuIH1MGxA4Vv3L2MWpfeVlcBbFytyuvFXdxkX4ipxIFpk TzqrBFC4X3n09eooIah9AzwbAX2FM1befq9XVjYu5e9lHhHrH1DnIvz9ipLVEgPowkPL bJSQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d194-20020a6336cb000000b004ccbc54e8bcsi3983493pga.93.2023.01.27.03.45.22; Fri, 27 Jan 2023 03:45:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233647AbjA0Lm4 (ORCPT + 99 others); Fri, 27 Jan 2023 06:42:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233925AbjA0LmB (ORCPT ); Fri, 27 Jan 2023 06:42:01 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E13317A4A1; Fri, 27 Jan 2023 03:41:29 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B8BAC165C; Fri, 27 Jan 2023 03:41:50 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 329813F64C; Fri, 27 Jan 2023 03:41:06 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 28/31] arm64: realm: Enforce virtio F_ACCESS_PLATFORM flag Date: Fri, 27 Jan 2023 11:39:29 +0000 Message-Id: <20230127113932.166089-29-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756175987949463054?= X-GMAIL-MSGID: =?utf-8?q?1756175987949463054?= For realms, force the F_ACCESS_PLATFORM flag to ensure DMA-APIs are triggered for virtio in Linux Signed-off-by: Suzuki K Poulose --- arm/aarch64/kvm.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c index a4664237..1f3a0def 100644 --- a/arm/aarch64/kvm.c +++ b/arm/aarch64/kvm.c @@ -5,6 +5,7 @@ #include #include #include +#include #include @@ -237,5 +238,10 @@ void kvm__arch_enable_mte(struct kvm *kvm) u64 kvm__arch_get_virtio_host_features(struct kvm *kvm) { - return 0; + u64 features = 0; + + /* Enforce F_ACCESS_PLATFORM for Realms */ + if (kvm->cfg.arch.is_realm) + features |= (1ULL << VIRTIO_F_ACCESS_PLATFORM); + return features; } From patchwork Fri Jan 27 11:39:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49297 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp787991wrn; Fri, 27 Jan 2023 03:45:47 -0800 (PST) X-Google-Smtp-Source: AMrXdXsqg9l7SgD1Uq2Gh/RkzE0Lqp7CD6Q/79z847sKo/UNLXdcjazC5zj35MIY9DibCcN8+xiv X-Received: by 2002:aa7:cc8f:0:b0:492:8207:f2ba with SMTP id p15-20020aa7cc8f000000b004928207f2bamr47740492edt.1.1674819947678; Fri, 27 Jan 2023 03:45:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674819947; cv=none; d=google.com; s=arc-20160816; b=GXYTKHqGryjFGTZNy2eTQncItLiKCUUoqfaZi698sJldZe1PTQ5mA39NsrOPTKy5i/ sugmxg1qxC+oPUY5rzjtTiZXPiT5vLsAkuUZZePm0lBikaauq988b8RCo5ArESFCLh2Z xHDRIzrRpQdjqcF4NFzQoz6IrSKH5aRbTfNKj/+at2iw5efM3lokbrYtdL/kvkdFsOkx OGCGw7Zfh+EK8dsFCsg+60lN2OJL6VYN7ZJfs/Tym2hQuaKot+0q2XfhsM2lb9YmMah+ bp0Bv5svIy00m5fhgq+UUwue9si3/PCokeFl5Shuz/iW2PD4iRkDF/28QOD3M7FsWxH4 gWlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=BjmTOUZ/PjhxOgrHmb6iSD0DbbrkDvk8DcWPExZMP4c=; b=E8cNguxnBuZnfLaRmjLZAUer0HjaEx/q2D3ftuq1EvJfadlpOrQ1s6gp6gFEeklA83 YcQxhMID8pe5omXEMIgfzmQfWZvEYspo+ORjV0CpttxgO7Z7MgHMSUuHuneSd3tH07Ww G//nxrX2+6p7lpJVcd303alO6kh7Wm8PTEdDK9v5qtrxsptv96fkQuNCdlWoi2SD3gyY FpiNzngGl7Y4H7YSjp0DRKI7xQASlfzoMqHJfKBmR9x7LKOTB38BPRNG7z2BFq4ZUtJs tNaHQmFkr5OIe/ARW7/suEGA1hYwWobpDBZm/P7V8WEecOf9Ob9OfVxbWLzbNE/GXsaL ypug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j25-20020a50ed19000000b004a20fa1c65asi944534eds.365.2023.01.27.03.45.23; Fri, 27 Jan 2023 03:45:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233934AbjA0Lm7 (ORCPT + 99 others); Fri, 27 Jan 2023 06:42:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232184AbjA0LmC (ORCPT ); Fri, 27 Jan 2023 06:42:02 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 22E837B418; Fri, 27 Jan 2023 03:41:30 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id AC9DC1688; Fri, 27 Jan 2023 03:41:53 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 14CAB3F64C; Fri, 27 Jan 2023 03:41:08 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Joey Gouly Subject: [RFC kvmtool 29/31] mmio: add arch hook for an unhandled MMIO access Date: Fri, 27 Jan 2023 11:39:30 +0000 Message-Id: <20230127113932.166089-30-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756176001295130269?= X-GMAIL-MSGID: =?utf-8?q?1756176001295130269?= From: Joey Gouly Add a hook that allows an architecture to run some code on an unhandled MMIO access. Signed-off-by: Joey Gouly Signed-off-by: Suzuki K Poulose --- arm/kvm-cpu.c | 4 ++++ include/kvm/kvm-cpu.h | 2 ++ mips/kvm-cpu.c | 4 ++++ mmio.c | 3 +++ powerpc/kvm-cpu.c | 4 ++++ riscv/kvm-cpu.c | 4 ++++ x86/kvm-cpu.c | 4 ++++ 7 files changed, 25 insertions(+) diff --git a/arm/kvm-cpu.c b/arm/kvm-cpu.c index 98bc5fdf..90a15ae9 100644 --- a/arm/kvm-cpu.c +++ b/arm/kvm-cpu.c @@ -152,3 +152,7 @@ bool kvm_cpu__handle_exit(struct kvm_cpu *vcpu) void kvm_cpu__show_page_tables(struct kvm_cpu *vcpu) { } + +void kvm_cpu__arch_unhandled_mmio(struct kvm_cpu *vcpu) +{ +} diff --git a/include/kvm/kvm-cpu.h b/include/kvm/kvm-cpu.h index 0f16f8d6..d0c40598 100644 --- a/include/kvm/kvm-cpu.h +++ b/include/kvm/kvm-cpu.h @@ -29,4 +29,6 @@ void kvm_cpu__show_page_tables(struct kvm_cpu *vcpu); void kvm_cpu__arch_nmi(struct kvm_cpu *cpu); void kvm_cpu__run_on_all_cpus(struct kvm *kvm, struct kvm_cpu_task *task); +void kvm_cpu__arch_unhandled_mmio(struct kvm_cpu *cpu); + #endif /* KVM__KVM_CPU_H */ diff --git a/mips/kvm-cpu.c b/mips/kvm-cpu.c index 30a3de18..0ce88ac3 100644 --- a/mips/kvm-cpu.c +++ b/mips/kvm-cpu.c @@ -217,3 +217,7 @@ void kvm_cpu__show_code(struct kvm_cpu *vcpu) void kvm_cpu__show_page_tables(struct kvm_cpu *vcpu) { } + +void kvm_cpu__arch_unhandled_mmio(struct kvm_cpu *cpu) +{ +} diff --git a/mmio.c b/mmio.c index 5a114e99..7e31079b 100644 --- a/mmio.c +++ b/mmio.c @@ -206,6 +206,9 @@ bool kvm__emulate_mmio(struct kvm_cpu *vcpu, u64 phys_addr, u8 *data, fprintf(stderr, "Warning: Ignoring MMIO %s at %016llx (length %u)\n", to_direction(is_write), (unsigned long long)phys_addr, len); + + kvm_cpu__arch_unhandled_mmio(vcpu); + goto out; } diff --git a/powerpc/kvm-cpu.c b/powerpc/kvm-cpu.c index 461e0a90..e0c20f9d 100644 --- a/powerpc/kvm-cpu.c +++ b/powerpc/kvm-cpu.c @@ -288,3 +288,7 @@ void kvm_cpu__show_page_tables(struct kvm_cpu *vcpu) { /* Does nothing yet */ } + +void kvm_cpu__arch_unhandled_mmio(struct kvm_cpu *cpu) +{ +} diff --git a/riscv/kvm-cpu.c b/riscv/kvm-cpu.c index f98bd7ae..8417e361 100644 --- a/riscv/kvm-cpu.c +++ b/riscv/kvm-cpu.c @@ -461,3 +461,7 @@ void kvm_cpu__show_registers(struct kvm_cpu *vcpu) kvm_cpu__show_csrs(vcpu); } + +void kvm_cpu__arch_unhandled_mmio(struct kvm_cpu *cpu) +{ +} diff --git a/x86/kvm-cpu.c b/x86/kvm-cpu.c index b02ff65e..ac075ee4 100644 --- a/x86/kvm-cpu.c +++ b/x86/kvm-cpu.c @@ -444,3 +444,7 @@ void kvm_cpu__arch_nmi(struct kvm_cpu *cpu) ioctl(cpu->vcpu_fd, KVM_NMI); } + +void kvm_cpu__arch_unhandled_mmio(struct kvm_cpu *cpu) +{ +} From patchwork Fri Jan 27 11:39:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49304 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp788508wrn; Fri, 27 Jan 2023 03:47:02 -0800 (PST) X-Google-Smtp-Source: AMrXdXthtBAf0zR3To+Xt0qW26Cbmutbyp4UdfvDPTSRonXA0zkFXRmNr+q/t8dFNiiVne8tKu0e X-Received: by 2002:a17:902:6b06:b0:194:a602:13c8 with SMTP id o6-20020a1709026b0600b00194a60213c8mr34701163plk.52.1674820021927; Fri, 27 Jan 2023 03:47:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674820021; cv=none; d=google.com; s=arc-20160816; b=JfGf4jdqslU4QCwbPkJzyVrUh8akPyK1ZRvz2APL3lH1g3hfIH1SSAe0sCMJTr0ria OwLrBK272AUPQayHqUAxszQfZaKO3f9OdeujEpqVrbsDAaqD7iO5aMZoFQi5CfEz1+Yh A4pbq45wX6Rz/NcGr81QXrgUCKgHEVR3ZcjGibjXKG6CWWncjsPgu/lkRgzQju5pXQK/ fXm7W2C4gQzY6Of2DYYPqCsHYoQtK7I6nzh3GBO2vkoVXZW/qEzL22IlbzRGDAt8RMY/ hOaErjSMQfgjvU2LALIUbGCBbqSK+T5MzQJvuELeZZH6HTGt2OuK39emr04gUW56lwg4 fnPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=bsMAcFgkVBzLsel+wqtxlRZCjvfz+BLTIhiLpQ0D8eY=; b=Nsmp5jtPrjnOYG+oPLy8dTgnD8ZA3EgltS7FNU0JqXO7B1jhCtK0T0YmX2MW7D8qBf 2cJT4SMYXNahaz0YwFRRUfv2ZprmaygkymyWDGBlBCcuhMZnIhqaP+VWLJPIJxL6Xwyd M4XKn9Dyj+3khcbzcwk7cgiQws8mAbGHxCZswR91Hp5MARXsK+XlulyqlF1tcI8GJ3VM cBIeThdJgdskQQJI3RHwKkImOMhKPs49FwbgmcqNvZhGceRugSqVbATz+bnJp6OTuX0A e3HPQRK6Y/DhSVHB11EkpZRtj6V17DKsC2UJCkIHrU4lTEtapsE4Fopca5CYUwfUENMg /qdw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x24-20020aa79418000000b0058a4a6b6cbbsi4080062pfo.126.2023.01.27.03.46.49; Fri, 27 Jan 2023 03:47:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232068AbjA0LnD (ORCPT + 99 others); Fri, 27 Jan 2023 06:43:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233930AbjA0LmB (ORCPT ); Fri, 27 Jan 2023 06:42:01 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B2C177C31A; Fri, 27 Jan 2023 03:41:30 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A914E1691; Fri, 27 Jan 2023 03:41:56 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 08A9B3F64C; Fri, 27 Jan 2023 03:41:11 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Joey Gouly Subject: [RFC kvmtool 30/31] arm64: realm: inject an abort on an unhandled MMIO access Date: Fri, 27 Jan 2023 11:39:31 +0000 Message-Id: <20230127113932.166089-31-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756176079469495723?= X-GMAIL-MSGID: =?utf-8?q?1756176079469495723?= From: Joey Gouly For Realms, inject a synchronous external abort, instead of ignoring unknown MMIO accesses. Signed-off-by: Joey Gouly Signed-off-by: Suzuki K Poulose --- arm/kvm-cpu.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arm/kvm-cpu.c b/arm/kvm-cpu.c index 90a15ae9..c96d75eb 100644 --- a/arm/kvm-cpu.c +++ b/arm/kvm-cpu.c @@ -155,4 +155,13 @@ void kvm_cpu__show_page_tables(struct kvm_cpu *vcpu) void kvm_cpu__arch_unhandled_mmio(struct kvm_cpu *vcpu) { + struct kvm_vcpu_events events = { }; + + if (!vcpu->kvm->cfg.arch.is_realm) + return; + + events.exception.ext_dabt_pending = 1; + + if (ioctl(vcpu->vcpu_fd, KVM_SET_VCPU_EVENTS, &events) < 0) + die_perror("KVM_SET_VCPU_EVENTS failed"); } From patchwork Fri Jan 27 11:39:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 49300 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp788201wrn; Fri, 27 Jan 2023 03:46:19 -0800 (PST) X-Google-Smtp-Source: AK7set94JpR2F6DCo5whKSm9Y0AwqZiTUXfArcYTkCT/6MbGS96qC/9lG8T+06yhbGt+kLNdd8Rh X-Received: by 2002:a05:6a20:6926:b0:bc:3523:13c6 with SMTP id q38-20020a056a20692600b000bc352313c6mr2617681pzj.29.1674819978987; Fri, 27 Jan 2023 03:46:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674819978; cv=none; d=google.com; s=arc-20160816; b=uAVorHTtc7rhfqct5KJy3EcfKAn895lrFWGATUnBwsKk/KLtUNX2jbj22QOPuHiowE 7/xytuONXTUNLGkzRmMFEUlyiYL5tcg/XNvkONBAvzAb8MRxTw9dyVg7eLHrKB+879JV V5hPShLNkBBVqfSdaBk0V9SWo/8MGjzsVfa+cHgnlvgqqUkiVB0bTKygomE6tHiYEdIZ uokH38v/rKZqJQqRGg+9DuyQdz7qY6pTLcjXmx4ro9mjqhqEGZ6Kti/It7kgsJDZtJiF C2McG3ppRBEiki7fQ5952ur+alXZdjfya5kZUqZBllKb84j8ggoxKrykD5zvFnl3ob0a CHPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=R29oYkVEb9BroytohBg1GajtHDXmKuwVmqR2/985BpY=; b=zwJ0ko6EhUcLyc9eRvwLHPyXlyjs/DAmTZLLJsvYitYCchLf8tlgcQSNnxyuMLmpZ+ YFuZ/e0frljTNrdM8eb1/Ghi/yCdcAuZeChFjjH7CnwxRrFkmyESY8VKv+TeJNC/8j9s CCPAsjX7Uq83Apx9ifYi7RohpG0XrmMBni4n90NsTAYP31tuTiqhR3AtgARN2Ho3wTxQ ROmBHTjGG7RCF9+tpLK0UHP2ihAd9ASFExVThIjkfaheLJDk1zxrMxQ9FNS0ecE4ULMw Eau5LkSS03CQIO7vddyOPBUdpkGicgiJc2oRnU8EaI1rjPO/A4WLvadjWwXsIlOULNe3 xGMA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i4-20020a639d04000000b004a26c35feeesi4089572pgd.859.2023.01.27.03.46.06; Fri, 27 Jan 2023 03:46:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234013AbjA0LnB (ORCPT + 99 others); Fri, 27 Jan 2023 06:43:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231487AbjA0LmC (ORCPT ); Fri, 27 Jan 2023 06:42:02 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 056107C328; Fri, 27 Jan 2023 03:41:32 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8AE0E169C; Fri, 27 Jan 2023 03:41:59 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 04DDB3F64C; Fri, 27 Jan 2023 03:41:14 -0800 (PST) From: Suzuki K Poulose To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: suzuki.poulose@arm.com, Alexandru Elisei , Andrew Jones , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Thomas Huth , Will Deacon , Zenghui Yu , linux-coco@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC kvmtool 31/31] arm64: Allow the user to create a realm Date: Fri, 27 Jan 2023 11:39:32 +0000 Message-Id: <20230127113932.166089-32-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127113932.166089-1-suzuki.poulose@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127113932.166089-1-suzuki.poulose@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756176034188216757?= X-GMAIL-MSGID: =?utf-8?q?1756176034188216757?= From: Alexandru Elisei We have everything in place to create a realm, allow the user to do so. Signed-off-by: Alexandru Elisei Signed-off-by: Suzuki K Poulose --- arm/aarch64/kvm.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c index 1f3a0def..422dbec2 100644 --- a/arm/aarch64/kvm.c +++ b/arm/aarch64/kvm.c @@ -104,8 +104,6 @@ static void validate_realm_cfg(struct kvm *kvm) if (strlen(kvm->cfg.arch.realm_pv) > KVM_CAP_ARM_RME_RPV_SIZE) die("Invalid size for Realm Personalization Value\n"); } - - die("Realms not supported"); } void kvm__arch_validate_cfg(struct kvm *kvm)