From patchwork Wed Jan 29 11:57:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13953688 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 0E088C02190 for ; Wed, 29 Jan 2025 11:58:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8AA95280060; Wed, 29 Jan 2025 06:58:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 85B1928005A; Wed, 29 Jan 2025 06:58:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6FBE0280060; Wed, 29 Jan 2025 06:58:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 4F28328005A for ; Wed, 29 Jan 2025 06:58:18 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 307961C7D5E for ; Wed, 29 Jan 2025 11:58:17 +0000 (UTC) X-FDA: 83060341434.24.AB15162 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 74D7E80013 for ; Wed, 29 Jan 2025 11:58:13 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=i4V+ikB2; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738151895; a=rsa-sha256; cv=none; b=XFtBajoxSMxfnv3IVp58zLNXToD+DQ4VLp5TahUq0dLuJVUwjR1XWahdKYfjZiLiQjKVJ1 r5jAMaBhBMPW9UBL+9cKEsqsvuoQhGld9ajoqqw5Vv3xMLLUX5Ah7R8XP5QMoCHL00qZhX k9psXulZC48n4L69h/8kErFQx4kR5Ps= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=i4V+ikB2; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738151895; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=IvULs1yE7EOmGau/Ggivq4i0htACtoQXWVK4/nOi/M8=; b=DVldzzwdUV25BnZY8taZmfTkLwu074+WcXpU4M/ArxfPXJLuO9Z1QWewlM5EYb+aLI/c/s 74hqgxIg8E1A2E3mYepaCY3ZLB2y/GF5W0sdiSfbTIuKqnoq8fhqVrlYd2QnRFADU1bwgs b5Q4gmVKObsmiT2/9OkCLZ8BNC2c59I= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738151892; 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=IvULs1yE7EOmGau/Ggivq4i0htACtoQXWVK4/nOi/M8=; b=i4V+ikB2Gk5mBT1ntGNVcNrB8GGm/iQdKYp3hzkcgqOAZoBvTu2NU4E7txnmdd1a5wJikT npgDh1aaT+RnJVMxs48IAG3iTGUqKhLf0ebcrJCMa+JksyRR/4TaW/0HCsiKoa4pgTTlkm 1s9BVr5u6oxTsLASo8Vsa++UtvJYUvw= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-464-LrZ6zNGYPBaxGSOBP99D3A-1; Wed, 29 Jan 2025 06:58:11 -0500 X-MC-Unique: LrZ6zNGYPBaxGSOBP99D3A-1 X-Mimecast-MFC-AGG-ID: LrZ6zNGYPBaxGSOBP99D3A Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4362552ce62so32640525e9.0 for ; Wed, 29 Jan 2025 03:58:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738151890; x=1738756690; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IvULs1yE7EOmGau/Ggivq4i0htACtoQXWVK4/nOi/M8=; b=XhLD47f0jLAQMcBlfbkT9os2ggL2CZDAsnKaZysVe7vciYXPgqGyxEndgywbgpCHVG 57i4K8xa0ZFsCpXZJmCeiClSYwXxp9fxom8StNsjGdgwx+Ysh9dQPmRRgbjvH+8Ywei+ qFC8WL263bcTQfrNUGgKjq5IpIuWmvRxBU3oAlD0X6jfk3Tu2NV/mNT8VlNQSfUgz3NZ l/9sG2IHW/d+ZNLrkT4kUn+Q+sNmlLsnq/fWWAwFnHO+UUhFCon3z3Kc7pFdXms6R/wE yptXDPH48vDdVEjgo+Rz0gtlF/mAkZPumEuJBOvU+j/igEHUyfbt/OwaOZgMnyW8fdJY Uarg== X-Forwarded-Encrypted: i=1; AJvYcCXKFGsfto2WHxPb4qXuT2/8yhLTI49gU0XTNDpC3M6qfg+1WGn4EYm2Ul5SfDxRd4ZPc3BGjdtulw==@kvack.org X-Gm-Message-State: AOJu0Yz6NTJUJF9l7OlL6YltcM8yOZp80pdJzqS+l2sFlvshI9m6vLSz fm2mg1pIAaALfv+PPXOTOVhJvW1jGP0KecnQmvSBC7cXg5SjLn11MHOfzFbMb9MwhbIluQC7vc0 2Z8+Lz8S4gErkSnQF9BD68qUYEEFMyyfhrCV50JCnfKtPYuxb X-Gm-Gg: ASbGncumEKguJGpA9vU1jHpG45IPD8oa0nzZUyV6JBeJinVFrpz7aumEB8SGt08cweD YCwZDZZbmp+bCjtwzJnsIGG6FVPfnDTZs7ddQQe8SdPT13d9qzXNLuqYF5a3IhiikeRlExPdzYM 1hTjMjVn0zh0UBxfbzQDwH1xlgEFIcwEOMk/5INzFC3yhrTgKnnFTtN0CsJT656b4DhBPb065th aoEU3VgmvwHZSaqnpYZwK8SIkzWK0dVDa14ieHTgvOR7d+MeYr/5XkRj2gCZwj8cS03kIMKCPfg /V3X9UXGP928oWKB5w2km6Nk3l8cAe2M1dxP4FV177/RHWaN54At9jxnZGbV8YIKFg== X-Received: by 2002:a05:600c:5252:b0:431:6153:a258 with SMTP id 5b1f17b1804b1-438dc3ca802mr23864255e9.13.1738151890445; Wed, 29 Jan 2025 03:58:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IEqM74m4ZV9IsBXW9SIKcsLoOPVNY/fxsU8Okkl94/EsEQHDya1iNUyBhUuUArF4/LgH5tlYg== X-Received: by 2002:a05:600c:5252:b0:431:6153:a258 with SMTP id 5b1f17b1804b1-438dc3ca802mr23863905e9.13.1738151890101; Wed, 29 Jan 2025 03:58:10 -0800 (PST) Received: from localhost (p200300cbc7053b0064b867195794bf13.dip0.t-ipconnect.de. [2003:cb:c705:3b00:64b8:6719:5794:bf13]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-438dcc12f88sm20420515e9.2.2025.01.29.03.58.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Jan 2025 03:58:08 -0800 (PST) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-doc@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-mm@kvack.org, nouveau@lists.freedesktop.org, David Hildenbrand , Andrew Morton , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , 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: [PATCH v1 1/4] lib/test_hmm: make dmirror_atomic_map() consume a single page Date: Wed, 29 Jan 2025 12:57:59 +0100 Message-ID: <20250129115803.2084769-2-david@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129115803.2084769-1-david@redhat.com> References: <20250129115803.2084769-1-david@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 2_y-_eAXuJ3a7IsUodGtfi8WSNh-X91MlJxjqPQexMo_1738151890 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 74D7E80013 X-Stat-Signature: kxqocq3j4tnks19bad94n1fnpjsxyouf X-HE-Tag: 1738151893-185895 X-HE-Meta: U2FsdGVkX193qUR7nkKE7qKzsAiHWtbngT34fe5zhgqNDXAoNdcfFT4r5tOAZWz+mixPjPsPCJRqor+6TqbdZ8K0cb11MptXpgwDy6HocwNG7B2jmGFN4gLxnZ3NRdv5TEcyvIEc0m2JQOhbT59//hh7aMMHDXMO+Y4xUvh6M4ROu/Upat55jpS5MrQY8Vf99J7jBnZsGJrQjdgK2WvT0sz5gQa61h+8x+juRHBBkdo6wrZl7lzPwxIdmTF24cvOdik8jkqxZPFSlWrG48znMJuChBemIhQtP3plT5Upa0a3dfTiKdsiJjsG7sgJo96rST//Jt6ICgSCq+jZIVYTUpipDdXLyvVjSP6/u/htE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8JqiA+SIIkxgrFYcDwuXFyRsNHVWPk2512afzjYyZGonZLm5FQBFV+iOpdpLcpV1wS6/Z7tPUGvhN+EWw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The caller now always passes a single page; let's simplify, and return "0" on success. Signed-off-by: David Hildenbrand Reviewed-by: Alistair Popple --- lib/test_hmm.c | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/lib/test_hmm.c b/lib/test_hmm.c index 9e1b07a227a3..1c0a58279db9 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -706,34 +706,23 @@ static int dmirror_check_atomic(struct dmirror *dmirror, unsigned long start, return 0; } -static int dmirror_atomic_map(unsigned long start, unsigned long end, - struct page **pages, struct dmirror *dmirror) +static int dmirror_atomic_map(unsigned long addr, struct page *page, + struct dmirror *dmirror) { - unsigned long pfn, mapped = 0; - int i; + void *entry; /* Map the migrated pages into the device's page tables. */ mutex_lock(&dmirror->mutex); - for (i = 0, pfn = start >> PAGE_SHIFT; pfn < (end >> PAGE_SHIFT); pfn++, i++) { - void *entry; - - if (!pages[i]) - continue; - - entry = pages[i]; - entry = xa_tag_pointer(entry, DPT_XA_TAG_ATOMIC); - entry = xa_store(&dmirror->pt, pfn, entry, GFP_ATOMIC); - if (xa_is_err(entry)) { - mutex_unlock(&dmirror->mutex); - return xa_err(entry); - } - - mapped++; + entry = xa_tag_pointer(page, DPT_XA_TAG_ATOMIC); + entry = xa_store(&dmirror->pt, addr >> PAGE_SHIFT, entry, GFP_ATOMIC); + if (xa_is_err(entry)) { + mutex_unlock(&dmirror->mutex); + return xa_err(entry); } mutex_unlock(&dmirror->mutex); - return mapped; + return 0; } static int dmirror_migrate_finalize_and_map(struct migrate_vma *args, @@ -803,9 +792,7 @@ static int dmirror_exclusive(struct dmirror *dmirror, break; } - ret = dmirror_atomic_map(addr, addr + PAGE_SIZE, &page, dmirror); - if (!ret) - ret = -EBUSY; + ret = dmirror_atomic_map(addr, page, dmirror); folio_unlock(folio); folio_put(folio); From patchwork Wed Jan 29 11:58:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13953690 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 C4BB0C02190 for ; Wed, 29 Jan 2025 11:58:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 54FAA2801BC; Wed, 29 Jan 2025 06:58:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4FF8928005A; Wed, 29 Jan 2025 06:58:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A0982801BC; Wed, 29 Jan 2025 06:58:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 19CA128005A for ; Wed, 29 Jan 2025 06:58:37 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 2B03BC0E0A for ; Wed, 29 Jan 2025 11:58:18 +0000 (UTC) X-FDA: 83060341518.01.F60FBFF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf09.hostedemail.com (Postfix) with ESMTP id DC8C114000B for ; Wed, 29 Jan 2025 11:58:15 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gyDacMND; spf=pass (imf09.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738151895; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=b7tz66Q1mh6b9biGlGMq1Dqed0aye0/ijzbhQ2yLKo0=; b=4f6BvCYA9dwO+qwtlxJV6J3aGi0fFCd7SBLqapqCOzlz0Du8A1Olw0+gP+nCf8SM/uo5E6 bygTdShcMoJ05kfs7DYVP5cotKvL/AhWGBEa5/VMtSXTE5pTt7xlVXMvOJiQfPLbw5Odcv xRoa2fN6Ugwri9HVuskGl0QpUQlPF90= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738151895; a=rsa-sha256; cv=none; b=tb98/oG0pNhFF7JOESlIoo3mQ1H6Y5xoCCOU550IdXEwU9urUwt96lddkimjEFWHQ5X47l S6NtR2J6M3texwhUKTboHSZ0Ghj0+OU67M9ruShRSugiN5f8uY7yTO3qLb5eAkyMyJz9ym 0wFc8jU6E3/ZW+GNT7FGTwCMJLkezQQ= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gyDacMND; spf=pass (imf09.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738151895; 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=b7tz66Q1mh6b9biGlGMq1Dqed0aye0/ijzbhQ2yLKo0=; b=gyDacMND/LhZRFD7mSoTy71Jwlz0dNSoMnvaa/EL86MuK5chqkPYGpwIXNdXKbjCvuCovx Gkxy8DbQWMGeiLIeyZKNJv8UDEqBQnaJXh6QFMPoDG9RDuaek4AoOl3TqwGFsUzyQGXPVZ PLwp9lFZ8AGepAVyHKfDdJ7U0WR4fV0= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-328-RzLv_t0zMrqPctIY-vXh2A-1; Wed, 29 Jan 2025 06:58:14 -0500 X-MC-Unique: RzLv_t0zMrqPctIY-vXh2A-1 X-Mimecast-MFC-AGG-ID: RzLv_t0zMrqPctIY-vXh2A Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-385d6ee042eso4940009f8f.0 for ; Wed, 29 Jan 2025 03:58:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738151892; x=1738756692; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=b7tz66Q1mh6b9biGlGMq1Dqed0aye0/ijzbhQ2yLKo0=; b=llgLdyMEQXAYxtYC2FSvSojo5MqEO5+BfBqcgE6IxZrYCzOsn7CQJdHjeedaxqoS7Y PGR80HW/ygeSuhGS083URE2897A87umUxMQlagL75tRu6XDxf7X39Df/BaxEGFUIEVPC mZ17v/7xXB/1ooM7OIdG1Nky6TnIta6ufiPKJolpV8DmqUfCkbgfwQNPWZAzP5WFS1H4 Sw86pfF36hFBpHdrQamN0VHZkReuVDXAZZ+WoY9YsXIJ1ih4n1qYoA8TgZLlS7HnNpPU q/6xpcaLjSiABOLJV9MR/QIbyqmzCIzPdMMv/y6vZIDLW+aiJ7Pl9hR9yy3gK/cLu6RR xHHQ== X-Forwarded-Encrypted: i=1; AJvYcCWHVJ/6WoGTLj3wcoR9sigwu4y6LLyAfyUoEQqSqWnAwtd35rB4uVKjQq+0soiKRfj9YVcibg8Mzg==@kvack.org X-Gm-Message-State: AOJu0YyiWXT5YTT6vyANE1xm7/1JlFPhbIMDNmbDo7ghsH4JqpdUqc2Y 8kdI/95PqCZy+o7NapRbyiL302wwDJVbqoQaINU8b+F6lbRo9PI5SgUczjDZaMOpE6eMaXYLHTm wS0U/fB9a05D1k/nupewyVG9ad2GYJXzjki1f1hh7pLIiDjUV X-Gm-Gg: ASbGncvIs49ZC7/vGgHF/3DdcMilwFqEhzP0jCmXuDNMaWGobCRQpHj7/R/7vo/+BZL esphv66lqcuQ1LPuKkK/j7yLno4JWgbfDBaYkVATum1ynfyhACqUozqA6+jaCTXotAD1SNzzkK4 5kAAZSfgPxnOeH9sshgNAl5JNWO/o50ozi5mXHQ/cninMj2EpbUknuzYdzK7sHONH9tY+jmONNs KsbXMPzsJ+723CZ04kHNs+eC3OxS0ycvV80iAYF4mwCEDaHZ5l5cW31vqK51ANfEbacEpe32pPD QJsr9zop0HaLoB2eRC719DK/XA6HKwvyEHc89hZ47b7wGeK7uKSxThDjZmNZ/F/oDg== X-Received: by 2002:a5d:5986:0:b0:38b:e1b3:16dc with SMTP id ffacd0b85a97d-38c520b0b02mr2139369f8f.50.1738151892499; Wed, 29 Jan 2025 03:58:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IFkkUWuvL/Qi4Q+ZXMjYaW+MERJXy55kjeOBJGiA5aHVhI3t0Ux4qagc7L275aZnwYNWB5ItA== X-Received: by 2002:a5d:5986:0:b0:38b:e1b3:16dc with SMTP id ffacd0b85a97d-38c520b0b02mr2139337f8f.50.1738151892123; Wed, 29 Jan 2025 03:58:12 -0800 (PST) Received: from localhost (p200300cbc7053b0064b867195794bf13.dip0.t-ipconnect.de. [2003:cb:c705:3b00:64b8:6719:5794:bf13]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-38c2a1bb057sm17068560f8f.62.2025.01.29.03.58.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Jan 2025 03:58:11 -0800 (PST) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-doc@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-mm@kvack.org, nouveau@lists.freedesktop.org, David Hildenbrand , Andrew Morton , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , 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: [PATCH v1 2/4] mm/mmu_notifier: drop owner from MMU_NOTIFY_EXCLUSIVE Date: Wed, 29 Jan 2025 12:58:00 +0100 Message-ID: <20250129115803.2084769-3-david@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129115803.2084769-1-david@redhat.com> References: <20250129115803.2084769-1-david@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: yYan0ZxLJPW5NbuViI8F5zrdFOO2iCQ0FDVe8ZE4em0_1738151892 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Stat-Signature: 68t88bgwr8m83op6bgan9ap99p8ssfdx X-Rspam-User: X-Rspamd-Queue-Id: DC8C114000B X-Rspamd-Server: rspam03 X-HE-Tag: 1738151895-555467 X-HE-Meta: U2FsdGVkX18GTY0+WeY0XVjYpyPwpbndbxo5RN3GTqIR9aVE+HhVvRzWYQX442TEN+JGhAEbgdiaJafg8Ee3SHxXKi7R7LHXa/pBanH3SgZl3e+1HDraYmcGxnCUcm4/B1r1eAAO0xATUmbGC4XFHPLeo6RzL9JpnAl0u+nXLzF2XI9W33t/OyseMNnzjSm7kqz5LYXD9Kz2Fu4aGq+++rJ/vrNNvkjzaXoAa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NeW6L2y8ypFk6/xjEtfNNTzxnGOpSJgIIBvs6WelOZPPuVmp4mrRKTWDnPbxMgk4WH01LizUxfzT/QKIFZg4aK+7fP2bQyCqv4Fo+u5Bad0YAomu5NWGde+I3Dp+WaAqSAGD5aKMaZjMg8AeaSixKV7D0pwd4hlKqaLC4lTZI3r+cVGesa2XqLWkjo+oDEpn+9gWCUdl3/37GakHAbxmOPv0WeXfg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: We no longer get a MMU_NOTIFY_EXCLUSIVE on conversion with the owner set that one has to filter out: if there already *is* a device-exclusive entry (e.g., other device, we don't have that information), GUP will convert it back to an ordinary PTE and notify via remove_device_exclusive_entry(). Signed-off-by: David Hildenbrand --- drivers/gpu/drm/nouveau/nouveau_svm.c | 6 +----- include/linux/mmu_notifier.h | 4 +--- include/linux/rmap.h | 2 +- lib/test_hmm.c | 2 +- mm/rmap.c | 3 +-- 5 files changed, 5 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_svm.c b/drivers/gpu/drm/nouveau/nouveau_svm.c index 39e3740980bb..4758fee182b4 100644 --- a/drivers/gpu/drm/nouveau/nouveau_svm.c +++ b/drivers/gpu/drm/nouveau/nouveau_svm.c @@ -510,10 +510,6 @@ static bool nouveau_svm_range_invalidate(struct mmu_interval_notifier *mni, struct svm_notifier *sn = container_of(mni, struct svm_notifier, notifier); - if (range->event == MMU_NOTIFY_EXCLUSIVE && - range->owner == sn->svmm->vmm->cli->drm->dev) - return true; - /* * serializes the update to mni->invalidate_seq done by caller and * prevents invalidation of the PTE from progressing while HW is being @@ -609,7 +605,7 @@ static int nouveau_atomic_range_fault(struct nouveau_svmm *svmm, notifier_seq = mmu_interval_read_begin(¬ifier->notifier); mmap_read_lock(mm); - page = make_device_exclusive(mm, start, drm->dev, &folio); + page = make_device_exclusive(mm, start, &folio); mmap_read_unlock(mm); if (IS_ERR(page)) { ret = -EINVAL; diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h index d4e714661826..bac2385099dd 100644 --- a/include/linux/mmu_notifier.h +++ b/include/linux/mmu_notifier.h @@ -44,9 +44,7 @@ struct mmu_interval_notifier; * owner field matches the driver's device private pgmap owner. * * @MMU_NOTIFY_EXCLUSIVE: to signal a device driver that the device will no - * longer have exclusive access to the page. When sent during creation of an - * exclusive range the owner will be initialised to the value provided by the - * caller of make_device_exclusive(), otherwise the owner will be NULL. + * longer have exclusive access to the page. */ enum mmu_notifier_event { MMU_NOTIFY_UNMAP = 0, diff --git a/include/linux/rmap.h b/include/linux/rmap.h index 86425d42c1a9..3b216b91d2e5 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -664,7 +664,7 @@ void try_to_migrate(struct folio *folio, enum ttu_flags flags); void try_to_unmap(struct folio *, enum ttu_flags flags); struct page *make_device_exclusive(struct mm_struct *mm, unsigned long addr, - void *owner, struct folio **foliop); + struct folio **foliop); /* Avoid racy checks */ #define PVMW_SYNC (1 << 0) diff --git a/lib/test_hmm.c b/lib/test_hmm.c index 1c0a58279db9..8520c1d1b21b 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -786,7 +786,7 @@ static int dmirror_exclusive(struct dmirror *dmirror, struct folio *folio; struct page *page; - page = make_device_exclusive(mm, addr, &folio, NULL); + page = make_device_exclusive(mm, addr, &folio); if (IS_ERR(page)) { ret = PTR_ERR(page); break; diff --git a/mm/rmap.c b/mm/rmap.c index 4acc9f6d743a..d99dbf59adc6 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -2397,7 +2397,6 @@ void try_to_migrate(struct folio *folio, enum ttu_flags flags) * make_device_exclusive() - Mark an address for exclusive use by a device * @mm: mm_struct of associated target process * @addr: the virtual address to mark for exclusive device access - * @owner: passed to MMU_NOTIFY_EXCLUSIVE range notifier to allow filtering * @foliop: folio pointer will be stored here on success. * * This function looks up the page mapped at the given address, grabs a @@ -2421,7 +2420,7 @@ void try_to_migrate(struct folio *folio, enum ttu_flags flags) * Returns: pointer to mapped page on success, otherwise a negative error. */ struct page *make_device_exclusive(struct mm_struct *mm, unsigned long addr, - void *owner, struct folio **foliop) + struct folio **foliop) { struct folio *folio, *fw_folio; struct vm_area_struct *vma; From patchwork Wed Jan 29 11:58:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13953691 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 7676CC0218D for ; Wed, 29 Jan 2025 11:58:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C09C02801C7; Wed, 29 Jan 2025 06:58:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B69C328005A; Wed, 29 Jan 2025 06:58:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 96D702801C7; Wed, 29 Jan 2025 06:58:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 78E2328005A for ; Wed, 29 Jan 2025 06:58:38 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id DEB37C0C71 for ; Wed, 29 Jan 2025 11:58:22 +0000 (UTC) X-FDA: 83060341644.13.264708F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf15.hostedemail.com (Postfix) with ESMTP id AADB6A0004 for ; Wed, 29 Jan 2025 11:58:20 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ucc5PXez; spf=pass (imf15.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738151900; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=n2/u4hMaC1Y/nn2Uh1F1xHtHTh10RqLxBEMK6rVGx5s=; b=2hmqLyEeJie3jgmRlbIe/rVtLa3I2uoGS47Op4IQ7CG08GU3s6meJuGmTNJbdDg+zPV/Io sVN2Yn+TugB13X4FxhyGSgD5gcAmqHgBVgzFdzPUXPNrVSziY2cmbiPwX+gw+xjsFmG1P0 LWwo1h8SEpHr7xuByANNkufWrn4nfZY= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ucc5PXez; spf=pass (imf15.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738151900; a=rsa-sha256; cv=none; b=e39pp91H9veVJDDMarO9d12dPpKrcqWz5r8uoKsNv7hBycwduULtXNDrmnltF6y5DW6ZkB JbyACuRTt8t2AiLYizgZZaI+Yj8fDW8vWjeDr7u8DmMQSXZ7YyKTRUmw4y2zSkbeNubgXC YH4Y9DK6MXNYRB77QLu4ZQK5T2Dz3MI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738151900; 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=n2/u4hMaC1Y/nn2Uh1F1xHtHTh10RqLxBEMK6rVGx5s=; b=Ucc5PXezVRK+eV6OYkwjjCTJY9lK2sZR7LWYq5WOuoDdXC74pfncMME+fDTqYWWlWPVQ5Q 9ZRa0jtyHCTOpQEebW9mLGFfDcKiBBbeARZtYaxOgODQ40SKT+mpgVmU73wQnIJAVbhae/ B5Z06MHjXfXL2czCPUk+dl9hzoFGxb0= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-251-yK-g8O0fO5qVcTqs0PzoAQ-1; Wed, 29 Jan 2025 06:58:17 -0500 X-MC-Unique: yK-g8O0fO5qVcTqs0PzoAQ-1 X-Mimecast-MFC-AGG-ID: yK-g8O0fO5qVcTqs0PzoAQ Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-38a2140a400so5197988f8f.0 for ; Wed, 29 Jan 2025 03:58:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738151896; x=1738756696; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=n2/u4hMaC1Y/nn2Uh1F1xHtHTh10RqLxBEMK6rVGx5s=; b=FRfkcw5wVVpT85xfMGFh6PkGE5ISWYMb1nj+SX/sSrOJ4YLI2s2eaiPLfvHuhYM0ZC ZHwiXhTFXnVRqiMQsqoiXNzt4Oq+Osaul5P/XPelC6tkxj4cdulKAj8OKvIJ5ZJujOwZ sY+Cd/k5r1wz6g3UOkKJ61nIxFX0RosTYjYWq68ofjmdrnlB2JS4v1gB2q4vp/x1DUdP 5x+XlVL+UqzklZR9pBJWdBJNsX/AtcQMCyyYMmEE0HHrvc+G/JsA9L1iKI8/4sb5Qyz8 txj4ZQE8hZMlg4EA6plNN3iNU4y9a7WrA9DmxAZnN8Wb+r9ibHo34ffh361lRn3dOwm3 1g0Q== X-Forwarded-Encrypted: i=1; AJvYcCU3RTc84wIAq/AyPO8E6ZkByiK5Qnr5v7kPreYa9SV5tXRvZGHwqblYo6I0edjmo8IbErpdUQDKHQ==@kvack.org X-Gm-Message-State: AOJu0YyBumxlvLP0qmjlGECBH/Mtv3PMYjzDjFI1Zu8nDPrEo0a1GB7m fRm1whSCqB2+s/VhkLHGgqxeooHaYJ82WPp+KDA5U5BW5BNwIB0Seo/1tndA8MAORFUg4H05e7k MDDY2Mvzphn8LLDGnsl2X8Ob0f0eh3Jbz6CoFibrt8d2X7Oxb X-Gm-Gg: ASbGnctD0+t5neQJFBIMsrokMD3qpomug/CxJxFpScAhBFT0g7ZlAHRnczTNCYueZe2 mmZ7Iu7iQpV9aKEaPsc93/ESpAu0NTcm2t13obQYJ0O0MwD0gMHV1v+qEMJ0oLptmOEiiRpyy11 Hm9kBNOBw8DmQOyDEyAdjVn2WBqKWz8soDkQqQcZ1jhpeETA49NIbs7zQ5RN5hr7/wR6z6palKE jXb+c5xzYqeoWVeFtfqDgyjcCVmupfETOY578XeXP3aJlbzSUuc0DDlUmqe64BklsOj1SsPnqXG o1Sp5tv+PWKkvXXov2DjABPsyqwQjt06+MG/BeUq7wCdbqCNfeFFY8yBdcwvuxkYNg== X-Received: by 2002:a05:6000:2c8:b0:38a:88f8:aac8 with SMTP id ffacd0b85a97d-38c52096289mr2025157f8f.54.1738151895828; Wed, 29 Jan 2025 03:58:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IEON5WkoaxoRH3qtkNX0vn2oqksdlJtc4nZs+NotAXeIJk4vQvUCQu3rl+CihtRV9gH+gpH8w== X-Received: by 2002:a05:6000:2c8:b0:38a:88f8:aac8 with SMTP id ffacd0b85a97d-38c52096289mr2025126f8f.54.1738151895421; Wed, 29 Jan 2025 03:58:15 -0800 (PST) Received: from localhost (p200300cbc7053b0064b867195794bf13.dip0.t-ipconnect.de. [2003:cb:c705:3b00:64b8:6719:5794:bf13]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-38c2a1764e9sm17070487f8f.17.2025.01.29.03.58.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Jan 2025 03:58:14 -0800 (PST) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-doc@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-mm@kvack.org, nouveau@lists.freedesktop.org, David Hildenbrand , Andrew Morton , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , 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: [PATCH v1 3/4] mm/memory: pass folio and pte to restore_exclusive_pte() Date: Wed, 29 Jan 2025 12:58:01 +0100 Message-ID: <20250129115803.2084769-4-david@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129115803.2084769-1-david@redhat.com> References: <20250129115803.2084769-1-david@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: FC5Sp220I1QZnvtbwY82LAgtCDlPCLzMNdsTKI8TuLk_1738151896 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: AADB6A0004 X-Stat-Signature: f8fbbgn8y7jb9qz9riar7ici699f87zo X-Rspam-User: X-HE-Tag: 1738151900-995022 X-HE-Meta: U2FsdGVkX1/zm3+bePmd92PiB31rfMQJO9lZifVpQMiAQgbNv05NxtoMebUz1pGKQf/GwfZ6K4WgYnEzKj8U0pC2WDs0CDq53ux8G7ZXy8MMMd0Q32IckfpMZMzg4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sCd+Bs3oED3a95wxc5nqj8Wjjt5Ev57p+LKjVuY9HaSmTIaklxUXYif05XMnDcipIvSQfwmLY8X10wFVm8hvUDt1nh//gg40erFpUke90iZwXHCSD6OY9vu+DtuGAv1zFayOnkKxUw2mFtHN4x6QRnyYQN96pJw1gHnomZz0v5pPDZwptZkFYF5MHAoTy+3j6BjYk6s8QmyaQSJg1cWeXgawb8/Xlrc4xz5uYEvB0pLRRos9jaUhWN3UL8T+H6SBujJZXq4Fskgw9TRRVIYK0Wk2QGi9ENr4Nlh6bU71eHp4aJYm1NBF1Z672/DwnycrTagBLlXg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Let's pass the folio and the pte to restore_exclusive_pte(), so we can avoid repeated page_folio() and ptep_get(). To do that, pass the pte to try_restore_exclusive_pte() and use a folio in there already. While at it, just avoid the "swp_entry_t entry" variable in try_restore_exclusive_pte() and add a folio-locked check to restore_exclusive_pte(). Signed-off-by: David Hildenbrand Reviewed-by: Alistair Popple --- mm/memory.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index cd689cd8a7c8..46956994aaff 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -719,14 +719,13 @@ struct folio *vm_normal_folio_pmd(struct vm_area_struct *vma, #endif static void restore_exclusive_pte(struct vm_area_struct *vma, - struct page *page, unsigned long address, - pte_t *ptep) + struct folio *folio, struct page *page, unsigned long address, + pte_t *ptep, pte_t orig_pte) { - struct folio *folio = page_folio(page); - pte_t orig_pte; pte_t pte; - orig_pte = ptep_get(ptep); + VM_WARN_ON_FOLIO(!folio_test_locked(folio), folio); + pte = pte_mkold(mk_pte(page, READ_ONCE(vma->vm_page_prot))); if (pte_swp_soft_dirty(orig_pte)) pte = pte_mksoft_dirty(pte); @@ -756,16 +755,15 @@ static void restore_exclusive_pte(struct vm_area_struct *vma, * Tries to restore an exclusive pte if the page lock can be acquired without * sleeping. */ -static int -try_restore_exclusive_pte(pte_t *src_pte, struct vm_area_struct *vma, - unsigned long addr) +static int try_restore_exclusive_pte(struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep, pte_t orig_pte) { - swp_entry_t entry = pte_to_swp_entry(ptep_get(src_pte)); - struct page *page = pfn_swap_entry_to_page(entry); + struct page *page = pfn_swap_entry_to_page(pte_to_swp_entry(orig_pte)); + struct folio *folio = page_folio(page); - if (trylock_page(page)) { - restore_exclusive_pte(vma, page, addr, src_pte); - unlock_page(page); + if (folio_trylock(folio)) { + restore_exclusive_pte(vma, folio, page, addr, ptep, orig_pte); + folio_unlock(folio); return 0; } @@ -871,7 +869,7 @@ copy_nonpresent_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm, * (ie. COW) mappings. */ VM_BUG_ON(!is_cow_mapping(src_vma->vm_flags)); - if (try_restore_exclusive_pte(src_pte, src_vma, addr)) + if (try_restore_exclusive_pte(src_vma, addr, src_pte, orig_pte)) return -EBUSY; return -ENOENT; } else if (is_pte_marker_entry(entry)) { @@ -3979,7 +3977,8 @@ static vm_fault_t remove_device_exclusive_entry(struct vm_fault *vmf) vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, vmf->address, &vmf->ptl); if (likely(vmf->pte && pte_same(ptep_get(vmf->pte), vmf->orig_pte))) - restore_exclusive_pte(vma, vmf->page, vmf->address, vmf->pte); + restore_exclusive_pte(vma, folio, vmf->page, vmf->address, + vmf->pte, vmf->orig_pte); if (vmf->pte) pte_unmap_unlock(vmf->pte, vmf->ptl); From patchwork Wed Jan 29 11:58:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13953689 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 D62DBC02190 for ; Wed, 29 Jan 2025 11:58:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6D967280061; Wed, 29 Jan 2025 06:58:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 686D428005A; Wed, 29 Jan 2025 06:58:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 529D7280061; Wed, 29 Jan 2025 06:58:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 33FCD28005A for ; Wed, 29 Jan 2025 06:58:32 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 5EBBCC0CC6 for ; Wed, 29 Jan 2025 11:58:25 +0000 (UTC) X-FDA: 83060341770.01.7285572 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf23.hostedemail.com (Postfix) with ESMTP id 32E3F140004 for ; Wed, 29 Jan 2025 11:58:23 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IX9lNX0i; spf=pass (imf23.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738151903; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=FOqcQk5sbfQYMqiwFwVZu0o4Vgt4WnJhwl3OPDX2fpI=; b=4+NYaz611GrxAhQBl4tWYF/Rkovo3T8ep9wuyvmepAsEylIv1vC210GgpJe9AM7s4eAK2U Hy79jcgsGeQOomIJthGsJK31JqU4AgFighmDwFtxzp7qDYWx2d/hcoQmBxHbGlIXXrQ5m6 PiKM09+U2DqmvQV+ni4fGgBd5IA8DS4= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IX9lNX0i; spf=pass (imf23.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738151903; a=rsa-sha256; cv=none; b=RFhljrjzfUhnbBahAPZD6spYa8uflYPl+ZiwgeUm3mxraFLUGm0dsjS/YwzwRNS/yfSdF/ lCzs8dhbAPI5HZOramKLguviQ3/KoBZ2VilEZm3zhqV8xvTOIkg9QYLfIyLE0O35zt+DYt w5nyJUwDUGbKeEgn1Tlleqme7jE1ChU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738151902; 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=FOqcQk5sbfQYMqiwFwVZu0o4Vgt4WnJhwl3OPDX2fpI=; b=IX9lNX0iCgdQ58c+TGfq4L1owxkb+zKErVXudQ8awVwla1aP5lKEBcjWXcAOUFXRVlQTBE QZeaJMH8c/CzWMG+3PnXvS2HkxAm2Q64uWpwqaEU8nWRzNZnTV2Txn4FwQz/FmEm2J7r1V AldxwSVUrWzBIHcYtQyzVJbd4tivNv0= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-193-kV4BleaOMTqOmJzW319f4Q-1; Wed, 29 Jan 2025 06:58:19 -0500 X-MC-Unique: kV4BleaOMTqOmJzW319f4Q-1 X-Mimecast-MFC-AGG-ID: kV4BleaOMTqOmJzW319f4Q Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-43631d8d9c7so3373875e9.1 for ; Wed, 29 Jan 2025 03:58:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738151898; x=1738756698; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FOqcQk5sbfQYMqiwFwVZu0o4Vgt4WnJhwl3OPDX2fpI=; b=AvDxnvaIXf0M5ZyZNItryPZquXRcv4DsL+jOgQN94HTL5kb+Z7S9lHSeBk/gChYsLI f8YgLSxmqlVmuA1roiKqjkH1UqMb9/j9ns2W/aFhGXu1/rWEDnDEJYS+dCxsGmqf+Ry7 G4or7VolIB6TC6ujqwPcVVBThbcWVQtp4FQTbq4LYuVNDuWsZc3ovKXjcgbrNlSSBUEB gsr0d1BFbtMkru/wnW/PWh3iIlQqs6SS1sKQi3k06zYNRdVvZgqkoXlHd4AGLFufppXV d8q0bUeccFsfDkGv5cU/Fv+rSMrtvjLMNrr2QImuHFFXasYJroOc+nq/RZKvPqFSfnQr zosg== X-Forwarded-Encrypted: i=1; AJvYcCXCaOWnh1aECqCWQtUBwQNkYuQJCquSMLqGk+DC+YHZiav/9u0G/yJf17mumVqDECPSVu5mU0f+nw==@kvack.org X-Gm-Message-State: AOJu0YwpDR8AX+6/0VuLvucUBiaQ0LJcJFCkgGwElw9BGzg9DRpQig6e 6FEUa4aWS/rE6yjPk6bPkLEtBpPEObItH5fGjAbpv2YzWEsc2K1l8cqewbpdDTUV9B2AUBX616S oY3ZVwBwuRnqWXqh/R4AcsHQbSt5LxI5wJy+onRDw+VfruEDi X-Gm-Gg: ASbGncstbh11mfCp1jDRbWBwpFTc+/4e1aKvxH4ub9jTMFEQuzrKfu6oggl0WT9tlvU 5oH4GWv7wrkYt5Y5YlvPgmXI/oboHJw478vaQle5V25qpG4Xv2nka5MeQ2rwIciGgwRxf1sFCY2 11iULuC4JxAw0f8ciPzvqPTVJVf51eM8do5hhqN1WzHMGDMUwqYp56E/XdXFH8RacYAiRzKvkiD 2nXLK3SPcEtNK9kQgMrx2d6oO/vcmxcaYnuGFEzm5/UvfvutWnmz+6Krtk6rfuIP97uNecvOyZB prn4mpUXTNp5olUR5w865pPeUqskfgRrDA6rq0IZ0LyOItQuMKrvApSwTof5EzAoVQ== X-Received: by 2002:a05:600c:3d87:b0:436:1b0b:2633 with SMTP id 5b1f17b1804b1-438dbe9a124mr27335695e9.9.1738151898326; Wed, 29 Jan 2025 03:58:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IEUOJXNPPQ6xLco9EGZUl9hRUezUN+y2Deyf0uuUDDMY6E4w4fKpt4O5zyjSgxt4LyQtnHPOg== X-Received: by 2002:a05:600c:3d87:b0:436:1b0b:2633 with SMTP id 5b1f17b1804b1-438dbe9a124mr27335535e9.9.1738151897999; Wed, 29 Jan 2025 03:58:17 -0800 (PST) Received: from localhost (p200300cbc7053b0064b867195794bf13.dip0.t-ipconnect.de. [2003:cb:c705:3b00:64b8:6719:5794:bf13]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-438dcc33e04sm20207605e9.29.2025.01.29.03.58.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Jan 2025 03:58:17 -0800 (PST) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-doc@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-mm@kvack.org, nouveau@lists.freedesktop.org, David Hildenbrand , Andrew Morton , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , 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: [PATCH v1 4/4] mm/memory: document restore_exclusive_pte() Date: Wed, 29 Jan 2025 12:58:02 +0100 Message-ID: <20250129115803.2084769-5-david@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129115803.2084769-1-david@redhat.com> References: <20250129115803.2084769-1-david@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: BGSBP6ocL7HuA2noY0aJTHr1dnFKuacMJuJ7o7IIFHI_1738151898 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 32E3F140004 X-Stat-Signature: 3icegn15qn5eg5w6mda37mbjoxt5dzsg X-Rspam-User: X-HE-Tag: 1738151903-729878 X-HE-Meta: U2FsdGVkX18xwfWmiQAKhfd7s223McT6GzBiX/S5tvzL866R7oRFS28oHGwKgQJzL0eGWZi5vF4zVcUqjwhn828R+pgdbWoeXyxtFK2l5ufB1CXvTcmWQLMK2DPfWJyIgFcJ0RchnzMhK8dV8AYHxGwdB8PJ4PuGlRekwyu/OfLARADrTLbzk9Kwo9er2c1orMo2S9eAt7IXYLYVTdb8dH9fHHaX6BjbRxlY6CVwYJaXr3MWCt2RYdID3R8tVaHV6x2FLDsDrXKeNJED904JaZZ0MnQOpp+tb2vuOfkHWNLb7MD5F/XM8BZbAnQesRn4ZSmAK3DP5Ju4C2swaT0MW5FSfUUinspbrhKTbA7Ael/cJPWTlevRnYnfpYSpFRmF541ZvhQ2gnW9gbFqMJFh2o0m2wQqN+ml+/ppQ3KaSTqaZNk0ffgTuAiI4BPxTK7caPuKQCJZJNUTTZkwXR075Jq+MlD52aCoJ5VBBTSF6Ur4zcUBAR0/2J2gSPMjR9wpIBMD7kzG734h0QSaaplG0CgDj3SpHOpeP3eSrtgSHIrCt3yfkvd/o6axbLQu4+vrQ3uJRqu3Oo5hOki0VFZiFUOCfVOipUnr9QOur2FWZXwGFhadzcDr9Pc8J/P/11hxx6Ld8Oo6fz3eRalQO7P7jeFWt0OneOReCjbDimsWHbtS8JD21OKiudJrG0hOQmDExxkJRuCJF0Fe+1BuO5WQdT7DgbM8wa6zxDgJQxP3nLSC0tH2AKZH8+6a74y77tOEgn6jMPeYAKSETRyMw+56zq5+dHJpwexTOYzjsIAUeqrtW0DjGpfzuA2NZuPo1T9dTDJLUZgz5ja6meBZHSEHe5DrreNgx1ns4a4QkYO5wzCuOT4ELtxqo4wlomNUViHS+ju/UtbPECdDJM147HUvwQt+8mo1O3rsSu9mk0hEEZDK2ptWyyOOhisMLVGCd5a5m7c64B+B2N2GI7bvTxW feW+DoFq qxHQ2GJvgsQfxEGFsKWB9z+/Zb6KYbYUD7mr+ZAi/lHUEEJ88xKHIBH2zZVWzPqMEMYl+p5I4zoRMexK0DMDfc1vBD11YAfyi/P9vhjTd1ZMAIvD87DV5vEg/3RkguT5EgOyGw5GKdrV9YmrbNW2e11ZlqPrvBHNjTxYeIcEhh/2Yr7NgKv43dgDakRrly77KyeoxwFPABsjwJS9JrbQl+BBEnc+kcJ53242RxdwhXZIQymvasOjmYXt4e2nDw4TN/dhOHR0ft8/WgZ3mr6sghWVljVA0QkIH6SoCSi9iMkc36rsurX4EFuO2dlBNkKqDzVNF7NLrFl1tMLuwG+UHjBVDiYegq11gSPWBKvT9QLUajkaHrnVSqaD4Mj7Q9l5CIP8dkEYj+B4PeHkMDV3wnu61pHhrtd9k82Z0XWIG2WGV1JfQ1C5ERf+iVpXPlaRlQGf9kjUGA3IQbea4qCtm1K88sBlQjzOD0czRugS88xxsNIuAnwko+KNfro/U34ZmlcyWPnP/WW1W0exHXqlffzI7ig== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Let's document how this function is to be used, and why the requirement for the folio lock might maybe be dropped in the future. Signed-off-by: David Hildenbrand --- mm/memory.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/mm/memory.c b/mm/memory.c index 46956994aaff..caaae8df11a9 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -718,6 +718,31 @@ struct folio *vm_normal_folio_pmd(struct vm_area_struct *vma, } #endif +/** + * restore_exclusive_pte - Restore a device-exclusive entry + * @vma: VMA covering @address + * @folio: the mapped folio + * @page: the mapped folio page + * @address: the virtual address + * @ptep: PTE pointer into the locked page table mapping the folio page + * @orig_pte: PTE value at @ptep + * + * Restore a device-exclusive non-swap entry to an ordinary present PTE. + * + * The folio and the page table must be locked, and MMU notifiers must have + * been called to invalidate any (exclusive) device mappings. In case of + * fork(), MMU_NOTIFY_PROTECTION_PAGE is triggered, and in case of a page + * fault MMU_NOTIFY_EXCLUSIVE is triggered. + * + * Locking the folio makes sure that anybody who just converted the PTE to + * a device-private entry can map it into the device, before unlocking it; so + * the folio lock prevents concurrent conversion to device-exclusive. + * + * TODO: the folio lock does not protect against all cases of concurrent + * page table modifications (e.g., MADV_DONTNEED, mprotect), so device drivers + * must already use MMU notifiers to sync against any concurrent changes + * Maybe the requirement for the folio lock can be dropped in the future. + */ static void restore_exclusive_pte(struct vm_area_struct *vma, struct folio *folio, struct page *page, unsigned long address, pte_t *ptep, pte_t orig_pte)