From patchwork Thu May 16 01:06:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong-Xuan Wang X-Patchwork-Id: 1935779 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=TCidUGRZ; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=PiJFrmF9; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VfsNz5Yjbz20KF for ; Thu, 16 May 2024 11:06:25 +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:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id: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=DtgRsPnB219dumWW5a1cp4Qug/KBxWEuoaCKm3ND56A=; b=TCidUGRZiIsb0e gw9kbgfSourlqEWno31I3ccpxXLl1DIJPZZiv4Q3hYmSMMa3DdKhvX+cPSOXbxmJ/h77XXPnY4hDE Z4PST9cLN0+hoUvUtgSOywUKPQQQ5yOQBOGyL7udU9eizAffKcYcCPrne9SGl/0XWEQ7iDWqlOy0M 4UXqmFzThSrHYwaV/OatNWXE/jcb00hqYThlt/jkAlhyc+H+ciLTGyDGpw7J1E/uoJ5GeoO8PRwCR WBxP3MZ26wfMzUok7q2Ijr34OnRMEvJNhm5o7NEJYJvdjyql9n/nCPMM9xfzMEav7ZSttkTtyNLhH 7cazIzR2mAY1ZviRMmVQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s7PZe-00000003Ke0-1Zmj; Thu, 16 May 2024 01:06:22 +0000 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s7PZa-00000003KcY-1oV8 for kvm-riscv@lists.infradead.org; Thu, 16 May 2024 01:06:20 +0000 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1e4c4fb6af3so44643525ad.0 for ; Wed, 15 May 2024 18:06:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1715821575; x=1716426375; darn=lists.infradead.org; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=A/UFcDnnjy3pyeAsdnnlsyXeGMcrQPBnwopB90N131Y=; b=PiJFrmF95viFPsrCYbMwHc4XsRv2SBIMFupD3Ov/pgQ43b3/2dT1eVniIjaBQJouDX dlGQ0jF82CAS24lQh8MFAFlckDR978/lUrZ2aDxFhdo3zfDapqfSk+KZqunCgCaPBU35 +O6bxOvwrS8SUhC/JQN0g1UP1pJLjNj1qo8r7AUdgJfT2UYgtuf8NwUeM1bgT1u53CIF z96LR1s9nu0mWNS6MRMJmtNZNJdORBt6D61ez7cD/H2uyGWzSQurXXwEoc8hCUO8oQjv tUVgaJs1mLXM9NRgqNWc2dYcaAjhRYkE5W5Ws2iDhfPLwSvRZtpHPMjYAsRqCYztBQMq 9j0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715821575; x=1716426375; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=A/UFcDnnjy3pyeAsdnnlsyXeGMcrQPBnwopB90N131Y=; b=QuWsVVvJ/MhbgrkxvGwYKOU7GNddXYQif9gKbIL0V4IFAR7ln66dI5TQ4q5qbuHa/S ja0ax6DQEpwHdiJu9bHYYt7b1kCNFXk7uDAnlQnhIgpWXgn9zLfCB6OL+qh2ufncU7XV G9cXHyMRHBR1jKGX3qo0VmEH82vVkQcXhmXPWRphn4kRbZaC0YgI7uWuuPTGrTKFn+iD Pnqmd8xkFBgWC8GfEonF0AAODAjhid1EddlKEi3Sa4XNf7pJaUMImd+o3992p1HCxbsh ujRDqj1x2atSlPodZ4NMggP2iib+/5teWajY7+gNA6mbyLCMwyJFv4c8lPVVGKp5kjGa IQ1g== X-Forwarded-Encrypted: i=1; AJvYcCUBjZBcf7B8i12KSvXf9EJgrqni8B9BuKxroMYhes2mq2qhaPXMR+TbUACywaI3qjULyJUEKDklMy+i6czNj3EnKt4U1xjW97J29Hc5mg== X-Gm-Message-State: AOJu0Yw5zBkOL0uxuTBYjCAjL5BqFQ9TisS5vimapQwRr5T43fZX9f3H eqcYJhHvi+nU/4dGUAeaKOEDk6fKw2OPNqtVPGLw5i0jU0HMCWti1Ju65TDT9NU= X-Google-Smtp-Source: AGHT+IFWQCLfM9nDqO4/Vzf0Qykfi/rGKbCui2qknji+9I132i+xvtmVL4rM7HV3QXYTYGm9mnJRMw== X-Received: by 2002:a17:903:120d:b0:1e3:cf18:7464 with SMTP id d9443c01a7336-1ef42d69b44mr229915525ad.3.1715821575542; Wed, 15 May 2024 18:06:15 -0700 (PDT) Received: from hsinchu26.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f0cb2141b0sm2054875ad.285.2024.05.15.18.06.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 18:06:15 -0700 (PDT) From: Yong-Xuan Wang To: linux-riscv@lists.infradead.org, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org Cc: will@kernel.org, julien.thierry.kdev@gmail.com, apatel@ventanamicro.com, greentime.hu@sifive.com, vincent.chen@sifive.com, Yong-Xuan Wang Subject: [kvmtool PATCH v3 1/1] riscv: Fix the hart bit setting of AIA Date: Thu, 16 May 2024 09:06:10 +0800 Message-Id: <20240516010610.30013-1-yongxuan.wang@sifive.com> X-Mailer: git-send-email 2.17.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240515_180618_572497_9E43CDDC X-CRM114-Status: GOOD ( 12.81 ) 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: In AIA spec, each hart (or each hart within a group) has a unique hart number to locate the memory pages of interrupt files in the address space. The number of bits required to represent any hart numb [...] 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 [2607:f8b0:4864:20:0:0:0:636 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 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: , MIME-Version: 1.0 Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org In AIA spec, each hart (or each hart within a group) has a unique hart number to locate the memory pages of interrupt files in the address space. The number of bits required to represent any hart number is equal to ceil(log2(hmax + 1)), where hmax is the largest hart number among groups. However, if the largest hart number among groups is a power of 2, kvmtool will pass an inaccurate hart-index-bit setting to Linux. For example, when the guest OS has 4 harts, only ceil(log2(3 + 1)) = 2 bits are sufficient to represent 4 harts, but we passes 3 to Linux. The code needs to be updated to ensure accurate hart-index-bit settings. Additionally, a Linux patch[1] is necessary to correctly recover the hart index when the guest OS has only 1 hart, where the hart-index-bit is 0. [1] https://lore.kernel.org/lkml/20240415064905.25184-1-yongxuan.wang@sifive.com/t/ Signed-off-by: Yong-Xuan Wang Reviewed-by: Andrew Jones --- Changelog v2: - update commit message v3: - update commit message --- riscv/aia.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/riscv/aia.c b/riscv/aia.c index fe9399a8ffc1..21d9704145d0 100644 --- a/riscv/aia.c +++ b/riscv/aia.c @@ -164,7 +164,7 @@ static int aia__init(struct kvm *kvm) ret = ioctl(aia_fd, KVM_SET_DEVICE_ATTR, &aia_nr_sources_attr); if (ret) return ret; - aia_hart_bits = fls_long(kvm->nrcpus); + aia_hart_bits = fls_long(kvm->nrcpus - 1); ret = ioctl(aia_fd, KVM_SET_DEVICE_ATTR, &aia_hart_bits_attr); if (ret) return ret;