From mboxrd@z Thu Jan 1 00:00:00 1970 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 B0B6A411F91 for ; Thu, 6 Aug 2026 23:32:39 +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=1786059161; cv=none; b=CGJXT4rzj5yh8Vn4BVfoMUVARVfuv//E/6UyyJ89u0SEF1Ao39q+YqWp49h1GPcPcfLBTU5QnE8YjFz3saZMn/1iqD34cBusFpZErd+9N1q/Fm12MBcK3U82eQpKX9jWTt0lfnZXd6AXIhgImJqwqm3bPrCakuhK3ZThSt8eJFQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786059161; c=relaxed/simple; bh=1EEc9DXazDAkqWyOTVLtE2IybOrjkcWooeu2y5oJv+Y=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=A9idgzC+n6F6iylD1nnBYcvgOA8xHgM2fQjaKrnh70kRsRzdddQq+wO/0cjHPulLPtQLBOhhwffwrluHKZh/Wa0tM/2ja6YLimqLNBGGrtByxTf3u0VUl0GIvB7JKlh6IG0r+Y3uqUCYaqFG5ct7uGXNUqmrl62hDE1p1ffYVdI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=OXmDDFQ9; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=WYXHfURV; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OXmDDFQ9"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="WYXHfURV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786059158; 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: in-reply-to:in-reply-to:references:references; bh=x1PY9KJIb1qTfXyzcPT+pdmLvTO8tSJ3NAtvLbML8yo=; b=OXmDDFQ9i6v4rbB2EMDF9Br7lZJv7zBUXGlTPwtIYMWBItwS7EgYVmJDTmAlImn4KIDUO6 Grn1nWkQPnd5jnLiZxwJDUvWCaejoM8PqZns2byj3Nsnwim01dN+HQoe5Y1aEFEyfI1cYR oL5VgkHz8RN6+jIC1Ms6hN9J5Lvx3E8= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-299-lZf138xlOXm8qGOzcSQTRg-1; Thu, 06 Aug 2026 19:32:37 -0400 X-MC-Unique: lZf138xlOXm8qGOzcSQTRg-1 X-Mimecast-MFC-AGG-ID: lZf138xlOXm8qGOzcSQTRg_1786059157 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-5283fa0656dso18841151cf.1 for ; Thu, 06 Aug 2026 16:32:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1786059157; x=1786663957; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=x1PY9KJIb1qTfXyzcPT+pdmLvTO8tSJ3NAtvLbML8yo=; b=WYXHfURVAoykH1tH+TgahTEScVCiVPTZ1eFiubpXWxWiQPHVGFvAv1gU8YBlXRHiPZ r+l5u6DDdb8axzseYxH0B00FpIaYqcj7v2hOwkg/je3w75+mlbYNmhcJoYUHYRfXdwOK HtXOZoe0HDhLqIHGjqTS1q0ycOpcP8jmtIisp1LG6BkGh6GN7LYsyV7PkM7j+jNYdIlW TTrmn82Fg5A89o2IO4JjGQ1GFRbwOL01I+dD/lZCldonX4pFZOlIFdPsvC46vtqSne6w CFLsxq6/wFI7bLcyJrL42pAXtOrlhc1tLA3yKrIakz/R7AtwrkT8xSxHFZgpYGVlw/18 z9bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786059157; x=1786663957; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=x1PY9KJIb1qTfXyzcPT+pdmLvTO8tSJ3NAtvLbML8yo=; b=W7+c0rCmRt0idmmxStCjxj51NQ37p1MaS/24ZlkKnPiuQ8gG+quib8G4+tj/YRaYpN XS/sBEuu2ApRqlpJOVMD3VxIbHd2n2vsajdMdx+zMFs+8rqMZU//aw45fX0m8J+NIQmt 6I+BJtZXlC+dHKd0BrxjzI2+i1LnDrbNoPdaxV0EyXoFk9l5724ojchzY9pKC7robAWg Z3QiBsHxXqXiSq7Ih0Nx/0mso/arlodAtM3WPWF8+pf+/YP0G1AmMDARJ2PiyYDI3D0q yZXkaFZcu3jh7dVNTXNm0e75SnTPve7gcuC6+Syhfx411o+28rcEY5S0QoQt87dDPtpL SfUQ== X-Gm-Message-State: AOJu0Yw1GtYAD/bmGJYHXkq8eQXf+J5AG+8OMALKoSWELo26sSVo7cjM nYXexiWTjfvLR7WTBvz8EQKF5n9ThDtgG4bYuVY/i0EEv//TqA63eOjBpf49kRjeTBRFkDHohrE 5GPU0HAFxahwOkTzN1IA7LhgHMHsKD6ZJeGcFrXxUEW7RtXDCEJOsyZxkn/Yep/3hmGMkiFQZTg == X-Gm-Gg: AR+sD10bvgSJnjmHhEJGo4FUy9t7pBxuIC1hsTwuJkvopjv2soz7oDfBv0cHkXmOYLN Kt/fjv5L2IhTWGxRIBZDgVec+lpDFXEAwMmpBIC7PzlJkzNkb1E/5RTtrI3kqndMk9Ao1HxFOtO D3/GvFhxAgSxnnv6F+Xc58d1fQIWnJRnoxnjXTIqX+0IiAd5p5NUUa+Lbbs0XH7AG71XNkm3u1d Fb40uNC3j+Wt3+mk95ApnFkmubszoIUg1QsLmxlNnaWic//gCQiIkgLmxC33dB3F+bLNlY4SB7l EO7l40MBH8f7SJHzfGL3lkIghnmRogFhL77JZu0JNgVEpwlcgcwwByKL/uo2VlMQH0Vm X-Received: by 2002:ac8:6f19:0:b0:50e:635b:5562 with SMTP id d75a77b69052e-52d00498b36mr95353371cf.22.1786059156664; Thu, 06 Aug 2026 16:32:36 -0700 (PDT) X-Received: by 2002:ac8:6f19:0:b0:50e:635b:5562 with SMTP id d75a77b69052e-52d00498b36mr95352631cf.22.1786059156155; Thu, 06 Aug 2026 16:32:36 -0700 (PDT) Received: from x1.local ([174.91.117.74]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-52d16335bb4sm273151cf.2.2026.08.06.16.32.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Aug 2026 16:32:35 -0700 (PDT) Date: Thu, 6 Aug 2026 19:32:22 -0400 From: Peter Xu To: Paolo Bonzini Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Alex Williamson , bcm-kernel-feedback-list@broadcom.com, Boris Brezillon , Christian Koenig , David Hildenbrand , dri-devel@lists.freedesktop.org, Fei Li , Huang Rui , linux-mm@kvack.org, linux-s390@vger.kernel.org, Michal Hocko , Sergio Lopez , Sean Christopherson , Thomas Zimmermann , stable@vger.kernel.org Subject: Re: [PATCH v2 3/6] drm/ttm, drm/vmwgfx: directly create writable PTEs when mkwrite is in use Message-ID: References: <20260804120529.1730187-1-pbonzini@redhat.com> <20260804120529.1730187-4-pbonzini@redhat.com> 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=utf-8 Content-Disposition: inline In-Reply-To: <20260804120529.1730187-4-pbonzini@redhat.com> On Tue, Aug 04, 2026 at 02:05:25PM +0200, Paolo Bonzini wrote: > This ensures that fixup_user_fault() users see a writable PTE when > they request one. The flip side is that vmw_bo_vm_fault() now has > to record by hand the write fault, because .pfn_mkwrite() is > not invoked. > > Prefaulting works as before because only the first entry comes > out writable, while the following ones still end up executing > the .pfn_mkwrite() callback. > > Cc: stable@vger.kernel.org > Signed-off-by: Paolo Bonzini Only some quick thoughts while reading through this, as below.. even if some of it may make sense, I think that may be more suitable as follow up. This looks like a good fix for a regression already to me. > --- > drivers/gpu/drm/ttm/ttm_bo_vm.c | 7 ++-- > drivers/gpu/drm/vmwgfx/vmwgfx_page_dirty.c | 42 ++++++++++++---------- > 2 files changed, 29 insertions(+), 20 deletions(-) > > diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c > index a80510489c45..3ebde936ce60 100644 > --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c > +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c > @@ -191,6 +191,7 @@ vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *vmf, > unsigned long pfn; > struct ttm_tt *ttm = NULL; > struct page *page; > + bool mkwrite; > int err; > pgoff_t i; > vm_fault_t ret = VM_FAULT_NOPAGE; > @@ -242,6 +243,7 @@ vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *vmf, > * Speculatively prefault a number of pages. Only error on > * first page. > */ > + mkwrite = !!(vmf->flags & FAULT_FLAG_WRITE); > for (i = 0; i < num_prefault; ++i) { > if (bo->resource->bus.is_iomem) { > pfn = ttm_bo_io_mem_pfn(bo, page_offset); > @@ -263,9 +265,10 @@ vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *vmf, > * at arbitrary times while the data is mmap'ed. > * See vmf_insert_pfn_prot() for a discussion. > */ > - ret = vmf_insert_pfn_prot(vma, address, pfn, prot); > + ret = vmf_insert_pfn_prot_mkwrite(vma, address, pfn, prot, mkwrite); > > - /* Never error on prefaulted PTEs */ > + /* Never error on prefaulted PTEs and never map them writable */ I got confused when reading 1st time, but I got it then noticing the mark dirty was done by the caller. Two small things I thought about here: - Comparing to the time before introducing pfn_mkwrite(), this will cause previously one fault (with prefaults marking all follow up ptes writable) to be 1 writable plus N-1 read-only. May not be the most ideal if we consider the 2nd WP faults on the rest N-1 later as slight overheads, - Split the "mark WRITABLE" and "mark DIRTY" in code might be slightly error prone, especially if this is a common function used by multiple drivers, while there's only one driver that does the "mark DIRTY". IIUC the other idea can be, do not reset @mkwrite here but instead move the set dirty here, invoking whatever the vma's .pfn_mkwrite() is. So that we stick two things together; maybe slightly less error prone and less dup code when other drivers opt-in for pfn_mkwrite(). Not sure if it's a good idea, but just to raise it in case useful. Again, I still think this is a solid fix to the problem already. Other than that, FWIW the whole approach looks reasonable at least to me. I agree in the fault processing we should best resolve the fault in one shot if possible. In this context, FAULT_FLAG_WRITE is the flag showing that a 2nd fault is required, then IMHO it's indeed better to resolve the fault in one go, as proposed in this series. Another thing I came to mind that may not really be relevant to this regression alone, but maybe matters for the future to at least keep in mnind: I wonder if there can be races happen while fixup_user_fault() is resolving faults, causing the 2nd pfnmap follow code to fail once more, say, some other thread modified the pgtable again (e.g. wr-protect with write bit removed right after set). So maybe pfnmap lookup and fixup_user_fault() should be done in a loop until any of them hit real errors.. if any of such race may become a real problem some day. Looks like low possibility that threads will mess up with PFN maps.. but just to raise this idea. I believe currently our mm fault handler should be working like that with handle_mm_fault(), hence neutral with such races (it'll loop a few more rounds until race disappear). I recall there used to have thoughts adding some n_retry_max counts to the fault handler, but we didn't really do that, and it runs all fine over the years. Thanks, -- Peter Xu