From patchwork Fri Aug 9 16:09:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13758939 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 86C16C52D7F for ; Fri, 9 Aug 2024 16:10:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 19F736B00B0; Fri, 9 Aug 2024 12:09:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 14FFC6B00B1; Fri, 9 Aug 2024 12:09:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F0AD06B00B2; Fri, 9 Aug 2024 12:09:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id D089F6B00B0 for ; Fri, 9 Aug 2024 12:09:53 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A027C1A102A for ; Fri, 9 Aug 2024 16:09:53 +0000 (UTC) X-FDA: 82433193066.27.7080CFA Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf26.hostedemail.com (Postfix) with ESMTP id 65556140035 for ; Fri, 9 Aug 2024 16:09:51 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=AhY5TU29; spf=pass (imf26.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@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=1723219781; 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=9FTs1XtnGv67Q34nCFPbcUqDR1Dyk8Tfq0P0nZ4zw7U=; b=OJ48B5zeP4GB6Vsn8Ju2K+eCxD6F/GtjmKAmXFE7U0UlAsTVpFJtdozffyTJTVjdi1lxUa 5Z4HFaxeE2LAY8phPyTgmLvJMp3nCrmXvAfWEwO8jx0WyyFUvU/+W3EF+WmAqEby0QGkHc BtFM7Gy1WwHtQ00J/NVleuHdGTXheu4= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=AhY5TU29; spf=pass (imf26.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723219781; a=rsa-sha256; cv=none; b=NQNsDGnCLzeTUsbO/Dtzjs+qGYH0ckZp7ejAE9lms2jcrpUgCizsBnrSKgY98Pu2JDSFil bIbh1gwzo+Xqn+zARJ0cAy9xZ+f9GIUZ5Rhm4C+lQBPJuF+uW9ihel7OIl0W2VSmwRtOOj TbN51imyIIYpaf9fXWNo8yBKUHNXIKA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723219790; 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=9FTs1XtnGv67Q34nCFPbcUqDR1Dyk8Tfq0P0nZ4zw7U=; b=AhY5TU29KFIoZUAFt/vE8ansnAn+BAds844IseN4ZW7ZlfEEg6HVU/Ofrf3rMIloDrE/oQ 7dkyXdosofR3mHRinQl6vYZWqOuDncvMK4G7tc8qmh60a8liCa9q7SLQrbXklzCDhl3rwE wUL1MrjqBIRo/k9Z4KvkktrsWNnA/fI= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-631-mckn3LVINVuKgskhPPS9GQ-1; Fri, 09 Aug 2024 12:09:49 -0400 X-MC-Unique: mckn3LVINVuKgskhPPS9GQ-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-7a1dd7e9a72so5256985a.2 for ; Fri, 09 Aug 2024 09:09:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723219789; x=1723824589; 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=9FTs1XtnGv67Q34nCFPbcUqDR1Dyk8Tfq0P0nZ4zw7U=; b=ocqXQs7ym/zZizHHbwBUwMUszbpnK3AdZz2Awq+eMTYAxORizCfUfifM4DVo3oE31k T3nbT54Boly3+odRvVjgGgYyr6xlIf6eUVV9wko1uP+esuEagzo/lDgzg+5J7VNC+XNT 0d0utCcckvC/1yErqBtV4CKE1bWasNU4Edtlg2No5r7CFJQP9KLowkbHQgdD/cbW06J/ vivIrqJWawVgs0UklO4GG4Fc2D+dFuzcn1iEu1DlIBqfj1X0X9bzt0oSyyG1M1/xPyIR ofZLPBR8n/AOp0dyPGJsQF91b12hAyOesNKuFXilhoLF+Fn0Cex0kzi2ectRdhus/km+ ZjWQ== X-Gm-Message-State: AOJu0YyeSe7gbL7nZpcjjju/596ikuy3AdGVANLmjA+RPlOidEZC4yZV WCvIVMW0NTeF9dMzCnm4qZD2b51JfYvbJ92fPoDcMcLYp44/l/+wu95nDvqAiioTuG5jpMtmEqo 8q0HS4pOgEaq9CVdjnNWzFKK19jz0vUgeXX6LxEzGpPMCBAnFspBtVfw6CQgu5fKf15nA9seM8F RiWtzDtD1fBxND/ahkb2yY/M+QCKI0iLxP X-Received: by 2002:a05:622a:11d1:b0:446:5b0a:e778 with SMTP id d75a77b69052e-4531235a44cmr11675251cf.0.1723219788899; Fri, 09 Aug 2024 09:09:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH3kKOCpVIG6mSA6dMC4Xb4vB8Z6SmUroM26OhSq4nP1v0KE/gOqkuWVbJLnRl3s3aUYCeIEQ== X-Received: by 2002:a05:622a:11d1:b0:446:5b0a:e778 with SMTP id d75a77b69052e-4531235a44cmr11674811cf.0.1723219788421; Fri, 09 Aug 2024 09:09:48 -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 d75a77b69052e-451c870016csm22526741cf.19.2024.08.09.09.09.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Aug 2024 09:09:48 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Sean Christopherson , Oscar Salvador , Jason Gunthorpe , Axel Rasmussen , linux-arm-kernel@lists.infradead.org, x86@kernel.org, peterx@redhat.com, Will Deacon , Gavin Shan , Paolo Bonzini , Zi Yan , Andrew Morton , Catalin Marinas , Ingo Molnar , Alistair Popple , Borislav Petkov , David Hildenbrand , Thomas Gleixner , kvm@vger.kernel.org, Dave Hansen , Alex Williamson , Yan Zhao Subject: [PATCH 15/19] mm/access_process_vm: Use the new follow_pfnmap API Date: Fri, 9 Aug 2024 12:09:05 -0400 Message-ID: <20240809160909.1023470-16-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240809160909.1023470-1-peterx@redhat.com> References: <20240809160909.1023470-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-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ywlAlX5U oA40nush vgmpHkX3WGuwv0CkcBDnsMNPDgnYqnrM558HQO5i+2gcwoxxQxJM/9yTNPniLM7rGsyHjgNsla81cxPFDJZZz753ADNj3ZgnL/Hhn6UiWgw3clrFnVhdFHFpzMR2r7hnk16h6wAtbQhLMsLQzGvZkZgncnFQdsi1ytGlxricQYHyX6iuDH3IyX69aYEYsynyfw3ulNqqSdZSYD6seaiwEiM1XmTWwLF/3PdzZXTiJtnSsS3GrCnFAYlvm0flVLGYNZAPozDDrgLGtzPrPucQcmEGjFYF4hN3pk3Qrn3j4IhF5q2yq96Uty3ESgUuRg2/Oxi0XZsYscPG80ylSeZQbkyrOlNzVrT5dyJLvj/9kXIzCoUsJ19ColyMWWvP5KVBielSQHer4btghff4AS4s4rGiTvK5nTqk47gM21OAIPse9EhwyfzJXZsCSIQlY/NUTQKgHQBDyL7nRD7Ld1DScDPuuDOD+Qj6SZ1e6nP+vcWy9BnBdJ3bu6dKD0zXfr5d/zCUQ 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 2194e0f9f541..313c17eedf56 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -6504,34 +6504,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; } @@ -6540,7 +6540,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);