From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C5B3416139 for ; Tue, 11 Aug 2026 08:21:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786436475; cv=none; b=hWswV7k0DTGBAX1/hdLhpJ3NB0IqIjh9y2J02clPXApdETyCy4PQRzHBK17YfgD15D28eICH7jXEQg5wF8zsf1k8oxY+b3gYOXIUN5K8SjmmDABEt5vU87rvACrYZv5WcQUz/wNpmDdi8BU8IdTUh10NQakW+9KQURRfC9Eag1I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786436475; c=relaxed/simple; bh=Dkmbdh2ognbJLDvpaxMc8rYRxPmKmy9BFi7VABC3oPI=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LAjPy2fdJXHwtJsSstkDhVMx+aTpDH09NHi9X7XxuTXxCPUwk+OC7AtQRvtF+AZ9WtI7GX0xXhljoEAGV+MlOFyUDAEwkQG2171EjZmfNg61aeTt4UxUe6+LpcAA4DxHneYDiU/nxMWkUwzURvAg5ZL2bHYyT6CdUt6ZSMcwkSI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Vo7S6ALI; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Vo7S6ALI" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4995b0343c1so24673535e9.3 for ; Tue, 11 Aug 2026 01:21:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786436469; x=1787041269; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=PsVqbXfj6KXdZCKzed0xiDF5HlCoWH45JjgsepkCfGY=; b=Vo7S6ALIG5hH4bquBI/cbDA0HCUS6Wnb7Txkoj9IVFG4t1VcRkLWGeAozSDvkLM2L0 HZ5IHXWgEBF293CXH9HQeStYd4vcLnUUYN7iN1Z9eK/hjx5CUUIWxwnpZy7aRM+L32O6 pAqSqPV+TlJt2gOXN6qy6geV5yALvIc2RTxYg7rTEaBhb04jqp1Wln5HtQmW6pxwSVaA vugHhY9M+HzU90u5398FEWeH2lIILCFx2w8LUNWEY/ebi4iAfuaj3TPMO+MnZHas+AV+ W7Z4rjLNImEeCDhdsoj33+yS61BVpCo5c6CgO6cpd+XsKB9iZ4igkVjj9UeyJqeN8puE VGpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786436469; x=1787041269; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=PsVqbXfj6KXdZCKzed0xiDF5HlCoWH45JjgsepkCfGY=; b=Rj33Ov1hWgi4qDqBNIi6uF70S+qR5ED48ZYdO8CIDqmgmhAtThzrmcSlcn8wEpT6vy VdAhn4Jx+4dZbW+UY1Y5SFlH7KdIO8BGI3L4iQ3X89EckyOa1ZstGAmaQ+QN8LkQFqBh vKndheBYrvjNjIhVFHCP/GNaMVwkiM/trSDyGdPn6InJDnqxVKaBG2VQxvojkWC0zobV r4b6yEWhIWQe5c+CEqJJ7FaVGG4zGRUevztEh7yQTleNXvMNdCO0QK0gdxoa2Fjsr7PU m5+F50ciiUSoEKQLvwaBN8mHGuVj1QOMBQsyAPxcCRbdiE/f8zMVSYIoB9hMPOlfQXu/ L9Cg== X-Forwarded-Encrypted: i=1; AHgh+Roe62cj47hE5prCgPVUd2HPNpduoDJuPpaLSwcHR0jamJ39N5+Uo91aX0ECbny8Td/kafAbd4Q8NrYh4Lc=@vger.kernel.org X-Gm-Message-State: AOJu0YwD/9uCVGVNCWIs6ptocFZbDzmmMPDgQ1niXemXnJIy8Enkh+p1 ZGyZM5tToFJ8ssXga9rnXFE9xMKkqDQk/jNjhr2WI5dMRpqjXLxsyf4d X-Gm-Gg: AR+sD13qRL7w2uTLckIBME2aUJM20I49fuxwkPt+xoEl0hsu96Xdvre56bO5KdLElqd 9uhuYzSkA1k6JeO/vvFTbVxjoGf+T46fkl3xcIo1EvvlQ2xH2GRWD1dU9RdK/VVKfYXfIe8nIEE DfPy4Py1AGTbqz9Ynnz8k4TgfBL70dInlqapQ4OkhmuMV3H8YYBi7N5MCHYr8afunNGYIrhHZOf +rfI+R4jN+iTuV4Ca3M3vRydjK20SwZYO2z+F3sf3V7gRvH0U8rgizSmdAyNRFSf6etB2sLCLCr ySlN4AfaYywvds8TmqgDm72CwGfOVO+n/mVkE1BqJpslrnILAPFUq1UfzZQlPbdn166QnvUdp07 7kU1Lo3pL+Rg1BIM6jyJzFl2cwzbkoRQ/cZKjVqxPQ5KwBJhKYbW3q+ngJovpI/AWCiNsak5OTB IPsRG1NfbIsMKAW9tRNLp++eH5SccNPxZEVnSP1qEfKaCHwIy5D+PjMFDVZl4+agdydBzyLd8Mt 77CCBeKlyVwseMe84T8+gaXXA== X-Received: by 2002:a05:600c:3b9e:b0:499:795a:c60b with SMTP id 5b1f17b1804b1-499795ac6e4mr7851195e9.19.1786436468951; Tue, 11 Aug 2026 01:21:08 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-499740dbb03sm50158035e9.8.2026.08.11.01.21.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2026 01:21:08 -0700 (PDT) Date: Tue, 11 Aug 2026 09:21:07 +0100 From: David Laight To: Yazen Ghannam Cc: Jason Andryuk , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Ingo Molnar , Mario Limonciello , Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org, Penny Zheng , stable@vger.kernel.org Subject: Re: [PATCH 2/2] x86/amd_node: Avoid divide by zero on virtualized systems Message-ID: <20260811092107.37ef648b@pumpkin> In-Reply-To: <20260810144706.GC57095@yaz-khff2.amd.com> References: <20260806160159.230453-1-jason.andryuk@amd.com> <20260806160159.230453-3-jason.andryuk@amd.com> <20260810144706.GC57095@yaz-khff2.amd.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 10 Aug 2026 10:47:06 -0400 Yazen Ghannam wrote: > On Thu, Aug 06, 2026 at 12:01:57PM -0400, Jason Andryuk wrote: > > On a virtualized system, the number of nodes does not have a > > relationship to the number of roots. A Xen PVH dom0 can calculate > > roots_per_node as 0, which crashes with a divide by zero in: > > > > if (count++ % roots_per_node) > > > > On a virtualized system, default the value to 1. The issue is seen with > > Xen, but it could affect other systems. > > > > Fixes: 0a4b61d9c2e4 ("x86/amd_node: Fix AMD root device caching") > > Cc: stable@vger.kernel.org > > Signed-off-by: Jason Andryuk > > I agree with the idea with some minor feedback below. > > > --- > > X86_FEATURE_XENPV is only for PV, but this is observed with a PVH dom0. > > --- > > arch/x86/kernel/amd_node.c | 5 +++++ > > 1 file changed, 5 insertions(+) > > > > diff --git a/arch/x86/kernel/amd_node.c b/arch/x86/kernel/amd_node.c > > index ea553267e5fa..c5025e5291b6 100644 > > --- a/arch/x86/kernel/amd_node.c > > +++ b/arch/x86/kernel/amd_node.c > > @@ -286,6 +286,11 @@ static int __init amd_smn_init(void) > > return -ENOMEM; > > > > roots_per_node = num_roots / num_nodes; > > + if (roots_per_node == 0) { > > Can be '!roots_per_node'. > > > + if (!cpu_feature_enabled(X86_FEATURE_HYPERVISOR)) > > + pr_err(FW_BUG "Error detecting roots per node.\n"); > > + roots_per_node = 1; > > + } > > I don't think this is necessarily a Firmware bug. > > Likewise, it can be a 'warning' rather than 'error'. I interpret 'error' > as something known to be incorrect. This was my position before on this > topic. But the various contrary reports changed my mind (even if they > come from virtualization). > > Furthermore, I think 'warning' is more appropriate. It says "We found > something unexpected. We're letting you (the user) know about it. And > we'll mitigate it to avoid an error." > > Anyways, I just wanted to write out some thoughts since this topic has > come up a few times. > > Possible rework for the above change: > > if (!roots_per_node && !cpu_feature_enabled(X86_FEATURE_HYPERVISOR) > pr_warn("Expected at least 1 root per AMD node.\n"); > > roots_per_node = max(roots_per_node, 1); I'd not add the max(), just; if (!roots_per_node) { roots_per_node = 1; if (cpu_feature_enabled(X86_FEATURE_HYPERVISOR) pr_warn("Expected at least 1 root per AMD node.\n"); } David > > In any case, we should just go with a simple fix for the virt cases. > > I think we could even do away with caching the 'root' devices. But > that'll be another rework/cleanup. > > Thanks, > Yazen >