From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 952B5C02190 for ; Thu, 30 Jan 2025 13:03:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0BDBA28028C; Thu, 30 Jan 2025 08:03:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 06DA928028B; Thu, 30 Jan 2025 08:03:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E503828028C; Thu, 30 Jan 2025 08:03:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id C5FC528028B for ; Thu, 30 Jan 2025 08:03:49 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 33ACF140D82 for ; Thu, 30 Jan 2025 13:03:49 +0000 (UTC) X-FDA: 83064135378.13.893A6D3 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) by imf29.hostedemail.com (Postfix) with ESMTP id 23CF012000B for ; Thu, 30 Jan 2025 13:03:46 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=ffwll.ch header.s=google header.b=ORHEsKev; spf=none (imf29.hostedemail.com: domain of simona.vetter@ffwll.ch has no SPF policy when checking 209.85.221.51) smtp.mailfrom=simona.vetter@ffwll.ch; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738242227; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=UgiRf9jbTncFOwmj3rTY5I84Nfx6SDCI8aA3yE1P2kU=; b=W/l9k86ogno1bpSjPl2XIFUCpbZ8Bm29FnIlLRBGpoi6j3PbQ2FG6X9p66P6ChNtWCcykZ 88Gi+7J2oir1xYXKI8HprjsXvNrZpmAsVu+3jtvWiBrh3RhYr/Hui6KefsrPA6WsoRnnTH jALzq/upLVuEiP9y54rwIyXqQOvPJ+k= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738242227; a=rsa-sha256; cv=none; b=rNZvR0meuibuUlEt5hupCoeqcbM0csMAY1Nv6wFpRRr3WE3ar+qgSoYhvf/G6ZUR88BCvn cnx+X3zxjnioj8iTvVXnX1/WukQsEcwl9Clky1UKVyRAGp1CamJUvZ0fEu0CnJdP6xERsM 5Y4UvAkvCWEvjnhjnOXQxPqObqJX8as= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=ffwll.ch header.s=google header.b=ORHEsKev; spf=none (imf29.hostedemail.com: domain of simona.vetter@ffwll.ch has no SPF policy when checking 209.85.221.51) smtp.mailfrom=simona.vetter@ffwll.ch; dmarc=none Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-3862d161947so412740f8f.3 for ; Thu, 30 Jan 2025 05:03:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; t=1738242225; x=1738847025; darn=kvack.org; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date:from:to:cc :subject:date:message-id:reply-to; bh=UgiRf9jbTncFOwmj3rTY5I84Nfx6SDCI8aA3yE1P2kU=; b=ORHEsKevoacX0mMVRM2A1Kpd7/jFlE1QjS/R2L5z8D4psPRynhqiTooBwkA5Ordj6s LXyKqzaCJFHyy4LO6gvIctpfdMtKcA7rtu6k/1X+KUggkW/R2xGWdgHdzcT38jPBkyF5 O/yAEj38vNoLu8gkCurIi7DMk08LSy7cp9/D8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738242225; x=1738847025; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=UgiRf9jbTncFOwmj3rTY5I84Nfx6SDCI8aA3yE1P2kU=; b=domO1coW6ELEeAaNrVswg6OrldhooVEXnU1g51HSQaOEJM/HIBIAbRsPb0iUegvHgc tp2qiR+ra+FNOzn+NfgPMarem+YZ2xuSgSSEB8tao4EDhnaxb4j8UVD2WndyJWt+rT2Z Z2NWqucIub9ymPb/QOwJMYABjdfWwU1C0yccsntusHSHLPpMHzpaVL3Y/JyYMlPHJm7C gfA+Ik+oDDxfEF6q75rORsQtOsWcBb4Awba8Hd4hW6CCPxRb6889fDGGs+tNQOsyQ2/G kipndvH8tW5UOGJitY9Rbjv/VYVvnrUMyKgGgfaDN6t0DwTZoNQipROB1zH+EZTNm+RZ gVUA== X-Forwarded-Encrypted: i=1; AJvYcCV71R2a5Mw0R7nyTl1cjLmAvVnhpjlQKIHMJRuG6vX+tvVK9sLtdtsqJ/+Yx257M7SQn8NxRiL75g==@kvack.org X-Gm-Message-State: AOJu0YzUBCNZaUV39+8qwLdEfWeCrsl0vO3kC1K3tyM2/fRrQ7doXyWk 1B62YU/aw/Nsdd698xtn5eLuF81nuRolR0U7VizjtylBXqnax7TPjLpcgO1nGJA= X-Gm-Gg: ASbGncvoBkPIt4zNHgGV7YHyjDfX0SBVll4C1QW9N9rfs3jg8E4OgO04ZJbU3N11/eO 6tkinP2Z3DlfYa63Zu50MRvfofPoWxqOX1ndUidyTDLQVTn5t2ba8COndulAKtO2HEto9MryR2c csemmOzTvL71c72Tad8Uq5n/RI8xtyGcQlE7Dss8HbAaelDC5UiRxgg/kInejcaVW6XTQ5LL+ia BB5C+nYiSEd1EdxlQgJmEflb2sSyK+gupvVYrFcxMjpbstehBOhyaLIuM/bmmYIZV7saINIGwEX AzG+IXRZi56sruvNTM/nxPpDvwo= X-Google-Smtp-Source: AGHT+IHJ4PQVE5HpkzCPzrNWq8zl2Gl6Pk4aDkS8eqlkDUfbDlT8A12K1IbiCiXTus+F/gF8+q2ayQ== X-Received: by 2002:a5d:64ad:0:b0:38b:ecec:8576 with SMTP id ffacd0b85a97d-38c5167b5bfmr7295312f8f.0.1738242225257; Thu, 30 Jan 2025 05:03:45 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:5485:d4b2:c087:b497]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438dcc1317fsm59239255e9.8.2025.01.30.05.03.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jan 2025 05:03:44 -0800 (PST) Date: Thu, 30 Jan 2025 14:03:42 +0100 From: Simona Vetter To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-mm@kvack.org, nouveau@lists.freedesktop.org, Andrew Morton , =?iso-8859-1?B?Suly9G1l?= Glisse , Jonathan Corbet , Alex Shi , Yanteng Si , Karol Herbst , Lyude Paul , Danilo Krummrich , David Airlie , Simona Vetter , "Liam R. Howlett" , Lorenzo Stoakes , Vlastimil Babka , Jann Horn , Pasha Tatashin , Peter Xu , Alistair Popple , Jason Gunthorpe Subject: Re: [PATCH v1 05/12] mm/memory: detect writability in restore_exclusive_pte() through can_change_pte_writable() Message-ID: Mail-Followup-To: David Hildenbrand , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-mm@kvack.org, nouveau@lists.freedesktop.org, Andrew Morton , =?iso-8859-1?B?Suly9G1l?= Glisse , Jonathan Corbet , Alex Shi , Yanteng Si , Karol Herbst , Lyude Paul , Danilo Krummrich , David Airlie , Simona Vetter , "Liam R. Howlett" , Lorenzo Stoakes , Vlastimil Babka , Jann Horn , Pasha Tatashin , Peter Xu , Alistair Popple , Jason Gunthorpe References: <20250129115411.2077152-1-david@redhat.com> <20250129115411.2077152-6-david@redhat.com> <2670f65f-e973-483e-aed6-526d00125ad7@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2670f65f-e973-483e-aed6-526d00125ad7@redhat.com> X-Operating-System: Linux phenom 6.12.11-amd64 X-Stat-Signature: exj389ruks7i7ybqxui7o1tyj1om7wxc X-Rspamd-Queue-Id: 23CF012000B X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1738242226-824372 X-HE-Meta: U2FsdGVkX19aF1eGYlBz93dCE+oy5uWGkkhZusyo5HL2sUFlhrcNtx5Ftl5/xkebKItjuWe1+YNznZp58jtnOIaa4yy86lmShB0+MS2gpvkRiYLczZscpma8rBDVoZDiUysHQBkCBtBi5i2sEYafbScgnQeT3RA2pPo1+ISGDZQILSt/VcAURZczbTrprm02h7wftBf8mY7xwzkF+k3GxbxzC4g2o8c8DA0L0BVFSWdt85rb8T9UjHdbje9ur552so9V3aEXSOPTjL/bAFdzgYXONbsujdfIRo9fMXzU6bgEb6BmzYvbXDLtq/hSLs3EQSFxGSYyk92EA1A6fqD0iq1UltjNQS1ci8D2G6nutA6HA6WwIjLQEdCtRRIPxoEqiOGlJHzGkBbUg1pByQrgPqfrjAxQoW1lrsOmMsrCRhX9DLoThKvrU47QSq6AQB2VVXSBQT2JXvsf7bWfagCj6oQ7zJEa8Tjn/5C57ENjU8sD/dvs3+8lJlytQ5qPGLBtebVcWQ/nokUR9wxej2ew4jN7jvNZnBeB9fiJnWfVuQ2AgJy5ydK0bOjEd0ySbf9oT66Vonh0eem6AwSef898bQYttuPHQ1SME4tHqhdsn/Ev2mx8A70fQEoBWefXNWwfoQioQzlFekDOQcxRVqhAf4d+a18UZWky52NgZvAuLwDW9hrOv9C6xPwG3x4++Di8bEMOjx/KUt0MWFHYjHhciJKhMdaWNXq/UDF+0C7nsaR7GEDUN5Yhf1fZbwY4dCIvzvsEX9j0EbmbwSK+R7+hgyPgxSYTOTXf1PnROE6eJNgn4+vff1J/xd0GCm0Zl2U6fittrNl7/jDUkxT5vchw2lXUT0MdlfdN0ac5J3KA47Vba+eC+KB9QZhRaGxclU1VCVf3LylRmPebYcTabaOoPDfJebn7APd9U7fF9K0nVGxfnwW2v5liy1EUtuthFVGK/hnEd67Pu+sRg41KJoF HAh5wL0N eBwtOkjCjD0P1/+wR0kZfPWhDAu9TVJJJkrUJGhN96UOjE3h2Hhg/zBGKYxM8+s9QLpEXrHk0oTnD/QhI2gOb3S+eeSsj//rRNwYk2ZtJXAQs0RfpBxUbh4P8CWFVLcANipF/GOK0RJwUPWuctTWtyMPCeBEY1HnBD94o/Wq7lmbVPL5AAVzkN3tZV537oH2nvm78Cy1jasLOszVjZRdzRM3yCVWt0onaXh6xa0FoATx9gkjlwjc9AyyTEYspHg4qODvOb77y4kECuly5vbwq4hlxx/3Z0S25lpTQD+1aHtYQVJvo2AJva/tozE8KXThvu/GKnxkhpy6DE64pdnvykAzrlg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.001926, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Thu, Jan 30, 2025 at 10:58:51AM +0100, David Hildenbrand wrote: > On 30.01.25 10:51, Simona Vetter wrote: > > On Wed, Jan 29, 2025 at 12:54:03PM +0100, David Hildenbrand wrote: > > > Let's do it just like mprotect write-upgrade or during NUMA-hinting > > > faults on PROT_NONE PTEs: detect if the PTE can be writable by using > > > can_change_pte_writable(). > > > > > > Set the PTE only dirty if the folio is dirty: we might not > > > necessarily have a write access, and setting the PTE writable doesn't > > > require setting the PTE dirty. > > > > Not sure whether there's much difference in practice, since a device > > exclusive access means a write, so the folio better be dirty (unless we > > aborted halfway through). But then I couldn't find the code in nouveau to > > do that, so now I'm confused. > > That confused me as well. Requiring the PTE to be writable does not imply > that it is dirty. > > So something must either set the PTE or the folio dirty. Yeah I'm not finding that something. > ( In practice, most anonymous folios are dirty most of the time ... ) And yup that's why I think it hasn't blown up yet. > If we assume that "device-exclusive entries" are always dirty, then it > doesn't make sense to set the folio dirty when creating device-exclusive > entries. We'd always have to set the PTE dirty when restoring the exclusive > pte. I do agree with your change, I think it's correct to put this responsibility onto drivers. It's just that nouveau seems to not be entirely correct. And thinking about this I have vague memories that I've discussed the case of the missing folio_set_dirty in noveau hmm code before, maybe with Alistair. But quick search in archives didn't turn up anything. -Sima -- Simona Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch