Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp736328lqs; Tue, 5 Mar 2024 15:14:04 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVgZX25Zv8216SEWlNp25x4MbJhia6qWS0rOsMMxQpM2sxlyCv7YDT/kZO5xS4SXfwZh730KtgYw3VaLjPbwU6acctBZci+uTyTPjgLPw== X-Google-Smtp-Source: AGHT+IF6LDCg/XpZB53LPg/PNLWAmj8s+0+rla/JpEFW+Pn19uk+WZVxPqPmYae+jy74xChs+dir X-Received: by 2002:a17:903:2448:b0:1dc:af70:9f71 with SMTP id l8-20020a170903244800b001dcaf709f71mr4559877pls.20.1709680444487; Tue, 05 Mar 2024 15:14:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709680444; cv=pass; d=google.com; s=arc-20160816; b=hYE5tCMeBnMna3ia6oLEm/md4zDcJHEuGrnsJcXFbLdPhSD6ldzWv2C4ZyoXoWGqp5 UYCg5RFKAd7sCmLWgPGksw35y8q2v2x2/Q/48T+qi48ocv8PezUrDrULilIYdcZiaEwB U7ahwMkTy4ZtrDqkUdUsErjhE2D8shW6I/PGhdhmHUIZMWwaxdKzL1TejcjlMm6pLbQw PjwkwzCMb76N7Cs8k9Dx0xwn4wtYDEe0KVNYrvhAZ9MOgmDwDZt8lRxfXFzmQCWMii2/ 9UjV/QWF7qlJbKXKMs0Pd+/zf1H+jWTkftAIMKDuUV5lXam5CehLPW6CbLZs+N4OYv85 t+Lg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=A+hfIOAS3CirjTR2TDkQQzoNgn7WBbQgBJrbYh4eZAU=; fh=R5BAmjUzLqEsqdxmcYaH2SJwPXLMxASjlJCx+xmsrDk=; b=LYARfRvOAfjr/Ns/knl0w395kww/RudLf9OW1j43SqqvTCEnf/DPtE9VXH5RWlh61u Y7+hiN+kom2Dtxpk5j0qf4clSRkV0HICjHjDeUiJi1uUc5Nw4sevdRY7LaC2cvduxukO klH4fuDc0KGqavX98Easi/u4eMrYEle2O7R8X4vLajZMEOLA/SNs1HO6miSCN1LRJiBR v/o0tlTW5awh0gpd3ovfPJ3f1IEFHSfmk10I7C5ginTdM5oscZAn339l9k43HFWY5lXW hTXfrNAU3EtLDC/0nFEUYhUc5zda1DbBnpHcM4S4DgN0cvb6aTy6An2+meN4pzwjFRS8 PiMg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IzNiGEzu; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-93082-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-93082-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id e17-20020a656791000000b005dc8325e8cdsi10701300pgr.345.2024.03.05.15.14.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Mar 2024 15:14:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-93082-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=@redhat.com header.s=mimecast20190719 header.b=IzNiGEzu; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-93082-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-93082-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 26A0528B4E5 for ; Tue, 5 Mar 2024 23:14:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 63D9112E1DB; Tue, 5 Mar 2024 23:13:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="IzNiGEzu" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 A4FB212DD90 for ; Tue, 5 Mar 2024 23:13:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709680405; cv=none; b=EJ6vU/f2Yk6hYg5/oV4ibdC3xoFFMfUswMMXByqQAEvaE0AqMdqJxHFjqafYF+RWuKqST0aOMa3TB3BoiXN/o5oOVor4T/YkG7zWGy7xIQfmnlG81lVh7lQ5Hwu8iRlwuDnd4uyV3QmOzxpVTAKv9KvXpICQ5wPlqa5rovlCB5g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709680405; c=relaxed/simple; bh=cLhW8+AnPXF+x0lQb/dnv/o/Sf8sk08keva7j4YfP4M=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sBAkwvHl71nW8RNlBswWA9aJcUY/1hAaAjG5gneQbGQATTJr/nFWliRtGCX4kCEelYXW9IsZGD+D4iubUZnH4HT2BunumVAXDEg+ACAH51JuHtBvg89CLY7D0ngP5X0j4/cN1SpHe38hG+1YEer8SrFf46NEal8AV2cMltfshCE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=IzNiGEzu; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709680402; 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+hfIOAS3CirjTR2TDkQQzoNgn7WBbQgBJrbYh4eZAU=; b=IzNiGEzuKmOopKbyTc143xoAaOL9oxCEQQeYzeGnDZFm1oSgO6pAqhTfGqQKFOTavjvi6N 4a9EoguIXR4bjJ2hlv3BmiFT/6BSOPqqyOtMMqSZkBHSGLC/Qn1ySoPyg10RLkyTsiWoZa sWFiZKrVyKgW7wh1g3TPtDDiO/4ByEk= Received: from mail-il1-f200.google.com (mail-il1-f200.google.com [209.85.166.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-587-xxFt8O_9NfidoJbzod_iiA-1; Tue, 05 Mar 2024 18:13:21 -0500 X-MC-Unique: xxFt8O_9NfidoJbzod_iiA-1 Received: by mail-il1-f200.google.com with SMTP id e9e14a558f8ab-3650bfcb2bfso2212645ab.1 for ; Tue, 05 Mar 2024 15:13:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709680400; x=1710285200; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=A+hfIOAS3CirjTR2TDkQQzoNgn7WBbQgBJrbYh4eZAU=; b=LXqkuzMTcCceaF1qwX6+ettN9sQsvS0PE9UuT5M3CU3EJRDhKtWk7CGd14C0B3ZUQz vRBIQ9N3hZNFrPSfjRZ50TSRf0WzLA70xd1OCIm7QnzEOQw3GR2n4gwe/hG5pwuTBBwH hoTilR/as/qrLr5fiuVyKvWW2Kgkfn6gg7clA5HvSiQwxd3tsE4bXhL9VZ9Xf4SYdJzo SlLIts3lwNiEZGy+LgF7CmsX8iRoRqKIbS2FrYOH/+wYphTCyFZ5g02dUgbKIQobXAo+ nztNphfIxnwycFtT4tRp9ckOdC10pGE+5JyEJua89uqemcTGYeelrIyxXvE071DVJSDU 1Bpg== X-Forwarded-Encrypted: i=1; AJvYcCUebwa/xJpZG0KAvq0P4TTjyLJFVK0r2fhGcerJoIh7mH/35LOG+ATyXBCAZ2V4GNnd295EfgmiJN+ryXDFUqY/wsAAVO+SpmshGIRk X-Gm-Message-State: AOJu0Yz62l52u31ONA7WN9r9IJ/rrXsYYEzuCRCPsj25/2r9ifJ8mwul ODBndtlYbaRO0CKZBMnulVN2sx8wc9aPIukfW0F7wcQBz1nYgFreQESvSy/zYgHiu63CYj3CNks vRHK999dnv645m08rseSy6Eh0M0xjD4dLWAdExZUU/7Q2gi/bT8VE08xUrZ5ZFg== X-Received: by 2002:a05:6e02:20ea:b0:361:933c:3b04 with SMTP id q10-20020a056e0220ea00b00361933c3b04mr3503340ilv.7.1709680400426; Tue, 05 Mar 2024 15:13:20 -0800 (PST) X-Received: by 2002:a05:6e02:20ea:b0:361:933c:3b04 with SMTP id q10-20020a056e0220ea00b00361933c3b04mr3503335ilv.7.1709680400167; Tue, 05 Mar 2024 15:13:20 -0800 (PST) Received: from redhat.com ([38.15.36.11]) by smtp.gmail.com with ESMTPSA id c26-20020a02c9da000000b00474b48a629csm3084467jap.46.2024.03.05.15.13.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Mar 2024 15:13:18 -0800 (PST) Date: Tue, 5 Mar 2024 16:12:56 -0700 From: Alex Williamson To: , Oliver Upton Cc: , , , , , , , , , , , , , , , , , , , kvmarm@lists.linux.dev Subject: Re: [PATCH v2 1/1] vfio/nvgrace-gpu: Convey kvm to map device memory region as noncached Message-ID: <20240305161256.09bda6c4.alex.williamson@redhat.com> In-Reply-To: <20240229193934.2417-1-ankita@nvidia.com> References: <20240229193934.2417-1-ankita@nvidia.com> X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-redhat-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 29 Feb 2024 19:39:34 +0000 wrote: > From: Ankit Agrawal > > The NVIDIA Grace Hopper GPUs have device memory that is supposed to be > used as a regular RAM. It is accessible through CPU-GPU chip-to-chip > cache coherent interconnect and is present in the system physical > address space. The device memory is split into two regions - termed > as usemem and resmem - in the system physical address space, > with each region mapped and exposed to the VM as a separate fake > device BAR [1]. > > Owing to a hardware defect for Multi-Instance GPU (MIG) feature [2], > there is a requirement - as a workaround - for the resmem BAR to > display uncached memory characteristics. Based on [3], on system with > FWB enabled such as Grace Hopper, the requisite properties > (uncached, unaligned access) can be achieved through a VM mapping (S1) > of NORMAL_NC and host mapping (S2) of MT_S2_FWB_NORMAL_NC. > > KVM currently maps the MMIO region in S2 as MT_S2_FWB_DEVICE_nGnRE by > default. The fake device BARs thus displays DEVICE_nGnRE behavior in the > VM. > > The following table summarizes the behavior for the various S1 and S2 > mapping combinations for systems with FWB enabled [3]. > S1 | S2 | Result > NORMAL_NC | NORMAL_NC | NORMAL_NC > NORMAL_NC | DEVICE_nGnRE | DEVICE_nGnRE > > Recently a change was added that modifies this default behavior and > make KVM map MMIO as MT_S2_FWB_NORMAL_NC when a VMA flag > VM_ALLOW_ANY_UNCACHED is set [4]. Setting S2 as MT_S2_FWB_NORMAL_NC > provides the desired behavior (uncached, unaligned access) for resmem. > > To use VM_ALLOW_ANY_UNCACHED flag, the platform must guarantee that > no action taken on the MMIO mapping can trigger an uncontained > failure. The Grace Hopper satisfies this requirement. So set > the VM_ALLOW_ANY_UNCACHED flag in the VMA. > > Applied over next-20240227. > base-commit: 22ba90670a51 > > Link: https://lore.kernel.org/all/20240220115055.23546-4-ankita@nvidia.com/ [1] > Link: https://www.nvidia.com/en-in/technologies/multi-instance-gpu/ [2] > Link: https://developer.arm.com/documentation/ddi0487/latest/ section D8.5.5 [3] > Link: https://lore.kernel.org/all/20240224150546.368-1-ankita@nvidia.com/ [4] > > Cc: Alex Williamson > Cc: Kevin Tian > Cc: Jason Gunthorpe > Cc: Vikram Sethi > Cc: Zhi Wang > Signed-off-by: Ankit Agrawal > --- > drivers/vfio/pci/nvgrace-gpu/main.c | 11 ++++++++++- > 1 file changed, 10 insertions(+), 1 deletion(-) Applied to vfio next branch for v6.9. Oliver, FYI I did merge the branch you provided in [1] for this, thanks for the foresight in providing that. Alex [1]https://lore.kernel.org/all/170899100569.1405597.5047894183843333522.b4-ty@linux.dev/ > > diff --git a/drivers/vfio/pci/nvgrace-gpu/main.c b/drivers/vfio/pci/nvgrace-gpu/main.c > index 25814006352d..a7fd018aa548 100644 > --- a/drivers/vfio/pci/nvgrace-gpu/main.c > +++ b/drivers/vfio/pci/nvgrace-gpu/main.c > @@ -160,8 +160,17 @@ static int nvgrace_gpu_mmap(struct vfio_device *core_vdev, > * The carved out region of the device memory needs the NORMAL_NC > * property. Communicate as such to the hypervisor. > */ > - if (index == RESMEM_REGION_INDEX) > + if (index == RESMEM_REGION_INDEX) { > + /* > + * The nvgrace-gpu module has no issues with uncontained > + * failures on NORMAL_NC accesses. VM_ALLOW_ANY_UNCACHED is > + * set to communicate to the KVM to S2 map as NORMAL_NC. > + * This opens up guest usage of NORMAL_NC for this mapping. > + */ > + vm_flags_set(vma, VM_ALLOW_ANY_UNCACHED); > + > vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); > + } > > /* > * Perform a PFN map to the memory and back the device BAR by the