From patchwork Thu Jan 12 02:38:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13097383 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0DCB4C46467 for ; Thu, 12 Jan 2023 02:40:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=ucMeLKE2FmT3MRNFHh+XLj5B8SpI7G+jNIt9NiO0Vuc=; b=sO8QLExAmXNuUE y78PCn07gKS/iC01m0+9Rt6prDBBnB16hFZqAbZ8/hFIxakaUvZXdRsNKXTB5npq1/kcEpB6cE7Ub 6bdaivmr3+V3ZN7owW19295C1UdF/3V4K0EOxAccM0Mrlc8mt3e1frMxgZYCuCxCtVV//NCfUcatO BSRItI0JyhRcgCGneGsPr/S+iUz1bZVCVKibqkGg95p/Hw6es5A2eILc6WABu85FkoxEXCYRUhT3v sE3k7EpSnpO5z4Tdqx0v0BxY1IMEOXN4cZ4blLS3ltGEZWY/fTfb0UpmpaB34PdNeGukSsieRm+vi KTDHklT6ARbBue41ij6Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFnUp-00DStJ-Qd; Thu, 12 Jan 2023 02:39:15 +0000 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFnUl-00DSqk-C8 for linux-arm-kernel@lists.infradead.org; Thu, 12 Jan 2023 02:39:13 +0000 Received: by mail-pl1-x634.google.com with SMTP id s8so10492018plk.5 for ; Wed, 11 Jan 2023 18:39:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=k83D4cHet6xxSauwnXBAG2POGQDSG6eAKHoaOWKO0ZM=; b=HBHPRSkefxSL8v/u0WI3RXGK8TGWvBs9nWl0eAN6b2r3P/L5A0AHOW8k+WNlNXljiA xcBm7wjPg/EbuBJAaGK6fXmY1J99aLHf2ygMD4Ckkm5bZqFjjM6jm6yr1tg9BHpFyBU0 r3SZWa5xMt7w6fSPXq70t5UyNqDOUpXK5fucMnX+sRjFj6OGzvUeZKRJtYA4imZdpC15 RiJw9c0KYYLbr6ilHj99I/BGqslESPEHZM66/T1Uxls26qk4KKAZzb4XrwUYzsiXMGct N7ocX5rmVHAANjUVEMpylwE/OwUabgBkdVPmqiw4HmJxTNN7/PpzCgckFbi7PsfJA76L wbMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=k83D4cHet6xxSauwnXBAG2POGQDSG6eAKHoaOWKO0ZM=; b=ojLMrKo9M6QYGVY+k7Yr6HA1zJYDoFzYb81W4/DXz40AAJeh56tV99Y9AOVDLMihC4 Y7O7E7kTQNgnxltV+K62QqQHRQkjDo/8qdcnmqZGxxp+vvGRzHdgEALoAiFDzccTS/eF E9DgAPdBD08JET6utGh9v9yIMH1l643gr3b1q4HynOV+u25346w9BcXeG3guPGNxmnz9 FS1E6TMw2QHFd7Dfg4lRGVhpNerDPa4hy8u3hBr1XalFFQkrD/qT0DdukgURD91O3bmA kwTreqf9/NDrWidEh/UiAd6mChquIOkxJwDXwMbIY3eYKpFlGK51rWaKPmW5FFg19nHE x9fA== X-Gm-Message-State: AFqh2koxFXatZMH/D+C+NsgB8yTT5APg3Yzb5JrDYdJBUu+OWCVRGWLv 4IliocB3mB5l+IdvGUauQ6L5WA== X-Google-Smtp-Source: AMrXdXuarUuj+dnpfbLqlXdbjMkbC9/UcAPU+8TqzLcL101PU3o/EcvUpOQA1ixTQMd2bjFz7Yttag== X-Received: by 2002:a17:902:c102:b0:192:8e05:1505 with SMTP id 2-20020a170902c10200b001928e051505mr57871834pli.31.1673491146515; Wed, 11 Jan 2023 18:39:06 -0800 (PST) Received: from fedora.flets-east.jp ([2400:4050:a840:1e00:d54:e521:8bac:7bed]) by smtp.gmail.com with ESMTPSA id w7-20020a1709027b8700b001944b1285easm2310331pll.198.2023.01.11.18.39.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jan 2023 18:39:05 -0800 (PST) From: Akihiko Odaki To: Cc: Mark Brown , Marc Zyngier , linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, Mathieu Poirier , Oliver Upton , Suzuki K Poulose , Alexandru Elisei , James Morse , Will Deacon , Catalin Marinas , asahi@lists.linux.dev, Alyssa Rosenzweig , Sven Peter , Hector Martin , Akihiko Odaki Subject: [PATCH v7 0/7] KVM: arm64: Normalize cache configuration Date: Thu, 12 Jan 2023 11:38:45 +0900 Message-Id: <20230112023852.42012-1-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.39.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230111_183911_645765_EE51406E X-CRM114-Status: GOOD ( 13.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Before this change, the cache configuration of the physical CPU was exposed to vcpus. This is problematic because the cache configuration a vcpu sees varies when it migrates between vcpus with different cache configurations. Fabricate cache configuration from the sanitized value, which holds the CTR_EL0 value the userspace sees regardless of which physical CPU it resides on. V6 -> V7: - Make the code to determine cache line more readable. Based on Oliver Upton's suggestion. V5 -> V6: - Add a comment to get_min_cache_line_size() V4 -> V5: - Noted why cache level existence check is unnecessary when fabricating CCSIDR_EL1 value. - Removed FWB check. It is necessary as CLIDR_EL1.{LoUU, LoIUS} on the host are {0, 0} if FWB is enabled, and such a CLIDR_EL1 value sets the IDC bit of the sanitized CTR_EL0 value, which is already checked. - Removed UNDEF injection when reading CCSIDR_EL1 with an invalid CSSELR_EL1 value. - Added a check for CLIDR_EL1.{LoUU,LoC,LoUIS} values set from the userspace. V3 -> V4: - Implemented UNKNOWN system register definition for CCSIDR_EL1 - Added a comment about the relation between CCSIDR_EL1 and FEAT_CCIDX - Squashed "Normalize cache configuration" and "Allow user to set CCSIDR_EL1" The intermediate state between them did not make much sense. - Introduced FIELD_GET to extract CCSIDR_EL1_LineSize. V2 -> V3: - Corrected message for patch "Normalize cache configuration" - Split patch "Normalize cache configuration" - Added handling for CSSELR_EL1.TnD - Added code to ignore RES0 in CSSELR_EL1 - Replaced arm64_ftr_reg_ctrel0.sys_val with read_sanitised_ftr_reg(SYS_CTR_EL0) - Fixed vcpu->arch.ccsidr initialziation - Added CCSIDR_EL1 sanitization - Added FWB check - Added a comment for CACHE_TYPE_SEPARATE - Added MTE tag cache creation code for CLIDR_EL1 fabrication - Removed CLIDR_EL1 reset code for reset caused by guest - Added a comment for CCSIDR2 V2: https://lore.kernel.org/lkml/20221211051700.275761-2-akihiko.odaki@daynix.com/ V1: https://lore.kernel.org/lkml/525ff263-90b3-5b12-da31-171b09f9ad1b@daynix.com/ Akihiko Odaki (6): arm64/sysreg: Convert CCSIDR_EL1 to automatic generation arm64/sysreg: Add CCSIDR2_EL1 arm64/cache: Move CLIDR macro definitions KVM: arm64: Always set HCR_TID2 KVM: arm64: Mask FEAT_CCIDX KVM: arm64: Normalize cache configuration Marc Zyngier (1): arm64: Allow the definition of UNKNOWN system register fields arch/arm64/include/asm/cache.h | 9 + arch/arm64/include/asm/kvm_arm.h | 3 +- arch/arm64/include/asm/kvm_emulate.h | 4 - arch/arm64/include/asm/kvm_host.h | 6 +- arch/arm64/include/asm/sysreg.h | 1 - arch/arm64/kernel/cacheinfo.c | 5 - arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 2 - arch/arm64/kvm/reset.c | 1 + arch/arm64/kvm/sys_regs.c | 274 +++++++++++++-------- arch/arm64/tools/gen-sysreg.awk | 20 +- arch/arm64/tools/sysreg | 17 ++ 11 files changed, 230 insertions(+), 112 deletions(-)