From patchwork Fri Jan 5 09:14:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yan Zhao X-Patchwork-Id: 185321 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp6118539dyb; Fri, 5 Jan 2024 01:45:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IERmGg6+d2vwuLJnDecmnUOLZJFPNN+USq2P/uxIP2qMmVXYVSVBR0coCxTuiU4gPMWJ4Gd X-Received: by 2002:a17:902:f343:b0:1d4:5b0d:6ffc with SMTP id q3-20020a170902f34300b001d45b0d6ffcmr1860664ple.61.1704447911125; Fri, 05 Jan 2024 01:45:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704447911; cv=none; d=google.com; s=arc-20160816; b=HrFHiipIsQcIwWQ8kbiDfur3b9Ys2cmbaC1fRBK3CUZPDN8P66EodsJAXi6xe9cGN0 JnyLmQxsSGqGg6ZReGzx4nbh3tAtvn82gBqOJxpCpoVV9A+YfsSB4ftlhlBYLhDtcFFo UF1AqDyR+3bZk19Q/EDN87f3CLrcbQAdGpWhKbtLwB9NZ4WOkIDdCaHrxVGa/gHiyvw0 OOaCN1rUdpnYwmfaKFwOPSQZexU+1/Sr2bHPA92qBZdiH+Ijftnftal59wDG5ZlM5oSf Hy3ejZWMW5UeAdnWPN30DeDZDsagcaGPmL6G22IHapuFbffpC54a1LHH8Ehc+AYAAxOh pgmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=ys1cm82ezrCxiRVxC6TxuiTUVNZx+BgFFqroaPWxZaQ=; fh=YdyUGy0kKu0DsyGpr0tP9PGkupWicnl2+pb1wvQMDbw=; b=QwSF1NhmCRnEvh803z59IKkWfL+1igFezpu3oksU6JZeJzRtMZi65Xr96ly3igR0qR NMzjbQIx9qf4bBiw7N9vCd2H/ey1YAT6yGKitcyNWyXgJEUvwfgdz9bpvDnpfx0YFk+l SjihfXCSHhTw1P8HeT/f4WbZotYDoeQG7bTIelez82KIhBx0ousw2p6Ba6rZ+P1zcWIt cZa68Z6pKplLY2LbWMl3bDzWO2w0G8hLjl7KJ3f87o/TNBbOMqnAJvAoMSVsBqHPNS66 vS1Lz8LjD9ussfhI3PNjzZdNxZ7l50+UwOs9MwEqNqY3AogZhrC7j2SRbvP6waEYIE1e xOug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=llifZT+L; spf=pass (google.com: domain of linux-kernel+bounces-17678-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17678-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id m5-20020a170902db0500b001d3f5ea1a72si974323plx.72.2024.01.05.01.45.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 01:45:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17678-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=llifZT+L; spf=pass (google.com: domain of linux-kernel+bounces-17678-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17678-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 1237B283D34 for ; Fri, 5 Jan 2024 09:44:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B132528DAF; Fri, 5 Jan 2024 09:44:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="llifZT+L" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8210624B49; Fri, 5 Jan 2024 09:44:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1704447854; x=1735983854; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=TAQv9JJR1XqAj6tjxwKS30HsTbZYt1Z095C7qYz5bks=; b=llifZT+LT5JFklPZLtvMD6OSUyLlFZdQAxyVQwUyy85tmICkuc/cqXuU 5VbNfepjNfrHPRTF87oa3jb7W8PdQASabjwJ5IY7CQYfNXmO/BME9pRl0 Xn8+0gO72RU8Q9jlQWAiJHmgd/5A3pxROn3CqYM6fjK4GSFH4IWcbaZ0m p6g59h/OD3IHe0Vm7DjrXUiOiLIOWGZjTWN8Bc4F2hLZFr/hLjO/b6yfX iDoJ6PyobELrAtjGtVmrR07CmgrZUxqnetHRH/ipB8PiThBy5MubqRyZP bAEc0WKhFl7awk/AilCXHQ8AYrzcuvmRqFWNfR2Ts410s3BeCQvqV++d1 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10943"; a="10842964" X-IronPort-AV: E=Sophos;i="6.04,333,1695711600"; d="scan'208";a="10842964" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2024 01:44:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,333,1695711600"; d="scan'208";a="22458420" Received: from yzhao56-desk.sh.intel.com ([10.239.159.62]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2024 01:44:07 -0800 From: Yan Zhao To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Cc: pbonzini@redhat.com, seanjc@google.com, olvaffe@gmail.com, kevin.tian@intel.com, zhiyuan.lv@intel.com, zhenyu.z.wang@intel.com, yongwei.ma@intel.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, gurchetansingh@chromium.org, kraxel@redhat.com, zzyiwei@google.com, ankita@nvidia.com, jgg@nvidia.com, alex.williamson@redhat.com, maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, Yan Zhao , Zhenyu Wang Subject: [PATCH 2/4] KVM: x86: Add a new param "slot" to op get_mt_mask in kvm_x86_ops Date: Fri, 5 Jan 2024 17:14:54 +0800 Message-Id: <20240105091454.24700-1-yan.y.zhao@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240105091237.24577-1-yan.y.zhao@intel.com> References: <20240105091237.24577-1-yan.y.zhao@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787243173125493866 X-GMAIL-MSGID: 1787243173125493866 Add param "slot" to op get_mt_mask in kvm_x86_ops. This is a preparation patch to later honor guest PATs for certain memslots. No functional change intended. Suggested-by: Sean Christopherson Cc: Kevin Tian Cc: Zhenyu Wang Tested-by: Yongwei Ma Signed-off-by: Yan Zhao --- arch/x86/include/asm/kvm_host.h | 3 ++- arch/x86/kvm/mmu/spte.c | 3 ++- arch/x86/kvm/vmx/vmx.c | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index a565a2e70f30..6be0d8ccff65 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1675,7 +1675,8 @@ struct kvm_x86_ops { int (*sync_pir_to_irr)(struct kvm_vcpu *vcpu); int (*set_tss_addr)(struct kvm *kvm, unsigned int addr); int (*set_identity_map_addr)(struct kvm *kvm, u64 ident_addr); - u8 (*get_mt_mask)(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio); + u8 (*get_mt_mask)(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio, + const struct kvm_memory_slot *slot); void (*load_mmu_pgd)(struct kvm_vcpu *vcpu, hpa_t root_hpa, int root_level); diff --git a/arch/x86/kvm/mmu/spte.c b/arch/x86/kvm/mmu/spte.c index 4a599130e9c9..2c3ede3f27a9 100644 --- a/arch/x86/kvm/mmu/spte.c +++ b/arch/x86/kvm/mmu/spte.c @@ -191,7 +191,8 @@ bool make_spte(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, if (shadow_memtype_mask) spte |= static_call(kvm_x86_get_mt_mask)(vcpu, gfn, - kvm_is_mmio_pfn(pfn)); + kvm_is_mmio_pfn(pfn), + slot); if (host_writable) spte |= shadow_host_writable_mask; else diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 40e3780d73ae..85a23765e506 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7576,7 +7576,8 @@ static int vmx_vm_init(struct kvm *kvm) return 0; } -static u8 vmx_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio) +static u8 vmx_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio, + const struct kvm_memory_slot *slot) { /* We wanted to honor guest CD/MTRR/PAT, but doing so could result in * memory aliases with conflicting memory types and sometimes MCEs.