Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp35840lqt; Wed, 5 Jun 2024 16:20:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWAwYoB2iQgjSqYp3wNg2MpzDkVT93TSgScutM7XDSOVp5g9tlUf8aUjDBa81m362TzgfjgN8kG1Lj7LWQa27UmrB77M2dD/Nw6/jVWYg== X-Google-Smtp-Source: AGHT+IHqmwQlYJXoKBpMd7OErGskDK8HJxqhBKdPyOUvK8X9t4b+oyN8SFZ8BRaMcqJ2jFBHOCii X-Received: by 2002:a05:6a00:cca:b0:6ed:5f64:2fef with SMTP id d2e1a72fcca58-703e59cedc8mr4592178b3a.17.1717629601117; Wed, 05 Jun 2024 16:20:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717629601; cv=pass; d=google.com; s=arc-20160816; b=WW7YQ0nFIZFvv7NBAA2sAyiVTyKDcEecBooPh99zOSsN/LRUx5d4yapO/oaEG3pGel +ayL5Vt6hWSIiTTAnNtT1h9+mUrq94kMovNQtxipEct0sm7TcoLHEeQgEZrDczqkGcI7 dYdnGn1DqYJOVJD5wkWwXsIXZmTCgpcsYn0cmgrBFrCyXv8qVIn2OknolVn3KOv84t0X CX2R7PUDZLy+AGytXSmqSaCOnipLwOeBTiwKXwParASGeS+ofJo0i0TMHkDVd3sZCnpp +5DWLIxTvld9jOWQW25/aWzrc3weNdt0cdwf1sQ6GM2WYHw38I2klGiMzvCeO6HCSART FFeA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :reply-to:dkim-signature; bh=ARgGaSqi8KoE1rzp74nNuwJdH1oic2zBLvAnQFTt+74=; fh=d96ppYB8SsPLuH840kRFC0enwv1ssUoG6fdO1ztsAHE=; b=WJK8vg/xlqsv9VMh1ZsGrBaxkNnbJDX+nxrIOaqZlpnaXkgjNL6YEl2V79iR4buEJ7 ai2ph1xmgtjCN8z2sZHYAh/MUfxECQazH6oc+LNAndXnRtUDQZDG18L4LyjUI4yI220c E5MntNjsbOAqRMQvBiiGP7/qIcLm92ZO63OK5f3aTE33efOBAWZwH+PLAjp9WwR6p43E 84ucBdWwxxgH9Cxi6NzvIAYIlI1RqEG76bKD9Ez3EfxFRZMv1yNJv0iAOq9Zwc9EZPr9 Wg5JnIE1AY3OIk1mzJ+2f+5PC0LVQaRhl4/mPJki5xbrNOwhaz/0QMPZr8YqGm8NYlOS 9VwA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=eOWx6Wky; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-203394-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203394-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d2e1a72fcca58-703fd390028si83675b3a.14.2024.06.05.16.20.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 16:20:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-203394-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=eOWx6Wky; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-203394-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203394-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id A4BA32828A7 for ; Wed, 5 Jun 2024 23:20:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 196E416ABCE; Wed, 5 Jun 2024 23:19:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="eOWx6Wky" Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 B6F3E167DB8 for ; Wed, 5 Jun 2024 23:19:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717629568; cv=none; b=EMj1XFd2zB/LHT5Q8yaGmZjLQBNPeRl8D0Mm4tQdy4Ob9F2UpHB5BYTFVKDE3vUXRVr4pauwfUMjLw0V8jepoWJnwBhGe3fAKRYzKe/GgaZpSjEvRS1riIrnzARZNTIzJ4rF0z+inYIrc0CLbX3ptgSWBPB2ko4gnYrYQD+kJiE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717629568; c=relaxed/simple; bh=OT9vjFDhZJe+JrrZnAEYUNwBDJu9CJaj1NqYkfGoeo8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=lvAfamaMJSyIGGeR9q+p8s1RmEMLcSUvw9B2gFaf6BEp5HXEWzIoHzhnuXXBn5COCbnR5XOdWf4CmnsKSU7MEyx1zlT0ZPOPobvdOHk/TqPrxjD8saa9jvhbVG2QUYxLVrj2D5if9bPv7wJgABikDiXNJzvZSz6mKkhv79F/4UA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=eOWx6Wky; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2c1bb32d87eso310194a91.2 for ; Wed, 05 Jun 2024 16:19:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717629566; x=1718234366; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=ARgGaSqi8KoE1rzp74nNuwJdH1oic2zBLvAnQFTt+74=; b=eOWx6WkyZB64F2yv50KrVKWPQvvZnN0dBJ5ZFInZ1FCho1RMgsYnShdf9aW0nZE3uM TZWP/QNw+/19J2nQuhYrtoK/Wkqr7USxQhVx5p9pAA+ue5d90agnTSj+lvpzqCHJVgaM Wlkhvu/5HEIinP4DqQz5mM0F8tu46i0mz55lfoTzUzsB66mU+8hjmN9R7Jk17B1SXT8K +jv92+tEjUlLcc3KjncSkXCWfdFzwcmfpoWjAFC0c8AbVakzH8f8enyaoH3GS3DYa+d1 wOET/Dt5ycFfbo9SqKlkMI1QWbpojzZk3C6pHVkQP1dpKv3vn+XDNlmzSIN2Wa0gV+P4 9W2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717629566; x=1718234366; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ARgGaSqi8KoE1rzp74nNuwJdH1oic2zBLvAnQFTt+74=; b=k3cC7wqVABgfz3Yb9JSsyvLPRtLyUF42aGVpsjAEFYxeatBVgfluTPBby7C6xTIeUN vdFwTExC0eX0xmWQG18MRRQgH8v5XU8bSsmpMNK7o7NGzbt1q2pSS1cfcUOOfz1qvgvN OfmyWGcUNfOt7rv8n9xbmSLQ/QOg6bFX0C3GQP58wGgBXtKc18aQzfEy8d3fIJhsGNJg uHPmgmzE13fJyn5a6ceG4BPUxi8mPov8vjaYPLblZOydQkdv0Z5VgoTdwnusQS9k+J2v yFoyDz/Mb6uF+IadtFBJIEmbIM1v2T8KrQw8Y1pD2T1Ixmxsl4XwqL74f5m7GWYZ2vvs UNAw== X-Gm-Message-State: AOJu0Yw2oopJbrA5feOpl0lYxtIXc56jbITnd/VEtLZSMOwsdjzAV1zq UQW9XU0+5R8Vs3sJxGCAVPgOLTgTO5NhhrYlkibw73PECgGsDLGcX7k06Q2wWWzR+04dvpUd8gX Wbg== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:90b:347:b0:2c2:128:47af with SMTP id 98e67ed59e1d1-2c27db6810cmr14869a91.7.1717629565921; Wed, 05 Jun 2024 16:19:25 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 5 Jun 2024 16:19:10 -0700 In-Reply-To: <20240605231918.2915961-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240605231918.2915961-1-seanjc@google.com> X-Mailer: git-send-email 2.45.1.467.gbab1589fc0-goog Message-ID: <20240605231918.2915961-3-seanjc@google.com> Subject: [PATCH v8 02/10] x86/cpu: KVM: Move macro to encode PAT value to common header From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Sean Christopherson , Paolo Bonzini , Andy Lutomirski , Peter Zijlstra Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Xiaoyao Li , Kai Huang , Jim Mattson , Shan Kang , Xin Li , Zhao Liu Content-Type: text/plain; charset="UTF-8" Move pat/memtype.c's PAT() macro to msr-index.h as PAT_VALUE(), and use it in KVM to define the default (Power-On / RESET) PAT value instead of open coding an inscrutable magic number. No functional change intended. Reviewed-by: Xiaoyao Li Reviewed-by: Kai Huang Signed-off-by: Sean Christopherson --- arch/x86/include/asm/msr-index.h | 6 ++++++ arch/x86/kvm/x86.h | 3 ++- arch/x86/mm/pat/memtype.c | 13 +++---------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h index 1978ba0adb49..d93b73476583 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -377,6 +377,12 @@ #define MSR_IA32_CR_PAT 0x00000277 +#define PAT_VALUE(p0, p1, p2, p3, p4, p5, p6, p7) \ + ((X86_MEMTYPE_ ## p0) | (X86_MEMTYPE_ ## p1 << 8) | \ + (X86_MEMTYPE_ ## p2 << 16) | (X86_MEMTYPE_ ## p3 << 24) | \ + (X86_MEMTYPE_ ## p4 << 32) | (X86_MEMTYPE_ ## p5 << 40) | \ + (X86_MEMTYPE_ ## p6 << 48) | (X86_MEMTYPE_ ## p7 << 56)) + #define MSR_IA32_DEBUGCTLMSR 0x000001d9 #define MSR_IA32_LASTBRANCHFROMIP 0x000001db #define MSR_IA32_LASTBRANCHTOIP 0x000001dc diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h index 5da5b869a991..056cc4a12e56 100644 --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h @@ -103,7 +103,8 @@ static inline unsigned int __shrink_ple_window(unsigned int val, return max(val, min); } -#define MSR_IA32_CR_PAT_DEFAULT 0x0007040600070406ULL +#define MSR_IA32_CR_PAT_DEFAULT \ + PAT_VALUE(WB, WT, UC_MINUS, UC, WB, WT, UC_MINUS, UC) void kvm_service_local_tlb_flush_requests(struct kvm_vcpu *vcpu); int kvm_check_nested_events(struct kvm_vcpu *vcpu); diff --git a/arch/x86/mm/pat/memtype.c b/arch/x86/mm/pat/memtype.c index 15b888ebaf17..6c4e29457c10 100644 --- a/arch/x86/mm/pat/memtype.c +++ b/arch/x86/mm/pat/memtype.c @@ -248,12 +248,6 @@ void pat_cpu_init(void) void __init pat_bp_init(void) { struct cpuinfo_x86 *c = &boot_cpu_data; -#define PAT(p0, p1, p2, p3, p4, p5, p6, p7) \ - ((X86_MEMTYPE_ ## p0) | (X86_MEMTYPE_ ## p1 << 8) | \ - (X86_MEMTYPE_ ## p2 << 16) | (X86_MEMTYPE_ ## p3 << 24) | \ - (X86_MEMTYPE_ ## p4 << 32) | (X86_MEMTYPE_ ## p5 << 40) | \ - (X86_MEMTYPE_ ## p6 << 48) | (X86_MEMTYPE_ ## p7 << 56)) - if (!IS_ENABLED(CONFIG_X86_PAT)) pr_info_once("x86/PAT: PAT support disabled because CONFIG_X86_PAT is disabled in the kernel.\n"); @@ -284,7 +278,7 @@ void __init pat_bp_init(void) * NOTE: When WC or WP is used, it is redirected to UC- per * the default setup in __cachemode2pte_tbl[]. */ - pat_msr_val = PAT(WB, WT, UC_MINUS, UC, WB, WT, UC_MINUS, UC); + pat_msr_val = PAT_VALUE(WB, WT, UC_MINUS, UC, WB, WT, UC_MINUS, UC); } /* @@ -319,7 +313,7 @@ void __init pat_bp_init(void) * NOTE: When WT or WP is used, it is redirected to UC- per * the default setup in __cachemode2pte_tbl[]. */ - pat_msr_val = PAT(WB, WC, UC_MINUS, UC, WB, WC, UC_MINUS, UC); + pat_msr_val = PAT_VALUE(WB, WC, UC_MINUS, UC, WB, WC, UC_MINUS, UC); } else { /* * Full PAT support. We put WT in slot 7 to improve @@ -347,13 +341,12 @@ void __init pat_bp_init(void) * The reserved slots are unused, but mapped to their * corresponding types in the presence of PAT errata. */ - pat_msr_val = PAT(WB, WC, UC_MINUS, UC, WB, WP, UC_MINUS, WT); + pat_msr_val = PAT_VALUE(WB, WC, UC_MINUS, UC, WB, WP, UC_MINUS, WT); } memory_caching_control |= CACHE_PAT; init_cache_modes(pat_msr_val); -#undef PAT } static DEFINE_SPINLOCK(memtype_lock); /* protects memtype accesses */ -- 2.45.1.467.gbab1589fc0-goog