Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp1319113lqj; Mon, 3 Jun 2024 18:44:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUX+/QU3HIWqERnxWCbY62ms488J94PfxvFjvoeBp0Co6MB9eB+m3hrbKW982QXiqx2Qq8eTmGIqWU2go1nRgBqxFFNzkD1XRrjU91Ycg== X-Google-Smtp-Source: AGHT+IE2Tmvoy6lSBaaSkfJvOksgdRiNVyVJPDuaRuu9VCIBsT0pIpZRC2aqyNp5tOqEb3EAEgII X-Received: by 2002:a05:620a:26a3:b0:794:9639:1702 with SMTP id af79cd13be357-794f5c973f2mr1318598285a.36.1717465464766; Mon, 03 Jun 2024 18:44:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717465464; cv=pass; d=google.com; s=arc-20160816; b=ZQfKPU2wlWcS5bdc7xGuc8ogkDH1c27TK3qwunfJxlevLOMop4Cr1nisQMiGwWxmNC 53Yv4sYygBqGTWrwOZy51L04GVMdh8euIagqfhd9Gch9BpsEd/7oVTvXkW18IBG/Bb3f dVbr9812gTenD1Gf8LwFwQOwLW7ov4/wkr+onz78YrXGffnzdEFvGSkGgWHeRfcUBNNt K0KZP5/C1svjd8Iz0v7KFxmwfeFfhg7je162625m99Lx3uMPB87yh3/wbbYqLm/vqHEF 5vkYE8MiopRyfoK+6ogsHSXmU8SQGXzGF1qIIcET7lMf04aB5h7qUEsjlBIAJsLGpVVa bKww== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:to:from :sender:dkim-signature; bh=H6Tf1Riu9q7Xz/KLQjcwHxW5z7Z6dmOlmlHHwP+1DzQ=; fh=R9LxaON+CVrhjV0En/TIQF7uAscfcjgYFz2G5X7rnV4=; b=Y+WW/+0KDn3NekzzdEWpLBAO3loMdgF2SX216quRbBjK1vx/EEAkrLOI/sGgIfBbI8 qFj9pZpAP3jSkR0fk4M5gC+1GN9T/HM5Wffx/VGFkm0P6mF5aGt+AN/o+raf0qXFjrWG Q5VxMYjdO2EraxeXF77+u1y3AJKw7btaChkzBK+w0yeXZh1mwxInTbb4V+W8XDYQ57S6 nJ2HA9r2mY+Y8vLOriSAojWwu3MufQ4tgsRXOPuZIcm3AzGiM1rt9/5ma8viAlRN6grL RCjzj08V0PY8dVlY0bi9nJWvopYl9mHn4r76dFx4dStmYPr61u+fmyCPElMMSC7kaw6m SYmw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=XSHG+sdb; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-199911-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199911-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-794f3064a56si1066550485a.255.2024.06.03.18.44.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 18:44:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-199911-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=XSHG+sdb; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-199911-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199911-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 7E4D51C23204 for ; Tue, 4 Jun 2024 01:44:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 164D613D29B; Tue, 4 Jun 2024 01:44:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XSHG+sdb" Received: from mail-oo1-f53.google.com (mail-oo1-f53.google.com [209.85.161.53]) (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 63E324A07 for ; Tue, 4 Jun 2024 01:44:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717465458; cv=none; b=mzwT64AlbKoHqPY0X2MQx/US5hpDPPPBqTg4HZ0Tw5k5IzW6Ba2fM9tRqKfpKYSyEAcwJufbaQJBY2Kzf4TWxcbRbLtUfUUhPz+o5PP89gdJch3VDNTm0SPQ1G5K6i1La1ujRHNyHKFwr9npBEJdiGnOefiCnyF7Pk3b7Hgp7Go= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717465458; c=relaxed/simple; bh=tgQUXAbqpX3U94aO6x/D2MmQFKzuA8RjZ0MFTCQwJeQ=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=few3HV6OtOY+QPYrHQYiMBCb8i9FWDWUJfvKGPM6C3vRFRJUhPUFctP6U1BcHHQ7zictfQscas2ghwVLdX/5QFp/pg7uMIeUbViQPn6Q/NuVEYI3RyYSTigrBRdVmr+lsNnhfmAEqDSHmmKn9sIJYimGtMfN26ifSS86Uy/QGbs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XSHG+sdb; arc=none smtp.client-ip=209.85.161.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oo1-f53.google.com with SMTP id 006d021491bc7-5b9c7ae2c98so304941eaf.3 for ; Mon, 03 Jun 2024 18:44:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717465455; x=1718070255; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:sender:from:to:cc:subject:date:message-id:reply-to; bh=H6Tf1Riu9q7Xz/KLQjcwHxW5z7Z6dmOlmlHHwP+1DzQ=; b=XSHG+sdbuyhnT6k1lcZdsEL8k7ryIEzJmw5PEEhfbVYx4IGJGJQsn0BYMFk1zITazP I/eUF7Upc7ADtFvq+O2yZ/bEZXg6LWXpXDP5xPFBINKyxWEbsqKuiCCO/MSBGu+wDwPX JfeRCulnR9JE/lTM40ojce8Q6ERZZ8bI6pgQtGaNZ0D7W7sVlklj+JkS0azKOK+W3qFv DRLIqPYfPvgqhNYr1RclU6+FY3FuOE0AWJnHJxjDJHoZi3bd3WDFFWLgNDuotnWU0JxS iKNLqQ6JOO2PCTp5UC5W3hGrqKsvTIk0N3L8ujiSRs3L2AsOR0ABhm1lE4Kgf1T+e89I 1L9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717465455; x=1718070255; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=H6Tf1Riu9q7Xz/KLQjcwHxW5z7Z6dmOlmlHHwP+1DzQ=; b=LooW2/bf6fOxAT/YVqFdb6TokhyENH4l1aN/TdjGT/nUjjUlmFmTgJRVOfe/8iHBbc PEWUAZIB3F12YsIs1Mu4WIb+G5ccdBNHg3JR2lWqWRS7b8VHDptYamo+F4GSx1e9oxBx L8pfGnE8eXH/f3zcWWsvkPnX5vKkoN7+J9X6roHiDeT5yfM5x7WezUHN6R2sbiFjZeJ1 cs3M5uk5QfKcp5o7uLViA6u/y2+XksGGgjnlMGPZR/5ZcG/uzJnp2i7jgHRTcyDEOpiT fp3ssu6Kz7x3jn1vPLf70dVhuKEyMtzv3Rd0bBNmKn9l89jh680gXqcb61LqL3iJUVlV /LUg== X-Forwarded-Encrypted: i=1; AJvYcCUNqB3d238q2qjImACpNZxmEt8TZbgMsKZOSEd27E+Gbh9k7ADh0/ljxoXI8Kp0d0OMrQgRUzJXjbla50HnfF+pv/uj+YtVKyxR8+jI X-Gm-Message-State: AOJu0YyINoootQ+ykwQM64IKD7j9heyQK8GnAxyq8vO/dbs8EMiMccj8 D91ZxRIfy5Gueh27+tqAXjNgR+tWWxknYr+pldUsFhlrtdtXo1Gg X-Received: by 2002:a05:6358:708:b0:197:8ee2:4ce2 with SMTP id e5c5f4694b2df-19b490d719fmr1345888555d.21.1717465455211; Mon, 03 Jun 2024 18:44:15 -0700 (PDT) Received: from localhost (220-135-95-34.hinet-ip.hinet.net. [220.135.95.34]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-6cb90510a45sm2396637a12.29.2024.06.03.18.44.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 18:44:14 -0700 (PDT) Sender: AceLan Kao From: AceLan Kao To: Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org Subject: [PATCH] x86/mm: Simplify conditionals in PGD synchronization functions Date: Tue, 4 Jun 2024 09:44:13 +0800 Message-Id: <20240604014413.694442-1-acelan.kao@canonical.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Chia-Lin Kao (AceLan)" This patch streamlines the conditional checks within the sync_global_pgds_l5 and sync_global_pgds_l4 functions. Previously, the code redundantly checked both reference and target PGD/P4D entries for existence before proceeding with further actions. This redundancy is unnecessary since the existence of the reference entries is implied by earlier checks in the code flow. By assuming the reference PGD/P4D entries (*pgd_ref and *p4d_ref) are always valid within these conditional checks, we simplify the logic to only check the target entries (*pgd and *p4d). This change makes the code easier to read and understand while maintaining its original functionality. Modifications: - In sync_global_pgds_l5, removed the redundant check for pgd_none(*pgd_ref) when asserting or setting *pgd entries. - Applied a similar simplification in sync_global_pgds_l4 for *p4d and *p4d_ref checks. This patch does not alter the functionality of these functions but improves the clarity and efficiency of the code by removing unnecessary conditions. Signed-off-by: Chia-Lin Kao (AceLan) --- arch/x86/mm/init_64.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index a0dffaca6d2b..ed964bd081f8 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -155,10 +155,9 @@ static void sync_global_pgds_l5(unsigned long start, unsigned long end) pgt_lock = &pgd_page_get_mm(page)->page_table_lock; spin_lock(pgt_lock); - if (!pgd_none(*pgd_ref) && !pgd_none(*pgd)) + if (!pgd_none(*pgd)) BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref)); - - if (pgd_none(*pgd)) + else set_pgd(pgd, *pgd_ref); spin_unlock(pgt_lock); @@ -198,11 +197,10 @@ static void sync_global_pgds_l4(unsigned long start, unsigned long end) pgt_lock = &pgd_page_get_mm(page)->page_table_lock; spin_lock(pgt_lock); - if (!p4d_none(*p4d_ref) && !p4d_none(*p4d)) + if (!p4d_none(*p4d)) BUG_ON(p4d_pgtable(*p4d) != p4d_pgtable(*p4d_ref)); - - if (p4d_none(*p4d)) + else set_p4d(p4d, *p4d_ref); spin_unlock(pgt_lock); -- 2.34.1