Received: by 2002:a05:7412:8598:b0:f9:33c2:5753 with SMTP id n24csp281833rdh; Mon, 18 Dec 2023 20:56:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IHO5jzAfxiM/VIKnrPV+di05Nm1NZADuYLayzo4odVh8gZJeSCfc7Ldqv+yr4y4h0BHuX3+ X-Received: by 2002:a17:90b:3506:b0:28b:46d1:cfbe with SMTP id ls6-20020a17090b350600b0028b46d1cfbemr2360737pjb.8.1702961815107; Mon, 18 Dec 2023 20:56:55 -0800 (PST) Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id x4-20020a170902ec8400b001c88fc3c593si19983973plg.560.2023.12.18.20.56.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 20:56:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4698-linux.lists.archive=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=WFFwKJyt; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-4698-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4698-linux.lists.archive=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 BC499284BC3 for ; Tue, 19 Dec 2023 04:56:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 30D68C130; Tue, 19 Dec 2023 04:56:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="WFFwKJyt" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.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 C4366BE56; Tue, 19 Dec 2023 04:56:42 +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=1702961803; x=1734497803; h=date:from:to:cc:subject:message-id:reply-to:references: in-reply-to:mime-version; bh=Dujb6TVAR2D8zGQ8cpFndJkAFTyjqXaHFVWNE/GFAm8=; b=WFFwKJytFEFekN+5k8NmQVq9aKTzPwmQmxriS/nmPgAbXZikPdt5LDkO 9ZocaI01L6SVFZgoR6Sg/N8eQ6bljBPFqOTCQ8gI5BQieqwmOu/8yavrC iINKRdV74hX5zuK9jTPSj+GH4ROrbTTW7wubH9RwG7i7eW51V+eArpYAA IITD8cHGIDDmQ+mKcvHwQDobvsyBtvHE68mkJHzBB3KI0368e/6NsCFyP y8ho2Zw04/T/VH1eegPldDAxK7iYuxptKltjhtZKQM1UbSp0VseCh2RAX ebWP4JW+MCDkSmjYMeRihX4C0mGxEacKs93yW+F+e9nlqwLwFr4myALPT g==; X-IronPort-AV: E=McAfee;i="6600,9927,10928"; a="2821773" X-IronPort-AV: E=Sophos;i="6.04,287,1695711600"; d="scan'208";a="2821773" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Dec 2023 20:56:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,287,1695711600"; d="scan'208";a="17461907" Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by orviesa002.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 18 Dec 2023 20:56:41 -0800 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Mon, 18 Dec 2023 20:56:40 -0800 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35 via Frontend Transport; Mon, 18 Dec 2023 20:56:40 -0800 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (104.47.74.40) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Mon, 18 Dec 2023 20:56:00 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lVlJ1N5MnT7CRQYWNBT072o/zW7H6WqDatglntldOb+vCsuwTINW9qpUjMo6MmnSAOC3xBI2pChul3ID/ZjP66an33BokG228m6BMRFcnxaqnYYKQlmrG4dokyPSaMZoEbgDcwrTr+/JUTQBCRzXi4XnRWaQPg2WbxJjMTz9UUuxAyNP8vqumbGnPItRSy+FH6c+b5K+uHAnrehAzB4T/tHbrIJCy3z0XumqfquCCPHo7UGYEGrmmVhM5pSndd8DvZiVSzCwQR9/kH8nYic1ispr3jj/ju9/rN7xxGncUZ4IuGQ4/ve1M7PGrSj9IBKa2HUcUv7qXdlcFwxdRXMuPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7kWKH91ebMcH568pEY9p9EriQc+DjcaX9fA6B8t5aaw=; b=GQWVxBWvZ/oRVtG2yHfNTo8lHIR1lBceXuQk+SieJPmrlO5xl8Z2lqJ1+vbX8qz7FnlrMeJCkrHvUMxcsyEXP8rYcUyP/vTS4a1oKMx3BQHDypVjeBTPryqeu6iwiFNQZlF874sp658hkrgAv9S4rSm1wVUmpNKoWFXztUlg/AyuNmG2vpXNG8IF2W28GsWde4cFOdLuyev+SlGw/5Sbyul36/b+8qaS2NKNqy+iz7xGQCbsnl43nHKcOCOGZRVeOECG0LTAIFB0CiaQ4yGwN4AK/Bl3TqbDSfWa1+J0oqHzAgZAGydCtzIldjq/gZXRlcOUKLh6jSOPfO98r2nTRg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DS7PR11MB5966.namprd11.prod.outlook.com (2603:10b6:8:71::6) by MN2PR11MB4742.namprd11.prod.outlook.com (2603:10b6:208:26b::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.38; Tue, 19 Dec 2023 04:55:57 +0000 Received: from DS7PR11MB5966.namprd11.prod.outlook.com ([fe80::32a9:54b8:4253:31d4]) by DS7PR11MB5966.namprd11.prod.outlook.com ([fe80::32a9:54b8:4253:31d4%4]) with mapi id 15.20.7091.034; Tue, 19 Dec 2023 04:55:57 +0000 Date: Tue, 19 Dec 2023 12:26:45 +0800 From: Yan Zhao To: Sean Christopherson CC: Kevin Tian , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "dri-devel@lists.freedesktop.org" , "pbonzini@redhat.com" , "olvaffe@gmail.com" , Zhiyuan Lv , Zhenyu Z Wang , Yongwei Ma , "vkuznets@redhat.com" , "wanpengli@tencent.com" , "jmattson@google.com" , "joro@8bytes.org" , "gurchetansingh@chromium.org" , "kraxel@redhat.com" , Yiwei Zhang Subject: Re: [RFC PATCH] KVM: Introduce KVM VIRTIO device Message-ID: Reply-To: Yan Zhao References: <20231214103520.7198-1-yan.y.zhao@intel.com> Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: SI2P153CA0034.APCP153.PROD.OUTLOOK.COM (2603:1096:4:190::17) To DS7PR11MB5966.namprd11.prod.outlook.com (2603:10b6:8:71::6) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR11MB5966:EE_|MN2PR11MB4742:EE_ X-MS-Office365-Filtering-Correlation-Id: b06b8127-9199-4107-628a-08dc004ec9af X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Vf+rjZS7r9WOJNAgAGWAYtig7rx18RY7j22Waf+iqeA5rSS8ahA4KbXQ0T6VcNzgC4i4m38Y1elmL968sXdnSKEwIU5GvmOsuAaIuLrB4UrqpnOQLCACXtwFX1EG59blcxCuF/ZI8QPOnKbgNgVpSrs1FH/RAeKHEwNR7udUDjMVl/DCrcJFAo9A0kZ26KVboma07Vc44Bheo6kBrTLqcku50bHG4eUPocDW9qSRSghqOZnrfLAHIl5edjmgt7Qm7+wAggRYAhaMspyKUdcD7Jy+eVlLUIK5CAXCcIC95wOPwNJMKOQmcAKejdPWliNmR9it7yEiRK2dgIKr+UYVnhZo6hF8BUIsW0DGLxdpHxsau/xHNFtxm6cE0L9Re4IflvbWLCoBqMMzNeRROQAYpMYbxLYsT6bnuMMtWt7CYJj9720pRVQElR5n4kqamq9NPdkiY1ZyB7iDXOVd+J06PXKaVALTUvMsrTBd1vGnn8NmYyIaN3BFBp5pLBT8U69I8uzuEf5YjbSLL1Tf9QT3xwdj8J9R1u/BjvBjECcqhqu2J/1OXx2/sSwDAxh/gkDTccrusyeFi73YnlNXig9nwDkjaI03hl2GgTsSpujPfBE= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR11MB5966.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(396003)(136003)(366004)(376002)(39860400002)(230922051799003)(186009)(451199024)(64100799003)(1800799012)(82960400001)(6486002)(478600001)(6506007)(26005)(6512007)(41300700001)(83380400001)(6666004)(3450700001)(86362001)(2906002)(6916009)(316002)(66556008)(66476007)(54906003)(66946007)(7416002)(5660300002)(38100700002)(8936002)(4326008)(8676002)(67856001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?p3ddz74dNOIIQqMsmF6VCBARE/L5/h34f4PqQDrTZPFxQCUcHLS1aHyCNPhU?= =?us-ascii?Q?8S695JLQ8nxhB9IJNZa7Lmo3glIgNtOjSN6rLwwp9M3cJJmHzthtZrIY/SF5?= =?us-ascii?Q?T0xXvoJaq7hvG8trLV00G5O5kZYIF+FSWlpDY41a7ITC9YDihDJnwPJ5zGi/?= =?us-ascii?Q?bW9HK0F+xm+in+c3fQH8fummXkKKE8ZKmTQyF7a/F2gqS6h8FUktm8ZI0t4W?= =?us-ascii?Q?wSwj5KTT/HEX7ZyEkZOtrvF/pSlPuMdbL+W5agjV8vyjV8DY5GIcGC363qlR?= =?us-ascii?Q?m/I5BNctt870qzKcZ8pdOimj1xYNqcsBXnzH6s1cbjwo5vwG91WymPYdOeQX?= =?us-ascii?Q?le32PzooL9d/6XYBQUZ1m9v5ODUfEZKGuQRj9ho4A3TY8/S/W30vSWBDJ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R3KpPp1kJXyPm4+SfC7N3hrl6ZcRPyNXTBVham?= =?us-ascii?Q?RuqYiHUk6vcZ2vL+h2u14JICeJG52WkL9sE27SGPbuscQ5Iui3SPcCFdgNoO?= =?us-ascii?Q?iH9PMv/b+oxg8P7cCMHvgFW2WH37W6EfOlCZn67IdU+3h/FiZKHshh3+INVI?= =?us-ascii?Q?BPaIqkL8QxuACiuScrq351q+tvNGnkjl+EXM1wQxkXM70hwTHwdcmVmSbD4m?= =?us-ascii?Q?SCUWq53v6hb9VP1oVwpEJNAN/HQTWcLIEMLogGfxD6TWKSRYYy0as+F8GInR?= =?us-ascii?Q?rCjUYctN+6PFeBkxcXNV7UTy7tkHwtoj4wrPwmvo?= X-MS-Exchange-CrossTenant-Network-Message-Id: b06b8127-9199-4107-628a-08dc004ec9af X-MS-Exchange-CrossTenant-AuthSource: DS7PR11MB5966.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Dec 2023 04:55:57.2225 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: mzq1o5SSFUKJSkUSRTZKRFv3v9CPjh2ZULZpqoxzcdwoGVYFoapQ8UbvHMkUYyN8wMhHKl5qcXlQZrHd3Kke4g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB4742 X-OriginatorOrg: intel.com On Mon, Dec 18, 2023 at 07:08:51AM -0800, Sean Christopherson wrote: > > > Implementation Consideration > > > === > > > There is a previous series [1] from google to serve the same purpose to > > > let KVM be aware of virtio GPU's noncoherent DMA status. That series > > > requires a new memslot flag, and special memslots in user space. > > > > > > We don't choose to use memslot flag to request honoring guest memory > > > type. > > > > memslot flag has the potential to restrict the impact e.g. when using > > clflush-before-read in migration? > > Yep, exactly. E.g. if KVM needs to ensure coherency when freeing memory back to > the host kernel, then the memslot flag will allow for a much more targeted > operation. > > > Of course the implication is to honor guest type only for the selected slot > > in KVM instead of applying to the entire guest memory as in previous series > > (which selects this way because vmx_get_mt_mask() is in perf-critical path > > hence not good to check memslot flag?) > > Checking a memslot flag won't impact performance. KVM already has the memslot > when creating SPTEs, e.g. the sole caller of vmx_get_mt_mask(), make_spte(), has > access to the memslot. > > That isn't coincidental, KVM _must_ have the memslot to construct the SPTE, e.g. > to retrieve the associated PFN, update write-tracking for shadow pages, etc. > Hi Sean, Do you prefer to introduce a memslot flag KVM_MEM_DMA or KVM_MEM_WC? For KVM_MEM_DMA, KVM needs to (a) search VMA for vma->vm_page_prot and convert it to page cache mode (with pgprot2cachemode()? ), or (b) look up memtype of the PFN, by calling lookup_memtype(), similar to that in pat_pfn_immune_to_uc_mtrr(). But pgprot2cachemode() and lookup_memtype() are not exported by x86 code now. For KVM_MEM_WC, it requires user to ensure the memory is actually mapped to WC, right? Then, vmx_get_mt_mask() just ignores guest PAT and programs host PAT as EPT type for the special memslot only, as below. Is this understanding correct? static u8 vmx_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio) { if (is_mmio) return MTRR_TYPE_UNCACHABLE << VMX_EPT_MT_EPTE_SHIFT; if (gfn_in_dma_slot(vcpu->kvm, gfn)) { u8 type = MTRR_TYPE_WRCOMB; //u8 type = pat_pfn_memtype(pfn); return (type << VMX_EPT_MT_EPTE_SHIFT) | VMX_EPT_IPAT_BIT; } if (!kvm_arch_has_noncoherent_dma(vcpu->kvm)) return (MTRR_TYPE_WRBACK << VMX_EPT_MT_EPTE_SHIFT) | VMX_EPT_IPAT_BIT; if (kvm_read_cr0_bits(vcpu, X86_CR0_CD)) { if (kvm_check_has_quirk(vcpu->kvm, KVM_X86_QUIRK_CD_NW_CLEARED)) return MTRR_TYPE_WRBACK << VMX_EPT_MT_EPTE_SHIFT; else return (MTRR_TYPE_UNCACHABLE << VMX_EPT_MT_EPTE_SHIFT) | VMX_EPT_IPAT_BIT; } return kvm_mtrr_get_guest_memory_type(vcpu, gfn) << VMX_EPT_MT_EPTE_SHIFT; } BTW, since the special memslot must be exposed to guest as virtio GPU BAR in order to prevent other guest drivers from access, I wonder if it's better to include some keyword like VIRTIO_GPU_BAR in memslot flag name.