Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp495536pxf; Thu, 8 Apr 2021 07:19:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqKdluFVun2vBJ927pZT+NluXQUH046azn49SUM9T00MgX8sD36sh8dOOXbMmYgdM90lzL X-Received: by 2002:a17:90b:f93:: with SMTP id ft19mr8440620pjb.135.1617891594591; Thu, 08 Apr 2021 07:19:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617891594; cv=none; d=google.com; s=arc-20160816; b=ULnc7MbgXJc1rjoBM3K73WrMIejh97kt77P8OmU5V+eLicwsQLojfm3Wbk7ZI0ay2u O8bwjjmPHg+/6jfAdkV21JfrxhMyT5m7+ZJaTURzRV0GiADz2AkdszZvO/eRkKl6AhBy Dc3K9aVwX8T+xNivx4QfGTpwQ8V1K0MXe7U9Wgzm2Y1DsKOyrqK60X5kITMUZBiXWWIv 6orV6DTYs0I3MXKHwvJBsV03PyHUFEhrVEgsLHXOSMBDoG9cr/0keanT86/qzVSfZX/B jtxypx1vbncpn28rhNXKUvf3DhqPVopTuXsFSFBDo4oG/+DuTdP0GFl/cC5/2DaUIr6T 9DJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=CEZEsj3wv3gzHNJ1Dp1MNUxaPCrmV56KLZRkLX0VqDg=; b=KHSMiC+LL6l2DQv2soB1l3RVwmLFJMgke97Nl5ac/mMUM1B4PDW0q8YOQ3bS7yHmLt a++P1evHVsghRsNOYuenP6T2lXfSd4ZvC9Tr7ykbafTk9U27ybQ6IakEsv8PZaYsy5GA oDJapXo7Ffh6km2VC7kahDyJKr4wf780O9hdANCC7xIYfM0FNP1D2nU0MOg7hSO2Phf3 IwiG3GgHRsxS1foqH2bfD0xhEcd8u3XxC21SKXfqdQ4pc8uWqGnz3sq5BNdMKgb+BhlM ddxxunn5M4tj8a+TfW7NzQ8z03cWmPZXFApOJVhjmCi6ds96pLtPjp73k5iQYaw+uhp6 i9Og== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v13si28415340ple.189.2021.04.08.07.19.42; Thu, 08 Apr 2021 07:19:54 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231709AbhDHOTT (ORCPT + 99 others); Thu, 8 Apr 2021 10:19:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:32778 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232084AbhDHOTL (ORCPT ); Thu, 8 Apr 2021 10:19:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B87866024A; Thu, 8 Apr 2021 14:18:57 +0000 (UTC) Date: Thu, 8 Apr 2021 15:18:55 +0100 From: Catalin Marinas To: Steven Price Cc: David Hildenbrand , 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 Subject: Re: [PATCH v10 2/6] arm64: kvm: Introduce MTE VM feature Message-ID: <20210408141853.GA7676@arm.com> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5e5bf772-1e4d-ca59-a9d8-058a72dfad4f@arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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?) > > BTW, after a page is restored from swap, how long do we keep the > > metadata around? I think we can delete it as soon as it was restored and > > PG_mte_tagged was set. Currently it looks like we only do this when the > > actual page was freed or swapoff. I haven't convinced myself that it's > > safe to do this for swapoff unless it guarantees that all the ptes > > sharing a page have been restored. > > My initial thought was to free the metadata immediately. However it turns > out that the following sequence can happen: > > 1. Swap out a page > 2. Swap the page in *read only* > 3. Discard the page > 4. Swap the page in again > > So there's no writing of the swap data again before (3). This works nicely > with a swap device because after writing a page it stays there forever, so > if you know it hasn't been modified it's pointless rewriting it. Sadly it's > not quite so ideal with the MTE tags which are currently kept in RAM. I missed this scenario. So we need to keep it around as long as the corresponding swap storage is still valid. -- Catalin