Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp720830pxf; Thu, 8 Apr 2021 11:17:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhG9/lZZPaajF4e6tZpeE3cEnaC384MqAC2s8KZnGYB/oVG3DaLR/8yK5fpAkrolvMHH6g X-Received: by 2002:a17:906:85c6:: with SMTP id i6mr12266297ejy.279.1617905878008; Thu, 08 Apr 2021 11:17:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617905878; cv=none; d=google.com; s=arc-20160816; b=S+Hx9itdJB/9XtVxuMbWZiAFP3TuEpg+PHlWuZxBvtvEuTpqUuhSiOj8/4PKHhmDkU VYyjP0c9uP2EsZg9CvKCJjz7XXqIno4WgF+CrL+dixoiGYQVPrmW6acP7RmFS1j1kxBT qvPca3wT1REmao/VF/ZaJkiZR2nrGs84iXQItpFE+qzmi9jfDlHtUXXJ0nrX/1/GZcHA 0/Do2TS1nIJciyI0S1gOyUw1mq20Fuv3h5c7D7f2n+J3NF7y5ZpBu/PnRk5mfq3XMIsl FIb6Od2Wav+xoc10kLt2toehcUMTz3eUjm8D+QaCuI8eaqssCPVBU5F6AQRt11JDhexu +Zpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:organization :from:references:cc:to:subject:dkim-signature; bh=a+ZAM3G9QEbZhESupLgtt9XPr4Jta/bTYgM9EuA2Thw=; b=N7/blSXeT//Md9iVJF6/hq5fbM29pHO4Si4ItmgEQmP/y6e2DnAsyLbW/J9yEvRxTL rf63TQ0Wc4dqI19C/kFNn90mnWPYiClHSsZhXs6M0OGBRoU9F5osntzYdiRqqd4hodgv 33jwOsNgzI2QHgufzU26ZxLEZaaAtErx0h+cU/zyPv4GnuwXRqGdATfuVJuU+D3ck8Bp r6m65/U9D2rZkpi3NOH9UDEg+jSeasHLJ7QNiy+yJSkscahjbzwtbW5ain1Y9Ag1G7of NzOnnPNvdoLVN0jXwv7HRwvPm7zbUCQoCjZyO9rtQistQen3cIB1D9BFwz6GL5UXBNy5 xfoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=F0c5YJiK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i13si168815edr.59.2021.04.08.11.17.34; Thu, 08 Apr 2021 11:17:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=F0c5YJiK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232670AbhDHSQm (ORCPT + 99 others); Thu, 8 Apr 2021 14:16:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:41689 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231676AbhDHSQl (ORCPT ); Thu, 8 Apr 2021 14:16:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617905789; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a+ZAM3G9QEbZhESupLgtt9XPr4Jta/bTYgM9EuA2Thw=; b=F0c5YJiKvEgKZZoboH/bZx9WwMN/8NUIaGx3Lhxnq1D9qK+FdiHHLz2DPhzUThgiqrfjCq 63CchNhZZH/OpPhXK1tiGkOFfOiz5+gDaQY7XUUUoO7CwO+8lFoXib+ZS7WfE0lD7EH4z0 BtKlG/senbKLpz5cBOZS8tnyRB4d2qg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-568-v5LP_p_OOEqJQ2MwT-ujmw-1; Thu, 08 Apr 2021 14:16:27 -0400 X-MC-Unique: v5LP_p_OOEqJQ2MwT-ujmw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DA6E384B9A0; Thu, 8 Apr 2021 18:16:25 +0000 (UTC) Received: from [10.36.113.26] (ovpn-113-26.ams2.redhat.com [10.36.113.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 542815C1C4; Thu, 8 Apr 2021 18:16:18 +0000 (UTC) Subject: Re: [PATCH v10 2/6] arm64: kvm: Introduce MTE VM feature To: Catalin Marinas , Steven Price Cc: Mark Rutland , Peter Maydell , "Dr. David Alan Gilbert" , Andrew Jones , Haibo Xu , Suzuki K Poulose , qemu-devel@nongnu.org, Marc Zyngier , Juan Quintela , Richard Henderson , linux-kernel@vger.kernel.org, Dave Martin , James Morse , linux-arm-kernel@lists.infradead.org, Thomas Gleixner , Will Deacon , kvmarm@lists.cs.columbia.edu, Julien Thierry References: <20210330103013.GD18075@arm.com> <8977120b-841d-4882-2472-6e403bc9c797@redhat.com> <20210331092109.GA21921@arm.com> <86a968c8-7a0e-44a4-28c3-bac62c2b7d65@arm.com> <20210331184311.GA10737@arm.com> <20210407151458.GC21451@arm.com> <5e5bf772-1e4d-ca59-a9d8-058a72dfad4f@arm.com> <20210408141853.GA7676@arm.com> From: David Hildenbrand Organization: Red Hat GmbH Message-ID: Date: Thu, 8 Apr 2021 20:16:17 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210408141853.GA7676@arm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08.04.21 16:18, Catalin Marinas wrote: > On Wed, Apr 07, 2021 at 04:52:54PM +0100, Steven Price wrote: >> On 07/04/2021 16:14, Catalin Marinas wrote: >>> On Wed, Apr 07, 2021 at 11:20:18AM +0100, Steven Price wrote: >>>> On 31/03/2021 19:43, Catalin Marinas wrote: >>>>> When a slot is added by the VMM, if it asked for MTE in guest (I guess >>>>> that's an opt-in by the VMM, haven't checked the other patches), can we >>>>> reject it if it's is going to be mapped as Normal Cacheable but it is a >>>>> ZONE_DEVICE (i.e. !kvm_is_device_pfn() + one of David's suggestions to >>>>> check for ZONE_DEVICE)? This way we don't need to do more expensive >>>>> checks in set_pte_at(). >>>> >>>> The problem is that KVM allows the VMM to change the memory backing a slot >>>> while the guest is running. This is obviously useful for the likes of >>>> migration, but ultimately means that even if you were to do checks at the >>>> time of slot creation, you would need to repeat the checks at set_pte_at() >>>> time to ensure a mischievous VMM didn't swap the page for a problematic one. >>> >>> Does changing the slot require some KVM API call? Can we intercept it >>> and do the checks there? >> >> As David has already replied - KVM uses MMU notifiers, so there's not really >> a good place to intercept this before the fault. >> >>> Maybe a better alternative for the time being is to add a new >>> kvm_is_zone_device_pfn() and force KVM_PGTABLE_PROT_DEVICE if it returns >>> true _and_ the VMM asked for MTE in guest. We can then only set >>> PG_mte_tagged if !device. >> >> KVM already has a kvm_is_device_pfn(), and yes I agree restricting the MTE >> checks to only !kvm_is_device_pfn() makes sense (I have the fix in my branch >> locally). > > Indeed, you can skip it if kvm_is_device_pfn(). In addition, with MTE, > I'd also mark a pfn as 'device' in user_mem_abort() if > pfn_to_online_page() is NULL as we don't want to map it as Cacheable in > Stage 2. It's unlikely that we'll trip over this path but just in case. > > (can we have a ZONE_DEVICE _online_ pfn or by definition they are > considered offline?) By definition (and implementation) offline. When you get a page = pfn_to_online_page() with page != NULL, that one should never be ZONE_DEVICE (otherwise it would be a BUG). As I said, things are different when exposing dax memory via dax/kmem to the buddy. But then, we are no longer talking about ZONE_DEVICE. -- Thanks, David / dhildenb