From patchwork Mon Sep 19 13:37:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1679426 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=KAsrnLrT; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=INFzW0vm; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MWQhr3Vpzz1ypH for ; Mon, 19 Sep 2022 23:37:32 +1000 (AEST) 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=eJbjsb5JdtHJh2ckBlpIMq44krui4gmA+X620cZ5+EE=; b=KAsrnLrTdeF2EI D6E1DQUPm6X4BCV5OjmYDp6RMGn7EsTWAo75oIIqsFpQXGusAZguh8EC1FDm6O5rUCVU7P651pA3D H6SzANInFTcdcQrHuSMzuizmxhBWZNTcinZgwERzfHi9s4ZC90iKTcrvKkNcy9C2IUFeoAeIrZgrM ptbm5ahRS8N33iIyZcGeQgsiODdP3HgLKDfD9LKy4G0RV/7BjeznYbH2Ny5ulhPgyX7xnkH84ALzM GgPjyCzjrr9lSiQ+QbWZBK9OHFyEA6mbW9Fnor98+S8zgNTBEeu8LKgRDPKSI7FTLpNByX45j1ego hDR09N5N0lZE+tOXP9kg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oaGxk-00BtzV-1W; Mon, 19 Sep 2022 13:37:28 +0000 Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oaGxf-00Btx4-9x for kvm-riscv@lists.infradead.org; Mon, 19 Sep 2022 13:37:24 +0000 Received: by mail-ed1-x52d.google.com with SMTP id w28so17374519edi.7 for ; Mon, 19 Sep 2022 06:37:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=ppfLIjxYzL5rc+S/H9knNqD42yvhK86QXUmy4drwhbA=; b=INFzW0vmbEhyPNzazs70pZZ0uTo79T/q2yqypvoCWURS4CbFlgTO3FJu1xDkFviQa3 eCBmRFvcWcRgrVfoNphhZ1aHpujbnmosdvUDEoHjBYcZnw2iE77V8GxJhcRqVURnm8Bk 7aJg+05hywIzkU132BQTTmC6dyEzaFGt0zudWx5A7MYRwDAR/EGnh1E+sS+U27VPo6eR SzZtJ8blsw1tSb+qeQ0ZKCwsN/vN6WMQpCtKRpORGHRZaXREoyh0oy8OFW/XvFOG/tNo xFZN9fDMJFe9IdVMAeai6ufYrBM8w2fkt3727UwNVw7bQBn+1mT18M0awZ0nY8H+/iMU fSyg== 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; bh=ppfLIjxYzL5rc+S/H9knNqD42yvhK86QXUmy4drwhbA=; b=T2EBl2zV+y6xX8510VeKNJqsr9iBjj9Qz7RXM/oFAPzpyu+zDDUkbTz4hVm5pQe+xt jtkzJU2OQH77AJaT8f1yDC+LR4STLfXMOkxwn1L7PscBPlBoB/3BAS5jjzo2OtNgCo+C H1VoeRRW1HAb7osv3JkkjByFEOtoQghgTABquASqa8iIpCxdTkWDhpozdC0/8743vwDq hSs4/Zbdd8SUhN7fh6ngCNrdDOQIe8kdmRjNMoxa4oRdEc1/844pTytxR+QYWLEr511e 8Ib89rX8UT0V8kaJqgod69iPHuOn00f975RWmeztRqB8KFxuqOe1VhmcndgtmpF0YEDD drtA== X-Gm-Message-State: ACrzQf2Qmv4jak87H1vwKgzaUNq9XQrESuaiDu2N/6maEdWeC/iCQl4R 8+XQKNy6ODwC/qCgLIoqRijVKu+whorHTg== X-Google-Smtp-Source: AMsMyM4ZezYll5/dsWHSItGp0PT8HxYRAasZ/o6lu50/t5DS3t8GEPVvke7Pcm5hBF1TJKr7S4H+Ug== X-Received: by 2002:a05:6402:b6c:b0:44e:2faf:1ba4 with SMTP id cb12-20020a0564020b6c00b0044e2faf1ba4mr15640788edb.191.1663594640685; Mon, 19 Sep 2022 06:37:20 -0700 (PDT) Received: from localhost (cst2-173-61.cust.vodafone.cz. [31.30.173.61]) by smtp.gmail.com with ESMTPSA id lb6-20020a170907784600b0073d9630cbafsm4929446ejc.126.2022.09.19.06.37.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Sep 2022 06:37:20 -0700 (PDT) From: Andrew Jones To: kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org Cc: anup@brainfault.org, atishp@atishpatra.org Subject: [PATCH] RISC-V: KVM: Make ISA ext mappings explicit Date: Mon, 19 Sep 2022 15:37:19 +0200 Message-Id: <20220919133719.230337-1-ajones@ventanamicro.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220919_063723_456139_6E59E0DB X-CRM114-Status: GOOD ( 10.92 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: While adding new extensions at the bottom of the array isn't hard to do, it's a pain to review in order to ensure we're not missing any. Also, resolving merge conflicts for multiple new ISA extensions [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:52d listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org While adding new extensions at the bottom of the array isn't hard to do, it's a pain to review in order to ensure we're not missing any. Also, resolving merge conflicts for multiple new ISA extensions can be error-prone. To make adding new mappings foolproof, explicitly assign the array elements. And, now that the order doesn't matter, we can alphabetize the extensions, so we do that too. Signed-off-by: Andrew Jones --- Applies to riscv_kvm_queue arch/riscv/kvm/vcpu.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c index 0de0dd22e734..61fe1604e8ea 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -42,19 +42,22 @@ const struct kvm_stats_header kvm_vcpu_stats_header = { #define KVM_RISCV_BASE_ISA_MASK GENMASK(25, 0) +#define KVM_ISA_EXT_ARR(ext) [KVM_RISCV_ISA_EXT_##ext] = RISCV_ISA_EXT_##ext + /* Mapping between KVM ISA Extension ID & Host ISA extension ID */ static const unsigned long kvm_isa_ext_arr[] = { - RISCV_ISA_EXT_a, - RISCV_ISA_EXT_c, - RISCV_ISA_EXT_d, - RISCV_ISA_EXT_f, - RISCV_ISA_EXT_h, - RISCV_ISA_EXT_i, - RISCV_ISA_EXT_m, - RISCV_ISA_EXT_SVPBMT, - RISCV_ISA_EXT_SSTC, - RISCV_ISA_EXT_SVINVAL, - RISCV_ISA_EXT_ZIHINTPAUSE, + [KVM_RISCV_ISA_EXT_A] = RISCV_ISA_EXT_a, + [KVM_RISCV_ISA_EXT_C] = RISCV_ISA_EXT_c, + [KVM_RISCV_ISA_EXT_D] = RISCV_ISA_EXT_d, + [KVM_RISCV_ISA_EXT_F] = RISCV_ISA_EXT_f, + [KVM_RISCV_ISA_EXT_H] = RISCV_ISA_EXT_h, + [KVM_RISCV_ISA_EXT_I] = RISCV_ISA_EXT_i, + [KVM_RISCV_ISA_EXT_M] = RISCV_ISA_EXT_m, + + KVM_ISA_EXT_ARR(SSTC), + KVM_ISA_EXT_ARR(SVINVAL), + KVM_ISA_EXT_ARR(SVPBMT), + KVM_ISA_EXT_ARR(ZIHINTPAUSE), }; static unsigned long kvm_riscv_vcpu_base2isa_ext(unsigned long base_ext)