From patchwork Mon Aug 26 20:43:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13778408 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 34460C5472E for ; Mon, 26 Aug 2024 20:44:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A55A96B00A6; Mon, 26 Aug 2024 16:44:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A07486B00A7; Mon, 26 Aug 2024 16:44:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7E4866B00A8; Mon, 26 Aug 2024 16:44:31 -0400 (EDT) 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 5D4B96B00A6 for ; Mon, 26 Aug 2024 16:44:31 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 168E6411DB for ; Mon, 26 Aug 2024 20:44:31 +0000 (UTC) X-FDA: 82495574742.06.1254C96 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf19.hostedemail.com (Postfix) with ESMTP id 0768E1A0007 for ; Mon, 26 Aug 2024 20:44:28 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=OewNm48n; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724705049; a=rsa-sha256; cv=none; b=Inr5EcRjsnTj1VKjRr13K0raSieewrY/UlVV6FBcb2/Nt9SVc3tpmYAoX6M2EuZ0cknVi4 ty2vvRZHXoCcKMKSoEMy+vZFLD1b+6E5KizcDPHrb2NCLAxeHLU3QFNfI6xXysCLwfWn7r hPOowIiT8jMc+NsDZs8Gzn1XChb+ixs= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=OewNm48n; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724705049; 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=t75nynj+5ccZ6qy3UooqAYOOLyCQeJyCwmKKtTf1Ss4=; b=2H8FNyY0fEn041fX7S2dQj69MpD/NKpUGQx65pHZSEIoNTPeo0airyBNi5rqVf1i+fETJR m+qL+imj+2nbjBweY5Von6yR2fDaGCAPeaZml8SIgir3iYRDV5B3jPNc4ashVvwUOUTGpY 1jCGAHGLUB04MbSQ24j4ktzih+CbgTg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724705068; 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=t75nynj+5ccZ6qy3UooqAYOOLyCQeJyCwmKKtTf1Ss4=; b=OewNm48nnEsXZ4g7ozbw/jYqwhX4mt6Y1hsL0mgpqyH6uTCnw2csiExh1uqsIAGtmZ2ORi q6yIMQDyO3onAN7MYTSsFszZfl/15J7Ksbhpyrxb/csEbZpaXX9icONu/RLJt78+tsNruR Q+dfJh3xwxLClRnVm9k00S+MxiD0aTg= Received: from mail-oa1-f71.google.com (mail-oa1-f71.google.com [209.85.160.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-479-M8nyVohvMpqCa_5kQDGLrA-1; Mon, 26 Aug 2024 16:44:27 -0400 X-MC-Unique: M8nyVohvMpqCa_5kQDGLrA-1 Received: by mail-oa1-f71.google.com with SMTP id 586e51a60fabf-2701a253946so7887382fac.3 for ; Mon, 26 Aug 2024 13:44:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724705066; x=1725309866; 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=t75nynj+5ccZ6qy3UooqAYOOLyCQeJyCwmKKtTf1Ss4=; b=Y07W5rO02I5pQDvgIK7mElU0R8utHQd1Go90wWd6PGkOJhNYciBDiEItgi783NRSFK pfYhkGH2q5HgO1z6Z/T/8pMxL3peCUd+Q6mpAAepqvGwA45I9j6vkU80+6XKEFlmhJp2 NMZv6rzVmNPHZ+INhyYELXqV13HRa//nAenVT3VtTsKOot+1fpVbKHJoeT7c9b5GjE9Y TXN4EqHuX1D6HyiWac9RXMtIFcczEEmZw2Vn7FmeIbWSd/BvBa78P5MTMYoFLvItZllO jAA5yAEXXf59ycWRH3apgu88x7030gQVPQ0Lgb+4TMEXMpZ5SRGN/wFWl1TfWiGTdUd6 izvA== X-Forwarded-Encrypted: i=1; AJvYcCVhmvWuHFnCv3bugtts16N1rwCWv+hIdZv3EaSdkyNyl5aR7aEP/QaqexuZjldaK0s6jQnFuYIxlQ==@kvack.org X-Gm-Message-State: AOJu0YwkOv2CgyZh0tTzDf4J9iEMa8TpQg7lqWqOZAdlScptk1GrIR2e z3sfJ1C0UDdcj9QirWYNa5MXsF+f+89lyUxuyHfWO7Xh6Zbyl5UlM3zzz5xkyP0+yZBX8oB7YDJ O3WDSnPdkB/LIaxynLV88ro8i6UD7DJrm/SLMAmMK+S4QJLox X-Received: by 2002:a05:6358:3a07:b0:1ad:10ff:341e with SMTP id e5c5f4694b2df-1b5c3a3b69dmr1457844155d.4.1724705066543; Mon, 26 Aug 2024 13:44:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGoPajws+HFHWojCbb3D8qBEyBE/zIeN3nkxAxD5pVBn23+qUQ20h6jqSHyvqmBY4DTTGYw+g== X-Received: by 2002:a05:6358:3a07:b0:1ad:10ff:341e with SMTP id e5c5f4694b2df-1b5c3a3b69dmr1457841255d.4.1724705066240; Mon, 26 Aug 2024 13:44:26 -0700 (PDT) Received: from x1n.redhat.com (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7a67f3fd6c1sm491055185a.121.2024.08.26.13.44.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 13:44:25 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Gavin Shan , Catalin Marinas , x86@kernel.org, Ingo Molnar , Andrew Morton , Paolo Bonzini , Dave Hansen , Thomas Gleixner , Alistair Popple , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Sean Christopherson , peterx@redhat.com, Oscar Salvador , Jason Gunthorpe , Borislav Petkov , Zi Yan , Axel Rasmussen , David Hildenbrand , Yan Zhao , Will Deacon , Kefeng Wang , Alex Williamson Subject: [PATCH v2 15/19] mm/access_process_vm: Use the new follow_pfnmap API Date: Mon, 26 Aug 2024 16:43:49 -0400 Message-ID: <20240826204353.2228736-16-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240826204353.2228736-1-peterx@redhat.com> References: <20240826204353.2228736-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Queue-Id: 0768E1A0007 X-Rspamd-Server: rspam01 X-Stat-Signature: 99br51sgeccxcfamwsmn6omahaeijr1o X-HE-Tag: 1724705068-378920 X-HE-Meta: U2FsdGVkX1+RqPM80klDqu4QM19XNXim3UTjALVIxCUMXlIvHORUsiVh9AAq9rodlszjOp2l6YHU18PNAtKy3FyveQE3K/og25VuB7Dd75zJeKhqXfdUjPPCmFBemavr5XqXYcuH9My4HkP5pIxYVTJS2RQhkkZhjYjmaB5eK8KyIemCFjuo5Os+nl+wtTYWNAwPBpuWNL8oEcl7lIUbeoHOI4k2mt4YS+nsn2oFM/DfV7fArjYz7IFQhpmQCNr/p3nPYiEZAjoldrTeiPxdaKCmYW7liEFekkTPRUYXpoSAlA/oxb/tHlsuE+/kyp8v/wpf+i1gMfmiu4B5BHlVQIZJTcLYeRahh1TDhNGzPLf5gM5HeS9fKGi+rdb8xz7ZUcdmrGWtOIuCKmb71b4qMsm252hEHUh5Ur3HjYiJRsKf2qv3LQGIYNxZbc6X7DfGQupf1Go8KjqM2VhwPJUJKdUcXyd6zKfCOyFx86sIeVdzHya/ebXYDybpwSioaNmqJNF1jN4sTix/mYwHLV5VzZ3GWd1dsvrPMMhMU/wLMj/WmrDjAc44Lm9hr8OOKB9pPeWYw9uYKs0/8uKk91UkZA+S+MBQ5w+360h2B8EJG2kQsWUGtjhZlUB5kkOta4/Xx/ySPjmtoPFYN2nBWX1TDaz5lD55uEy9vd164Zv5G+u7G6dj73XcGL6vnxNhSxvKL8NJwS3V5X73wy6UJmHhyKfFI/d2nC817n7xv/M8pVT/HqED9o5viEIK0EHvU7RBK2+8uLcbj8LWg5FJLGAGEAmhlA2TVvVh9bQ2HP/h3MFNkkQbMj3zBZ4aKhiyOr5GdV7iHhIb34tx2xRy+SIriWVTuo53sMAz6o+9iJi3fHWtPbzUb7vsYWLZPQm+xvoRcJHTPnF2e19lFJpa3LvYZ1qAEw7J04jwMtm5k3//gwncVrU2vbnL5IIonayexgL0tA8gJqWBtZ5C8tmmrJG ADpt5OSK yoC7igmxrbIhefxx3MXjsiS3AwxoZjz0tVBG5Y9kPhO2ZH9ab+aBMTpfaabv0yTrsFxI6b4ah4ALcUPyA6yfzXCuSq0M+cdbJgMf1zeu5BAkRXlJVZ/YyUMfZ71eeD8DQ+qYW4Wi34p7gyqaMS5JS+e4O0xFvOByBoqrzGLX/vow8V0lWc3tCLJvByogc+gZ5BT/J8MKJOBT0ifDMLjrkZBF2vIe8dG+ynoh/ASUvc2ewe4cd7W4wMOqJ2KrddL+bhQzPSwRL4splRyRieeVF4FCc40WEv+50Opp1Nu26IahoC7OXP/xIb7CoVEOt9KNPmt4eqs/cCQD1rdkMZNmIS0y/bQ== 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: Use the new API that can understand huge pfn mappings. Signed-off-by: Peter Xu --- mm/memory.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 0b136c398257..b5d07f493d5d 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -6342,34 +6342,34 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr, resource_size_t phys_addr; unsigned long prot = 0; void __iomem *maddr; - pte_t *ptep, pte; - spinlock_t *ptl; int offset = offset_in_page(addr); int ret = -EINVAL; + bool writable; + struct follow_pfnmap_args args = { .vma = vma, .address = addr }; retry: - if (follow_pte(vma, addr, &ptep, &ptl)) + if (follow_pfnmap_start(&args)) return -EINVAL; - pte = ptep_get(ptep); - pte_unmap_unlock(ptep, ptl); + prot = pgprot_val(args.pgprot); + phys_addr = (resource_size_t)args.pfn << PAGE_SHIFT; + writable = args.writable; + follow_pfnmap_end(&args); - prot = pgprot_val(pte_pgprot(pte)); - phys_addr = (resource_size_t)pte_pfn(pte) << PAGE_SHIFT; - - if ((write & FOLL_WRITE) && !pte_write(pte)) + if ((write & FOLL_WRITE) && !writable) return -EINVAL; maddr = ioremap_prot(phys_addr, PAGE_ALIGN(len + offset), prot); if (!maddr) return -ENOMEM; - if (follow_pte(vma, addr, &ptep, &ptl)) + if (follow_pfnmap_start(&args)) goto out_unmap; - if (!pte_same(pte, ptep_get(ptep))) { - pte_unmap_unlock(ptep, ptl); + if ((prot != pgprot_val(args.pgprot)) || + (phys_addr != (args.pfn << PAGE_SHIFT)) || + (writable != args.writable)) { + follow_pfnmap_end(&args); iounmap(maddr); - goto retry; } @@ -6378,7 +6378,7 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr, else memcpy_fromio(buf, maddr + offset, len); ret = len; - pte_unmap_unlock(ptep, ptl); + follow_pfnmap_end(&args); out_unmap: iounmap(maddr);